Implementation of binding and unbinding for Linux dual NIC

Source: Internet
Author: User

? The two-Nic binding implementation is the use of two network card virtual become a network card, the aggregation of the device appears to be a separate Ethernet interface device, the popular point is that two network cards have the same IP address and parallel link aggregation into a logical link work. Depending on the features that the switch can support, the most common is a dual-NIC binding that is set as the primary standby mode. There are seven types of NIC binding modes in Linux: 0. Round robin,1.active-backup,2.load Balancing (XOR), 3.fault-tolerance (broadcast), 4.lacp,5.transmit load balancing,6. Adaptive load Balancing.
First, the Operation procedure
Here is an example of a binding of two network cards. The configuration files are in the/etc/sysconfig/network-scripts/directory.
1. Edit the new ifcfg-bond0 file

# vim/etc/sysconfig/network-scripts/ifcfg-bond0
Device=bond0

Onboot=yes
Bootproto=static

ipaddr=192.168.216.252
netmask=255.255.255.0

gateway=192.168.216.1
bonding_opts= "Mode=1 miimon=100"
This is the actual IP setting of the last bond0 device.
2. Edit Ifcfg-eth0 and ifcfg-eth1 files separately

# Vim/etc/sysconfig/network-scripts/ifcfg-eth0
Device=eth0
Onboot=yes

Bootproto=none
Master=bond0
Slave=yes
# vim/etc/sysconfig/network-scripts/ifcfg-eth1
Device=eth1
Onboot=yes

Bootproto=none
Master=bond0
Slave=yes
3. Modify the/etc/modprobe.d/dist.conf file

# vi/etc/modprobe.d/dist.conf
Add the following content:

Alias Bond0 Bonding
Options Bond0 miimon=100 mode=1

Note: Since this is already written in ifcfg-bond0, this can be added or not added here.
Description

The Miimon is used for link monitoring. For example: miimon=100, then the system every 100MS monitoring link connection status, if one line is not connected to another line;
The value of mode indicates the mode of operation, he has a total of 0,1,2,3 four modes, commonly used for 0, 12 kinds. Depending on the mode of operation available to the switch.
The mode=0 indicates that load balancing (round-robin) is balanced, and both NICs work.
Mode=1 indicates that fault-tolerance (active-backup) provides redundancy, working in a way that the primary and standby means that only one NIC works by default, and the other is backed up.
Note

①bonding can only provide link monitoring, i.e. whether the link from the host to the switch is connected. If only the switch's external link is down, and the switch itself does not fail, then bonding will assume that the link is not a problem and continue to use it.
The mode set by the ② is consistent with the mode set by the switch .

4, Manual Import bonding Drive

#modprobe –i Bonding

5. Restart the Network Service

#service Network Restart

6, verify that the IP has been running on the BOND0 device

#ifconfig


Second, unloading bond0 equipment
To remove a dual-NIC binding system, perform the following actions:

#rm-F/etc/sysconfig/network-scripts/ifcfg-bond0
#vi/etc/etc/modprobe.d/dist.conf
After you delete the following two lines, save the exit

Alias Bond0 Bonding
Options Bond0 miimon=100 mode=1
Finally reconfigure the IP of the eth0 and eth1 and restart the network.
Iii. Automation Scripts
From the above steps can be seen, are fixed work, a user has collated a script out, run #./newbond.sh, the script is as follows:

#!/bin/bash

If [$#-lt 6];then

???? echo "Usage: $ <bond*> <eth*> <eth*> <ipaddress> <netmask> <gateway>"

???? echo "Eg: $ bond0 eth0 eth1 10.0.0.1 255.255.255.0 10.0.0.254"

???? Exit 1

Fi

?

#modify ifcfg-bond* File

echo "device=$1

Ipaddr=$4

Netmask=$5

Gateway=$6

Onboot=yes

Bootproto=none

Userctl=no ">/tmp/ifcfg-$1

Mv-f/tmp/ifcfg-$1/etc/sysconfig/network-scripts/

?

#modify ifcfg-eth0 File

echo "device=$2

Userctl=no

Onboot=yes

Master=$1

Slave=yes

Bootproto=none ">/tmp/ifcfg-$2

Mv-f/tmp/ifcfg-$2/etc/sysconfig/network-scripts/

?

#modify ifcfg-eth1 File

echo "device=$3

Userctl=no

Onboot=yes

Master=$1

Slave=yes

Bootproto=none ">/tmp/ifcfg-$3

Mv-f/tmp/ifcfg-$3/etc/sysconfig/network-scripts/

?

#modify Network File

#sed/gateway/d/etc/sysconfig/network >/tmp/network

#echo "gateway=\" $6\ "" >>/tmp/network

#mv-F/tmp/network/etc/sysconfig/

?

#modify MODULES.COF/MODPROBE.COF

Modconf=/null

tempfile1=/tmp/mod1.$$

tempfile2=/tmp/mod2.$$

Bakfile=/etc/.modconf

?

echo "Please select Your Bond Mode: (balance-rr/active-backup) or (0/1)?"

Read MODE

?

if [-f/etc/modprobe.conf]; Then

???? Modconf=/etc/modprobe.conf

Else

???? Modconf=/etc/modules.conf

Fi

?

CP $MODCONF $BAKFILE

?

Sed '/alias[\t]* ' [\t]*bonding/d;/options[\t]* ' $ ' [\t]*/d;/install.* ' \ d ' $MODCONF > $TEMPFILE 1

CP $TEMPFILE 1 $TEMPFILE 2

?

If ["$ (grep" alias.*bonding "$TEMPFILE 1)"! = ""]; Then

???? bondcount=$ (grep "alias.*bonding" $TEMPFILE 1 | wc-l)

elif ["$ (grep" install.*bond.* "$TEMPFILE 1)"! = ""]; Then

???? bondcount=$ (grep "install.*bond.*" $TEMPFILE 1 | wc-l)

Else

???? Bondcount=0

Fi

?

If ["$bondcount"-ge 1]; Then

???? Sed '/alias.*bonding/d;s/\ (options[\t]*\) \ (bond[0-9]*\)/install\ \2\ \/sbin\/modprobe\--ignore-install\ bonding\-O \ \2/' $TEMPFILE 1 > $TEMPFILE 2

?

???? echo "Install $1/sbin/modprobe--ignore-install bonding-o $ miimon=100 mode= $MODE" >> $TEMPFILE 2

Else

?

???? echo "Alias $ bonding" >> $TEMPFILE 2

???? echo "Options $ miimon=100 mode= $MODE" >> $TEMPFILE 2

Fi????

???? Mv-f $TEMPFILE 2 $MODCONF

?

#restart Network

echo "System would restart network continue (y/n)?"

Read BB

If ["$bb" = "y"] | | ["$BB" = "yes"] | | ["$bb" = "Y"];then

???? For Tempmod in $ (lsmod | grep-i Bond | awk ' {print $} ')

???? Do

???? Modprobe-r bonding-o "$tempmod"

???? Done

?

???? /etc/init.d/network restart

Fi

echo "ok!"

Exit 0

Implementation of binding and unbinding for Linux dual NIC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.