网桥是在链路层实现的网络中继,一般用来连接多个网络。它根据MAC地址对帧进行转发,将多个网段在数据链路层连接起来。
在debian中创建网桥比较简单,一般通过bridge-utils进行设置。
设计中,将系统的两个物理网卡桥接起来,实现虚拟交换机功能。
1,安装bridge工具包
apt-get install bridge-utils
2,安装ip工具包
apt-get install net-tools
3,检查系统的网络接口
ip addr
可以看到当前主机下物理网络接口有3个,分别是eno1、enp1s0f0和enp1s0f1
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host noprefixroute valid_lft forever preferred_lft forever 2: enp1s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000 link/ether a0:36:9f:d8:9c:88 brd ff:ff:ff:ff:ff:ff inet6 fe80::a236:9fff:fed8:9c88/64 scope link valid_lft forever preferred_lft forever 3: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 6c:0b:84:90:f4:e1 brd ff:ff:ff:ff:ff:ff altname enp0s25 inet 192.168.1.120/24 brd 192.168.1.255 scope global eno1 valid_lft forever preferred_lft forever inet6 fe80::6e0b:84ff:fe90:f4e1/64 scope link valid_lft forever preferred_lft forever 4: enp1s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000 link/ether a0:36:9f:d8:9c:89 brd ff:ff:ff:ff:ff:ff inet6 fe80::a236:9fff:fed8:9c89/64 scope link valid_lft forever preferred_lft forever
4. 添加网桥br0
brctl addbr br0
ip addr add 192.168.12.254/40 dev br0
5,添加物理网口到网桥
brctl addif br0 enp1s0f0
brctl addif br0 enp1s0f1
6,连接网桥
ip link set br0 up
7,查看网桥信息
brctl show
显示信息如下
bridge name bridge id STP enabled interfaces br0 8000.da62efddabfd no enp1s0f0 enp1s0f1
查看主机ip信息
可见网桥br0地址正确,且处于工作状态