CentOS7网卡桥接

系统版本:CentOS 7.1 x64

# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core) 
# uname -a
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

 桥接前配置:

# cat /etc/sysconfig/network-scripts/ifcfg-enp2s4 
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_FAILURE_FATAL=no
TYPE=Ethernet
NAME=enp2s4
UUID=65b1d8b3-2214-45ec-987f-d0f1cc0004cb
DEVICE=enp2s4
ONBOOT=yes

# cat /etc/sysconfig/network-scripts/ifcfg-enp3s5 
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_FAILURE_FATAL=no
TYPE=Ethernet
NAME=enp3s5
UUID=65b1d8b3-2214-45ec-987f-d0f1cc0004cb
DEVICE=enp3s5
ONBOOT=yes

通过配置文件配置桥接:

# cd /etc/sysconfig/network-scripts

# cat ifcfg-br0      #桥接口名称为br0
TYPE=Bridge
BOOTPROTO=static
IPADDR=192.168.1.82
PREFIX=24
IPV4_FAILURE_FATAL=no
NAME=br0
DEVICE=br0
ONBOOT=yes
BRIDGE_STP=yes

# cat ifcfg-enp2s4 
TYPE=Ethernet
NAME=enp2s4
UUID=30a9efb8-2594-4596-9cde-d87c1ac06003
#HWADDR=00:1c:c4:df:db:e4
DEVICE=enp2s4
ONBOOT=yes
BRIDGE=br0

# cat ifcfg-enp3s5 
TYPE=Ethernet
NAME=enp3s5
#HWADDR=00:1c:c4:df:db:e6
UUID=65b1d8b3-2214-45ec-987f-d0f1cc0004cb
DEVICE=enp3s5
ONBOOT=yes
BRIDGE=br0

# systemctl status network.service  #重启网络服务

#查看是否失效
# ifconfig 
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.82  netmask 255.255.255.0  broadcast 192.168.71.255
        inet6 fe80::21c:c4ff:fedf:dbe4  prefixlen 64  scopeid 0x20<link>
        ether 00:1c:c4:df:db:e4  txqueuelen 0  (Ethernet)
        RX packets 1438  bytes 182390 (178.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 592 (592.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp2s4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:1c:c4:df:db:e4  txqueuelen 1000  (Ethernet)
        RX packets 669318  bytes 968188165 (923.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 87613  bytes 7615798 (7.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:1c:c4:df:db:e6  txqueuelen 1000  (Ethernet)
        RX packets 87597  bytes 7613914 (7.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 666707  bytes 967793844 (922.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.001cc4dfdbe4       no              enp2s4
                                                        enp3s5

 通过brctl配置桥接:

#安装brctl
yum install bridge-utils

# ifconfig enp2s4 down
# ifconfig enp3s5 down
# ifconfig enp2s4 0.0.0.0
# ifconfig enp3s5 0.0.0.0

# brctl addbr br0
# brctl addif br0 enp2s4
# brctl addif br0 enp3s5

# ifconfig br0 192.168.1.82 up

# brctl stp br0 off  #关闭生成树协议
# brctl show

#brctl 命令配置重启后失效,可以把相关命令添加到/etc/rc.d/rc.local 即可。

 

参考:

CentOS 6桥接网卡配置

发表回复