这篇文章主要介绍Linux系统如何配置双网卡绑定,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

系统版本

[root@ ~]# cat /etc/redhat-release CentOS release 6.8 (Final)[root@ ~]# uname -r2.6.32-642.6.1.el6.x86_64

网卡说明

eth0 192.168.1.8(服务器外网卡)
eth2
eth3
两块服务器网卡(内网)

关闭防火墙

[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 stopStopping NetworkManager daemon: [ OK ][root@ ~]# chkconfig NetworkManager off[root@ ~]# /etc/init.d/network restart

编辑eth2网卡

[root@ ~]# cd /etc/sysconfig/network-scripts/[root@ network-scripts\]# cat >ifcfg-eth2 <<EOFDEVICE=eth2ONBOOT=yesBOOTPROTO=noneUSERCTL=noMASTER=bind0EOF

编辑eth3网卡

[root@ network-scripts]# cat >ifcfg-eth3 <<EOF DEVICE=eth3ONBOOT=yesBOOTPROTO=noneUSERCTL=noMASTER=bind0EOF

编辑bind0网卡

[root@ network-scripts]# cat >ifcfg-bind0 <<EOFDEVICE=bind0TYPE=EthernetONBOOT=yesBOOTPROTO=noneIPADDR=10.0.0.8NETMASK=255.255.255.0GATEWAY=10.0.0.254IPV6INIT=noUSERCTL=noEOF

配置bond参数

[root@ network-scripts]# cat >/etc/modprobe.conf <<EOFalias bind0 bondingoptions bind0 miimon=100 mode=6EOF

加入开机自启动(/etc/rc.local)

[root@ network-scripts]# cat >>/etc/rc.local <<EOFifenslave bind0 eth2 eth3EOF

重启网络服务

[root@LVS-2 network-scripts]# service network restartShutting down interface eth0: [ OK ]Shutting down interface eth2: [ OK ]Shutting down interface eth3: [ 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 eth2: RTNETLINK answers: File exists [ OK ]Bringing up interface eth3: RTNETLINK answers: File exists [ OK ]

配置使绑定立即生效

[root@LVS-2 network-scripts]# ifenslave bind0 eth2 eth3

测试联通

[root@LVS-2 network-scripts]# ping 10.0.0.8PING 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 ms64 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 1921msrtt min/avg/max/mdev = 0.046/0.067/0.089/0.023 ms

此时会发现系统多一个网卡

[root@LVS-2 network-scripts]# ifconfig bind0bind0 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.0inet6 addr: fe80::20c:29ff:fecc:9b55/64 Scope:LinkUP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1RX packets:151 errors:0 dropped:0 overruns:0 frame:0TX packets:3 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:11826 (11.5 KiB) TX bytes:258 (258.0 b)

以上是Linux系统如何配置双网卡绑定的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!