本地LAN环境
- LAN网关
192.168.1.1
- 子网掩码
255.255.255.0
- DHCP范围
192.168.1.2
-192.168.32
创建一个bridged network
创建一个网桥br0
给虚机使用,使得虚机和其他设备都在一个LAN下
总配置(netplan get
)如下:
network:
version: 2
renderer: NetworkManager
ethernets:
enp1s0:
dhcp4: false
dhcp6: false
bridges:
br0:
addresses:
- "192.168.1.100/24"
nameservers:
addresses:
- 192.168.1.1
dhcp4: false
dhcp6: false
interfaces:
- enp1s0
parameters:
stp: false
routes:
- to: "default"
via: "192.168.1.1"
由三个文件组成:
/etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
/etc/netplan/10-ethernet-enp1s0.yaml
network:
ethernets:
enp1s0:
dhcp4: false
dhcp6: false
/etc/netplan/99-bridged-network-br0.yaml
network:
bridges:
br0:
dhcp4: false
dhcp6: false
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 192.168.1.1
- 223.5.5.5
interfaces:
- enp1s0
parameters:
stp: false
应用网络配置
容易失联,如果是ssh远程操作请谨慎操作
netplan apply
补充
- 如何没有安装
NetworkManager
需要先安装(通过systemctl status NetworkManager
查看是否安装)
apt install network-manager -y
- 生产环境可以
systemd-networkd
和NetworkManager
共存, 但是在我这里遇到了一些问题
nmstate 依赖NetworkManager
服务, NM可以使用10-globally-managed-devices.conf
配置不管理哪些接口
- 禁用
systemd-networkd
# 先关闭 systemd-networkd.socket, 否则每次关闭 systemd-networkd 都会被马上重新激活
systemctl stop systemd-networkd.socket
systemctl disable systemd-networkd.socket
systemctl stop systemd-networkd
systemctl disable systemd-networkd
netplan apply
之后会发现br0
会出现好几个inet6