不同的操作系统通过静态IP地址指定网段配置网桥的操作步骤不同,可直接参考表1直接跳转到对应的内容。
虚拟机操作系统 |
参考步骤 |
---|---|
openEuler 22.03 LTS openEuler 20.03 LTS BC Linux 8.2 BC Linux 21.10 CentOS 7.5(5.10.0) CULinux 3.0 Kylin V10 Kylin V10 SP2 Kylin V10 SP3 Tlinux3.1 UOS V20(1050e) UOS V20(1050u2e) |
|
Ubuntu 20.04 Ubuntu 22.04 |
|
Debian10(veLinux 1.3) Debian10.13 veLinux 1.2 veLinux 1.1 veLinux 1.1(5.10.200) |
|
Debian10.8 Debian11.8 |
virsh net-list --all
显示如下,则表示默认网桥关闭。
Name State Autostart Persistent -------------------------------------------- default inactive no yes [root@localhost home]#
virsh net-destroy default
Network default destroyed
virsh net-autostart --disable default
Network default unmarked as autostarted
显示如下,表示安装成功。
Complete!
./configure
make && make install
显示如下,表示安装成功。
Complete!
vi /etc/sysconfig/network-scripts/ifcfg-enp189s0f0
在配置文件末尾增加如下加粗字体标注的内容并保存。
TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=enp189s0f0 ... BRIDGE=virbr0
vi /etc/sysconfig/network-scripts/ifcfg-virbr0
增加如下内容并保存。
TYPE=Bridge BOOTPROTO=static DEVICE=virbr0 IPADDR=x.x.x.x NETMASK=x.x.x.x GATEWAY=x.x.x.x
先生效虚拟网卡配置:NetworkManager virbr0或ifup virbr0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
再生效物理网卡配置:NetworkManager enp189s0f0或ifup enp189s0f0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
再生效物理网卡配置:ifup enp189s0f0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
若配置未生效,执行8。
reboot
virsh net-list --all
显示如下,则表示默认网桥关闭。
Name State Autostart Persistent -------------------------------------------- default inactive no yes [root@localhost home]#
virsh net-destroy default
Network default destroyed
virsh net-autostart --disable default
Network default unmarked as autostarted
apt install -y bridge-utils
Reading package lists... Done Building dependency tree Reading state information... Done bridge-utils is already the newest version (1.6-2ubuntu1).
vi /etc/netplan/00-installer-config.yaml
参考如下修改并保存:
# This is the network config written by 'subiquity' network: ethernets: enp189s0f0: dhcp4: false dhcp6: false bridges: virbr0: interfaces: [ enp189s0f0 ] addresses: [x.x.x.x/x] gateway4: x.x.x.x nameservers: addresses: [x.x.x.x] version: 2
netplan apply
apt install -y bridge-utils
Reading package lists... Done Building dependency tree Reading state information... Done bridge-utils is already the newest version (1.6-2ubuntu1).
ip -f inet a s
回显如下,x.x.x.x/x表示所在物理接口。
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 5: ens3f3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 inet x.x.x.x/x brd x.x.x.255 scope global noprefixroute ens3f3 valid_lft forever preferred_lft forever 6: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever
vi /etc/network/interface
确保只有 lo,即loopback在“ /etc/network/interface”中处于活动状态。删除与2查询的物理网卡相关的任何配置。
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface #allow-hotplug ens3f3 #iface ens3f3 inet static # address x.x.x.x/x # gateway x.x.x.x # # dns-* options are implemented by the resolvconf package, if installed # dns-nameservers x.x.x.x # dns-search huawei
loopback 指本地环回接口,也称为回送地址。
vi /etc/network/interfaces.d/br0
在文件中增加如下配置。
auto br0 iface br0 inet static address x.x.x.x # 当前host侧主机的ip netmask 255.255.252.0 gateway x.x.x.x bridge_ports ens3f3 # 对应物理网卡设备 bridge_stp off bridge_waitport 0 bridge_fd 0
systemctl restart networking.service
systemctl status networking.service
回显信息如下,若状态为“active (exited)”,则表示服务已启动。
● networking.service - Raise network interfaces Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled) Active: active (exited) since Thu 2023-11-09 00:19:28 EST; 1 day 2h ago Docs: man:interfaces(5) Main PID: 3526 (code=exited, status=0/SUCCESS) Tasks: 0 (limit: 29491) Memory: 0B CGroup: /system.slice/networking.service
ip a s
brctl show
bridge name bridge id STP enabled interfaces br0 8000.e84d7429debf no ens3f3 docker0 8000.0242f95b8fd4 no
bridge link
5: ens3f3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 4
若用户通过外接PCIe网卡方式配置网桥,可以参考如下步骤使能物理机网卡。
在物理机修改配置文件/etc/sysctl.conf,在配置文件末尾加入如下内容:
net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0
执行如下命令,使配置生效。
sysctl -p
apt install -y bridge-utils --allow-unauthenticated
root@debian:/home# apt install -y bridge-utils --allow-unauthenticated Reading package lists... Done Building dependency tree... Done Reading state information... Done bridge-utils is already the newest version (1.7-1). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
注意该网桥需要与XML文件中网桥名称一致。
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo virbr0 iface lo inet loopback iface enp189s0f0 inet manual iface virbr0 inet static bridge_ports enp189s0f0 address x.x.x.x netmask 255.255.255.0 gateway x.x.x.x