系统版本:CentOS 7.1 x64
1 | # cat /etc/redhat-release |
2 | CentOS Linux release 7.1.1503 (Core) |
3 | # uname -a |
4 | Linux localhost.localdomain 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux |
桥接前配置:
01 | # cat /etc/sysconfig/network-scripts/ifcfg-enp2s4 |
02 | BOOTPROTO=dhcp |
03 | DEFROUTE= yes |
04 | PEERDNS= yes |
05 | PEERROUTES= yes |
06 | IPV4_FAILURE_FATAL=no |
07 | IPV6INIT= yes |
08 | IPV6_AUTOCONF= yes |
09 | IPV6_DEFROUTE= yes |
10 | IPV6_PEERDNS= yes |
11 | IPV6_PEERROUTES= yes |
12 | IPV6_FAILURE_FATAL=no |
13 | IPV6_FAILURE_FATAL=no |
14 | TYPE=Ethernet |
15 | NAME=enp2s4 |
16 | UUID=65b1d8b3-2214-45ec-987f-d0f1cc0004cb |
17 | DEVICE=enp2s4 |
18 | ONBOOT= yes |
19 |
20 | # cat /etc/sysconfig/network-scripts/ifcfg-enp3s5 |
21 | BOOTPROTO=dhcp |
22 | DEFROUTE= yes |
23 | PEERDNS= yes |
24 | PEERROUTES= yes |
25 | IPV4_FAILURE_FATAL=no |
26 | IPV6INIT= yes |
27 | IPV6_AUTOCONF= yes |
28 | IPV6_DEFROUTE= yes |
29 | IPV6_PEERDNS= yes |
30 | IPV6_PEERROUTES= yes |
31 | IPV6_FAILURE_FATAL=no |
32 | IPV6_FAILURE_FATAL=no |
33 | TYPE=Ethernet |
34 | NAME=enp3s5 |
35 | UUID=65b1d8b3-2214-45ec-987f-d0f1cc0004cb |
36 | DEVICE=enp3s5 |
37 | ONBOOT= yes |
通过配置文件配置桥接:
01 | # cd /etc/sysconfig/network-scripts |
02 |
03 | # cat ifcfg-br0 #桥接口名称为br0 |
04 | TYPE=Bridge |
05 | BOOTPROTO=static |
06 | IPADDR=192.168.1.82 |
07 | PREFIX=24 |
08 | IPV4_FAILURE_FATAL=no |
09 | NAME=br0 |
10 | DEVICE=br0 |
11 | ONBOOT= yes |
12 | BRIDGE_STP= yes |
13 |
14 | # cat ifcfg-enp2s4 |
15 | TYPE=Ethernet |
16 | NAME=enp2s4 |
17 | UUID=30a9efb8-2594-4596-9cde-d87c1ac06003 |
18 | #HWADDR=00:1c:c4:df:db:e4 |
19 | DEVICE=enp2s4 |
20 | ONBOOT= yes |
21 | BRIDGE=br0 |
22 |
23 | # cat ifcfg-enp3s5 |
24 | TYPE=Ethernet |
25 | NAME=enp3s5 |
26 | #HWADDR=00:1c:c4:df:db:e6 |
27 | UUID=65b1d8b3-2214-45ec-987f-d0f1cc0004cb |
28 | DEVICE=enp3s5 |
29 | ONBOOT= yes |
30 | BRIDGE=br0 |
31 |
32 | # systemctl status network.service #重启网络服务 |
33 |
34 | #查看是否失效 |
35 | # ifconfig |
36 | br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 |
37 | inet 192.168.1.82 netmask 255.255.255.0 broadcast 192.168.71.255 |
38 | inet6 fe80::21c:c4ff:fedf:dbe4 prefixlen 64 scopeid 0x20<link> |
39 | ether 00:1c:c4: df :db:e4 txqueuelen 0 (Ethernet) |
40 | RX packets 1438 bytes 182390 (178.1 KiB) |
41 | RX errors 0 dropped 0 overruns 0 frame 0 |
42 | TX packets 8 bytes 592 (592.0 B) |
43 | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
44 |
45 | enp2s4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 |
46 | ether 00:1c:c4: df :db:e4 txqueuelen 1000 (Ethernet) |
47 | RX packets 669318 bytes 968188165 (923.3 MiB) |
48 | RX errors 0 dropped 0 overruns 0 frame 0 |
49 | TX packets 87613 bytes 7615798 (7.2 MiB) |
50 | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
51 |
52 | enp3s5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 |
53 | ether 00:1c:c4: df :db:e6 txqueuelen 1000 (Ethernet) |
54 | RX packets 87597 bytes 7613914 (7.2 MiB) |
55 | RX errors 0 dropped 0 overruns 0 frame 0 |
56 | TX packets 666707 bytes 967793844 (922.9 MiB) |
57 | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
58 |
59 | # brctl show |
60 | bridge name bridge id STP enabled interfaces |
61 | br0 8000.001cc4dfdbe4 no enp2s4 |
62 | enp3s5 |
通过brctl配置桥接:
01 | #安装brctl |
02 | yum install bridge-utils |
03 |
04 | # ifconfig enp2s4 down |
05 | # ifconfig enp3s5 down |
06 | # ifconfig enp2s4 0.0.0.0 |
07 | # ifconfig enp3s5 0.0.0.0 |
08 |
09 | # brctl addbr br0 |
10 | # brctl addif br0 enp2s4 |
11 | # brctl addif br0 enp3s5 |
12 |
13 | # ifconfig br0 192.168.1.82 up |
14 |
15 | # brctl stp br0 off #关闭生成树协议 |
16 | # brctl show |
17 |
18 | #brctl 命令配置重启后失效,可以把相关命令添加到/etc/rc.d/rc.local 即可。 |
参考: