动态创建,重启后就失效
#brctl addbr br0 #创建一个桥
#brctl addif br0 eth0 #将该桥绑定到eth0
或者,在/etc/sysconfig/network-scripts 下增加一个配置文件:
[root@oc6105682006 network-scripts]# cat ifcfg-br0
DEVICE="br0"
ONBOOT="yes"
TYPE="Bridge"
BOOTPROTO=dhcp
修改/etc/sysconfig/network-scripts/ifcfg-eth0
增加一行
BRIDGE="br0"
重启net-work
ps:
bridge的作用是交换机(2层,只负责mac转发),连接到同一个bridge相当于连接到同一个交换机上的网络设备。
ps2: 对于 libvirt自带的 virbr0, 这个虚拟网桥并没有连接到任何物理网卡(eth0),所以他是一个虚拟网桥,为了实现路由转发
我们需要在路由表中增加NAT 的路由规则(这些libvirt都已经为我们做了)
[root@oc6105682006 network-scripts]# brctl show
bridge name bridge idSTP enabled interfaces
virbr0 8000.fe54003d63e3yes vnet0
[root@oc6105682006 network-scripts]# brctl show virbr0
bridge name bridge idSTP enabled interfaces
virbr0 8000.fe54003d63e3yes vnet0
[root@oc6105682006 network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
9.115.122.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
9.115.126.0 0.0.0.0 255.255.254.0 U 2 0 0 wlan0
0.0.0.0 9.115.122.1 0.0.0.0 UG 0 0 0 eth0
[root@oc6105682006 network-scripts]# brctl showmacs
Incorrect number of arguments for command
Usage: brctl showmacs <bridge> show a list of mac addrs
[root@oc6105682006 network-scripts]# brctl showmacs virbr0
port no mac addris local? ageing timer
1 52:54:00:3d:63:e3no 5.02
1 fe:54:00:3d:63:e3yes 0.00
[root@oc6105682006 network-scripts]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE tcp -- 192.168.122.0/24 !192.168.122.0/24 masq ports: 1024-65535
MASQUERADE udp -- 192.168.122.0/24 !192.168.122.0/24 masq ports: 1024-65535
MASQUERADE all -- 192.168.122.0/24 !192.168.122.0/24
路由表中对目的地址做了地址伪装
请看