[root@ ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@ ~]# uname -r
2.6.32-642.6.1.el6.x86_64
网卡说明
eth0 192.168.1.8(服务器外网卡)
eth1 服务器网卡(内网)
eth2 服务器网卡(内网)
[root@ ~]# /etc/init.d/iptables stop
[root@ ~]# chkconfig iptables off
关闭selinux
[root@ ~]#setenforce 0
[root@ ~]#sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config
禁用NetworkManager
[root@ ~]# /etc/init.d/NetworkManager stop
Stopping NetworkManager daemon: [ OK ]
[root@ ~]# chkconfig NetworkManager off
[root@ ~]# /etc/init.d/network restart
双网卡绑定配置过程
[root@ ~]# cd /etc/sysconfig/network-scripts/
编辑eth1网卡
[root@ network-scripts]# cat >ifcfg-eth1 <>DEVICE=eth1
>ONBOOT=yes
>BOOTPROTO=none
>USERCTL=no
>MASTER=bind0
>EOF
编辑eth2网卡
[root@ network-scripts]# cat >ifcfg-eth2
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bind0
EOF
编辑bind0网卡
[root@ network-scripts]# cat >ifcfg-bind0 <>DEVICE=bind0
>TYPE=Ethernet
>ONBOOT=yes
>BOOTPROTO=none
>IPADDR=10.0.0.8
>NETMASK=255.255.255.0
>GATEWAY=10.0.0.254
>IPV6INIT=no
>USERCTL=no
>EOF
配置bond参数
[root@ network-scripts]# cat >/etc/modprobe.conf <>alias bind0 bonding
>options bind0 miimon=100 mode=6
>EOF
加入开机自启动(/etc/rc.local)
[root@ network-scripts]# cat >>/etc/rc.local <>ifenslave bind0 eth1 eth2
>EOF
重启网络服务
[root@LVS-2 network-scripts]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down interface eth2: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bind0: WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
Determining if ip address 10.0.0.8 is already in use for device bind0..[ OK ]
Bringing up interface eth0: Determining if ip address 192.168.1.8 is already in use for device eth0... [ OK ]
Bringing up interface eth1: RTNETLINK answers: File exists [ OK ]
Bringing up interface eth2: RTNETLINK answers: File exists [ OK ]
配置使绑定立即生效
[root@LVS-2 network-scripts]# ifenslave bind0 eth1 eth2
测试联通
[root@LVS-2 network-scripts]# ping 10.0.0.8
PING 10.0.0.8 (10.0.0.8) 56(84) bytes of data.
64 bytes from 10.0.0.8: icmp_seq=1 ttl=64 time=0.089 ms
64 bytes from 10.0.0.8: icmp_seq=2 ttl=64 time=0.046 ms
^C
--- 10.0.0.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1921ms
rtt min/avg/max/mdev = 0.046/0.067/0.089/0.023 ms
此时会发现系统多一个网卡
[root@LVS-2 network-scripts]# ifconfig bind0
bind0
Link encap:Ethernet HWaddr 00:0C:29:CC:9B:5
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fecc:9b55/64 Scope:LinkUP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:151 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11826 (11.5 KiB) TX bytes:258 (258.0 b)
注意: 2 张网卡,只能有1张网卡配置网关,另1张网卡不能配置网关,通过route add 添加路由功能来完成第2张网卡的网关配置。如 : eth1 (192.168.2.2)不需要配置网关, 但到 192.168.3.0 的网段,需要从eth1 去实现通信,其余的全部走eth0 网卡,eth0 配置 网关.
eth0 的配置如下,配置网关参数
[root@REDHAT network-scripts]# cat ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HOTPLUG=no
TYPE=Ethernet
IPADDR=192.168.1.2
NETMASK=255.255.255.0
HWADDR=d8:d3:85:fb:d4:60
GATEWAY=192.168.1.1
USERCTL=no
IPV6INIT=no
PEERDNS=yes
eth1 的配置如下,不需要配置网关
[root@SERVER network-scripts]# cat ifcfg-eth1
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
HOTPLUG=no
TYPE=Ethernet
IPADDR=192.168.2.2
NETMASK=255.255.255.0
USERCTL=no
IPV6INIT=no
PEERDNS=yes
Linux 命令行下添加路由,192.168.3.0 走 eth1 的网关 192.168.2.1
route add -net 192.168.3.0 netmask 255.255.255.0 dev eth1
linux下双网卡配置桥接如下首先,配置linux服务器端,将两张网卡配置成桥接模式:
在/etc/sysconfig/network-scripts/文件夹下创建ifcfg-br0桥接接口配置文件,内容如下:
[root@N3 network-scripts]# vi ifcfg-br0
# Broadcom Corporation NetXtreme BCM5722 Gigabit Ethernet PCI Express
DEVICE=br0-----桥接接口命名为bro
TYPE=Bridge-----类型桥接模式
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.222----这部分是配置桥接接口的管理ip(类似svi口的ip)和网关等等。
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
NETWORK=192.168.1.0
将两个接口加入桥接端口:
[root@N3 network-scripts]# vi ifcfg-eth0
# Broadcom Corporation NetXtreme BCM5722 Gigabit Ethernet PCI Express
DEVICE=eth4
BOOTPROTO=none
HWADDR=00:21:5E:47:31:98
ONBOOT=yes
BRIDGE=br0 ---加入桥接端口
IPV6INIT=no
PEERDNS=yes
NM_CONTROLLED=no
TYPE=Ethernet
USERCTL=no
[root@N3 network-scripts]# vi ifcfg-eth1
# Broadcom Corporation NetXtreme BCM5722 Gigabit Ethernet PCI Express
DEVICE=eth5
BOOTPROTO=none
HWADDR=00:21:5E:47:31:A0
ONBOOT=yes
BRIDGE=br0
IPV6INIT=no
PEERDNS=yes
NM_CONTROLLED=no
TYPE=Ethernet
USERCTL=no
配置完成后,需要重启设备后,网卡桥接才能生效。
其次,在linux下开启生成树协议:
到目前为此我们可以看到,如果linux端配置成桥接模式,而交换机端也没有开启生成树,整个网络是环路状态。
我们要在交换机端开启生成树:spanning-tree
同时在linux端也开启生成树协议,通过如下命令开启:
[root@SERVER2 ~]# brctl stp br0 on
可以通过如下命令查看linux服务器生成树状态:brctl showstp br0
交换机端查看生成树状态:show spanning-tree summary
可以看到交换机端端口GI0/50被block了,两端生成树都生效了。
至此Linux下双网卡桥接同时开启生成树保证网络拓扑不环路的方案就完成了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)