Linux multi-nic binding tutorial

Source: Internet
Author: User

Linux multi-nic binding tutorial

Lab environment: Redhat Enterprise Linux 5.2 VMware workstation 7


Figure 1 Nic configuration in the experiment environment: three virtual NICs, working in NAT Mode

1. Configure three NICs and bond0

[Root @ redhat5 ~] # Cd/etc/sysconfig/network-scripts
[Root @ redhat5 network-scripts] # ls | grep ifcfg
Ifcfg-bond0
Ifcfg-eth0
Ifcfg-eth1
Ifcfg-eth2
Ifcfg-lo
[Root @ redhat5 network-scripts] #

Edit the ifcfg-eth0 with the vi Editor, retain the configuration of three parameters on the basis of the reason: DEVICE = eth0, BOOTPROTO = static and ONBOOT = yes, Other
Comment out or delete the parameter value.

[Root @ redhat5 network-scripts] # vi ifcfg-eth0

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE = eth0
BOOTPROTO = static
# BROADCAST = 192.168.249.255
# HWADDR = 00: 0C: 29: 42: 42: 61
# IPADDR = 192.168.249.2
# IPV6INIT = yes
# Define 6_autoconf = yes
# NETMASK = 255.255.255.0
# NETWORK = 192.168.249.0
ONBOOT = yes
~
~
~

Ifcfg-eth0 "11L, 248C

The eth1 and eth2 configurations of the other two NICs are the same as those of eth0:

# Cat ifcfg-eth1 [root @ redhat5 network-scripts] #
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE = eth1
ONBOOT = yes
BOOTPROTO = static
# HWADDR = 00: 0c: 29: 42: 42: 6b
# Cat ifcfg-eth2 [root @ redhat5 network-scripts] #
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE = eth2
ONBOOT = yes
BOOTPROTO = static
# HWADDR = 00: 0c: 29: 42: 42: 75

Create a configuration file ifcfg-bond0 for bond0 with a NIC template:

[Root @ redhat5 network-scripts] # cp ifcfg-eth0 bond0

Modify the ifcfg-bond0 with vi, the content is as follows, retain DEVICE = bond0, BOOTPROTO = static, IPADDR = 192.168.249.2, NETMASK = 255.255.2550.
# Cat ifcfg-bond0 [root @ redhat5 network-scripts] #
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE = bond0
BOOTPROTO = static
# BROADCAST = 192.168.249.255
# HWADDR = 00: 0C: 29: 42: 42: 61
IPADDR = 192.168.249.2
# IPV6INIT = yes
# Define 6_autoconf = yes
NETMASK = 255.255.255.0
# NETWORK = 192.168.249.0
ONBOOT = yes

2. Edit the/etc/modprobe. conf file

Add two lines in the/etc/modprobe. conf file:
Alias bond0 bonding
Options bond0 miimon = 100 mode = 1

[Root @ redhat5/] # cat/etc/modprobe. conf
Alias eth0 pcnet32
Alias scsi_hostadapter mptbase
Alias scsi_hostadapter1 mptspi
Alias scsi_hostadapter2 ata_piix
Alias snd-card-0 snd-ens1371
Options snd-card-0 index = 0
Options snd-ens1371 index = 0
Remove snd-ens1371 {/usr/sbin/alsactl store 0>/dev/null 2> & 1 | |:;};/sbin/modprobe-r -- ignore-remove snd-ens1371
Alias eth1 pcnet32
Alias eth2 pcnet32
Alias bond0 bonding
Options bond0 miimon = 100 mode = 1
[Root @ redhat5/] #

Miimon = 100 indicates that the network card status detection time is 100 milliseconds. Mode parameter table network binding mode. mode 1 only works for one of the three NICs, and the other two are backed up.

3. Make binding take effect in the last step

Service network restart takes effect for nic and bond0 interface configurations
[Root @ redhat5/] # service network restart
Shutting down interface bond0: [OK]
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 bond0: [OK]
Bringing up interface eth0: [OK]
Bringing up interface eth1: [OK]
Bringing up interface eth2: [OK]
[Root @ redhat5/] #

Run ifenslave bond0 eth0 eth1 eth2

[Root @ redhat5/] # ifenslave bond0 eth0 eth1 eth2

