Implementation of Binding Configuration of Dual Network Cards in Linux System

  • 2021-08-12 04:22:14
  • OfStack

System version


[root@ ~]# cat /etc/redhat-release 

CentOS release 6.8 (Final)

[root@ ~]# uname -r

2.6.32-642.6.1.el6.x86_64

Network card description

eth0 192.168. 1.8 (external server network card)
eth1
eth2
Two server network cards (intranet)

Close the firewall


[root@ ~]# /etc/init.d/iptables stop

[root@ ~]# chkconfig iptables off

Turn off selinux


[root@ ~]#setenforce 0 
[root@ ~]#sed -i  ' s/SELINUX=enforcing/SELINUX=disabled/ '  /etc/selinux/config

Disable NetworkManager


[root@ ~]# /etc/init.d/NetworkManager stop

Stopping NetworkManager daemon:      [ OK ]

[root@ ~]# chkconfig NetworkManager off

[root@ ~]# /etc/init.d/network restart

Edit eth1 network card


[root@ ~]# cd /etc/sysconfig/network-scripts/
[root@ network-scripts\]# cat >ifcfg-eth1 <<EOF
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bind0
EOF

Edit eth2 network card


[root@ network-scripts]# cat >ifcfg-eth2 <<EOF    
DEVICE=eth2
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bind0
EOF

Edit bind0 network card


[root@ network-scripts]# cat >ifcfg-bind0 <<EOF
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

Configure bond parameters


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

Add boot self-startup (/etc/rc. local)


[root@ network-scripts]# cat >>/etc/rc.local <<EOF

ifenslave bind0 eth1 eth2

EOF

Restart network services


[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 ]

Configure for binding to take effect immediately


[root@ ~]# /etc/init.d/iptables stop

[root@ ~]# chkconfig iptables off

0

Test connectivity


[root@ ~]# /etc/init.d/iptables stop

[root@ ~]# chkconfig iptables off

1

At this time, you will find that the system has one more network card


[root@ ~]# /etc/init.d/iptables stop

[root@ ~]# chkconfig iptables off

2

Related articles: