网桥IP

网桥IP
  这里是一个给网桥设置IP地址的实验。
  实验环境:
  Linux版本:
# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

  bridge-utils的版本:
# rpm -qa | grep bridge-utils
bridge-utils-1.5-9.el7.x86_64

机器上只有一个网卡enp0s3,lo为回环接口:

# ifconfig
enp0s3: flags=4163 mtu 1500
        inet 192.168.1.11 netmask 255.255.255.0 broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fe2b:86c prefixlen 64 scopeid 0x20
        ether 08:00:27:2b:08:6c txqueuelen 1000 (Ethernet)
        RX packets 161 bytes 12052 (11.7 KiB)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 38 bytes 6957 (6.7 KiB)
        TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
        inet 127.0.0.1 netmask 255.0.0.0
        inet6 ::1 prefixlen 128 scopeid 0x10
        loop txqueuelen 0 (Local Loopback)
        RX packets 0 bytes 0 (0.0 B)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 0 bytes 0 (0.0 B)
        TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

# brctl show
bridge name bridge id STP enabled interfaces

  首先,我们创建一个网桥br0:

# brctl addbr br0

  查看网桥:

# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 no

  说明网桥br已经创建成功了。
  然后,我们将enp0s3加入网桥br0

# brctl addif br0 enp0s3

  将enp0s3加入网桥br0后,则enp0s3上的IP地址会失效,意味着如果我们是通过ssh远程连接到系统,则执行完命令后网络就断开。
  本地登录系统,给网桥br0设置原enp0s3上的IP地址:

# ifconfig br0 192.168.1.11/24 up

  使用ssh重新连接系统,发送已经可以连通了。
  查看网桥:

# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.0800272b086c no enp0s3

  查看网络接口:

# ifconfig
br0: flags=4163 mtu 1500
        inet 192.168.1.11 netmask 255.255.255.0 broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fe2b:86c prefixlen 64 scopeid 0x20
        ether 08:00:27:2b:08:6c txqueuelen 0 (Ethernet)
        RX packets 228 bytes 28196 (27.5 KiB)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 108 bytes 16379 (15.9 KiB)
        TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

enp0s3: flags=4163 mtu 1500
        inet 192.168.1.11 netmask 255.255.255.0 broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fe2b:86c prefixlen 64 scopeid 0x20
        ether 08:00:27:2b:08:6c txqueuelen 1000 (Ethernet)
        RX packets 8269 bytes 1091747 (1.0 MiB)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 199 bytes 31576 (30.8 KiB)
        TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
        inet 127.0.0.1 netmask 255.0.0.0
        inet6 ::1 prefixlen 128 scopeid 0x10
        loop txqueuelen 0 (Local Loopback)
        RX packets 5 bytes 492 (492.0 B)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 5 bytes 492 (492.0 B)
        TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  可以发现br0已经成功设置了IP地址:192.168.1.11。