To enable the system to automatically run the ifenslave command after the next restart, run the following command:
[Root @ redhat5 init. d] # echo 'ifenslave bond0 eth0 eth1 eth2 '>/etc/rc. local

Check:
[Root @ redhat5/] # cat/etc/rc. local
#! /Bin/sh
#
# This script will be executed * after * all the other init scripts.
# You can put your own initialization stuff in here if you don't
# Want to do the full Sys V style init stuff.

Touch/var/lock/subsys/local
Ifenslave bond0 eth0 eth1 eth2

The preceding command indicates that bond0 is the primary Eni, and the others are the secondary ENI. eth0 is the active secondary Eni, that is, eth0 is used for communication. View bond0 information:
[Root @ redhat5/] # cat/proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28,200 8)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (MS): 100
Up Delay (MS): 0
Down Delay (MS): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 61

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 6b

Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 75

Check the binding effect, and use the host machine to continuously send icmp data packets to the virtual machine. In turn, run down eth0 and eth1 to check whether the network can be connected.


Figure 2 ping a VM


Figure 3 disconnect the eth0 and eth1 NICs of a Virtual Machine



Figure 4 an icmp packet will be lost every time a network card is disconnected

After eth0 and eth1 are disconnected, the active network card is eth2,
[Root @ redhat5/] # cat/proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28,200 8)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (MS): 100
Up Delay (MS): 0
Down Delay (MS): 0

Slave Interface: eth0
MII Status: down
Link Failure Count: 1
Permanent HW addr: 00: 0c: 29: 42: 42: 61

Slave Interface: eth1
MII Status: down
Link Failure Count: 1
Permanent HW addr: 00: 0c: 29: 42: 42: 6b

Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 75
[Root @ redhat5/] #

4. bind multiple NICs to achieve Load Balancing

Modify the/etc/modprobe. conf file, mode = 0, and change the binding mode to Server Load balancer (round-robin ).

[Root @ redhat5 ~] # Cat/etc/modprobe. conf
Alias eth0 pcnet32
Alias scsi_hostadapter mptbase
Alias scsi_hostadapter1 mptspi
Alias scsi_hostadapter2 ata_piix
Alias snd-card-0 snd-ens1371
Options snd-card-0 index = 0
Options snd-ens1371 index = 0
Remove snd-ens1371 {/usr/sbin/alsactl store 0>/dev/null 2> & 1 | |:;};/sbin/modprobe-r -- ignore-remove snd-ens1371
Alias eth1 pcnet32
Alias eth2 pcnet32
Alias bond0 bonding
Options bond0 miimon = 100 mode = 0

[Root @ redhat5 ~] # Cat/proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28,200 8)

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (MS): 100
Up Delay (MS): 0
Down Delay (MS): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 61

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 6b

Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 75

Other modes:
Mode = 2
[Root @ redhat5 ~] # Cap/proc/net/bonding/bond0
-Bash: cap: command not found
[Root @ redhat5 ~] # Cat/proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28,200 8)

Bonding Mode: load balancing (xor)
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (MS): 100
Up Delay (MS): 0
Down Delay (MS): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 61

Slave Interface: eth1
MII Status: down
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 6b

Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 75
Mode = 3
[Root @ redhat5 ~] # Cat/proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28,200 8)

Bonding Mode: fault-tolerance (broadcast)
MII Status: up
MII Polling Interval (MS): 100
Up Delay (MS): 0
Down Delay (MS): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 61

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 6b

Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 75

Mode = 4
[Root @ redhat5 ~] # Cat/proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28,200 8)

Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (MS): 100
Up Delay (MS): 0
Down Delay (MS): 0

802.3ad info
LACP rate: slow
Active Aggregator Info:
Aggregator ID: 1
Number of ports: 1
Actor Key: 9
Partner Key: 1
Partner Mac Address: 00: 00: 00: 00: 00: 00

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 61
Aggregator ID: 1

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 6b
Aggregator ID: 2

Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00: 0c: 29: 42: 42: 75
Aggregator ID: 3

Note that when mode = 0, Server Load balancer can be implemented, but fault tolerance cannot be implemented. These mechanisms must be supported by vswitches. For example, IEEE link aggregation protocol.

Related Article

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.