root@ubuntu:~# cat /etc/network/interfaces # 修改前,網絡信息配置在ens160下
# 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
auto ens160
iface ens160 inet static
address 10.12.31.211
netmask 255.255.252.0
network 10.12.28.0
broadcast 10.12.31.255
gateway 10.12.28.6
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 10.12.28.6
up route add -net 172.22.0.0 netmask 255.255.0.0 gw 10.12.28.1 ens160
root@ubuntu:~# cat /etc/network/interfaces # 修改後,ens160掛載br0下,網絡信息配置在br0上
# 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
auto ens160
iface ens160 inet static
auto br0
iface br0 inet static
bridge_stp off
bridge_waitport 0
bridge_fd 0
bridge_ports ens160
address 10.12.31.211
netmask 255.255.252.0
network 10.12.28.0
broadcast 10.12.31.255
gateway 10.12.28.6
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 10.12.28.6
up route add -net 172.22.0.0 netmask 255.255.0.0 gw 10.12.28.1 br0
root@ubuntu:~# reboot # 重啓系統生效
root@ubuntu:~# ifconfig # 查看網絡信息都配置到了br0上
br0 Link encap:Ethernet HWaddr 00:50:56:87:4c:70
inet addr:10.12.31.211 Bcast:10.12.31.255 Mask:255.255.252.0
inet6 addr: fe80::250:56ff:fe87:4c70/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:307 errors:0 dropped:0 overruns:0 frame:0
TX packets:129 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:19800 (19.8 KB) TX bytes:18385 (18.3 KB)
ens160 Link encap:Ethernet HWaddr 00:50:56:87:4c:70
inet6 addr: fe80::250:56ff:fe87:4c70/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:314 errors:0 dropped:0 overruns:0 frame:0
TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24520 (24.5 KB) TX bytes:22247 (22.2 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:85 errors:0 dropped:0 overruns:0 frame:0
TX packets:85 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:6165 (6.1 KB) TX bytes:6165 (6.1 KB)
virbr0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
root@ubuntu:~# brctl show # 查看 ens160 掛到了br0 下
bridge name bridge id STP enabled interfaces
br0 8000.005056874c70 no ens160
virbr0 8000.000000000000 yes
除了br0 ,咱們還能看到一個 virbr0 的Bridge ,並且 virbr0 上已經配置了IP 地址 192.168.122.1 。virbr0 的做用咱們後面會介紹。