Linux multi-NIC configuration and binding

Source: Internet
Author: User

Redhat Linux Network Configuration, is implemented by modifying several configuration files, although you can also use Ifconfig to set the IP, with the route to configure the default gateway, with the hostname to configure the hostname, but the restart will be lost.

Related configuration Files

/ect/hosts Configure the hostname and IP address for the corresponding

/etc/sysconfig/network Configuring hostname and gateway  

/etc/sysconfig/network-scripts/ifcfg-eth0 eth0 configuration file, eth1 file name is ifcfg-eth1

First, the network card configuration

Suppose we want to configure the IP address 192.168.1.11/24 with the hostname Barfoo,eth0, the gateway address 192.168.1.254

The contents of the/etc/sysconfig/network file are as follows:

Networking=yes
Hostname=barfoo
gateway=192.168.1.254

eth0 corresponding configuration file/etc/sysconfig/network-scripts/ifcfg-eth0 content is as follows:

Device=eth0
Bootproto=static
ipaddr=192.168.1.11
netmask=255.255.255.0
Type=ethernet
Onboot=yes

Two, a single network adapter to bind multiple IPs

If you need to configure multiple IPs on a network card, for example, we need to configure IP 192.168.1.12 and 192.168.1.13 for eth0. Then you need to create a new two configuration file under/etc/sysconfig/network-scripts:

ifcfg-eth0:0 content is as follows:

device=eth0:0
Bootproto=static
ipaddr=192.168.1.12
netmask=255.255.255.0
Onboot=yes

ifcfg-eth0:1 content is as follows:

Device=eth0:1
Bootproto=static
ipaddr=192.168.1.13
netmask=255.255.255.0
Onboot=yes

Three, multiple network cards bundled into a virtual network card

In order to provide high availability of the network, we may need to bind multiple network cards into a virtual network card to provide services, so that even if one of the physical NIC fails, it will not cause a connection interruption. For example, we can bind eth0 and eth1 to a virtual NIC Bond0

First, create the BOND0 configuration file for the virtual network card under/etc/sysconfig/network-scripts/ ifcfg-bond0, as follows

Device=bond0
Bootproto=none
broadcast=192.168.1.10
ipaddr=192.168.1.1
netmask=255.255.255.0
network=192.168.1.0
Onboot=yes
Type=ethernet
gateway=192.168.1.250
Userctl=no

============================================================================

or the contents of Ifcfg-bond0 can be written as follows:

/etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE =bond0

ipaddr=192.168.1.10

Prefix=24

Onboot=yes

Usectl=no

Bootproto=none

bonding_opts= " Mode 1 miimon=50 "

Modify the configuration files for eth0 and eth1, respectively

Ifcfg-eth0 content:

Device=eth0
Bootproto=none
Onboot=yes
Userctl=no
Master=bond0
Slave=yes

Ifcfg-eth1 Content

Device=eth1
Bootproto=none
Onboot=yes
Userctl=no
Master=bond0
Slave=yes

Because the Linux virtual network card is implemented in the kernel module, it needs to be installed when the module is loaded. In the /etc/modules.conf file, add the following:

Alias Bond0 Bonding
Options Bond0 miimon=100 mode=1 primary=eth0

Where miimon=100 means check the link connection status every 100ms, if the general switch physical network card
Mode=1 represents the primary standby mode, which means that only one NIC is active and only provides fail-safe. If the mode=0 is in load-balanced mode, all network cards are active, and some other patterns are seldom used
Primary=eth0 indicates that eth0 is the default active NIC in primary and Standby mode

Miimon is the number of milliseconds that trigger an event that detects line stability every 100 milliseconds.
mode is the working state of Ifenslave.
there are altogether 7 ways:
= 0: (BALANCE-RR) round-robin policy: (Balanced polling ring policies): The transmit packet order is transmitted sequentially until the last transmission is complete, which provides load balancing and fault tolerance.
= 1: (active-backup) active-backup policy: (Primary-backup policy): Only one device is active. One goes down and the other immediately transforms the primary device from the backup. The MAC address is externally visible. This mode provides fault tolerance.
= 2: (balance-xor) XOR policy:(Balancing strategy): transmission selects the transmission device according to the original address Boolean value. This mode provides load balancing and fault tolerance.  
= 3: (broadcast) broadcast policy: (Broadcast policy): Transfers all packets to all interfaces. This mode provides fault tolerance.   
= 4: (802.3AD) IEEE 802.3ad Dynamic link aggregation. IEEE 802.3ad Dynamic Link aggregation: Create an aggregation group that shares the same speed and duplex settings. (I don't really understand.) )
= 5: (balance-tlb) Adaptive Transmit load balancing (adapter transport load Balancer): There is no special policy, the first device can not pass through the first device to take over the MAC address that is being processed, help on a pass.
=6: (balance-alb) Adaptive load Balancing: (Adapter transport load balancer): Roughly means including mode5,bonding driver intercepts requests sent by ARP on the local system, Overwrite the original address of the slave device with one of the hardware addresses. It's like a different person on the server using a different hardware address.

These options can be viewed with the command: # modinfo Bonding

Finally, add in the /etc/rc.local

Modprobe Bonding miimon=100 mode=1

Then start the logical network card:

Ifup Bond 0

Use Watch–n 1 ifconfig to monitor network card usage


Note: If you want to load balance, just set here Modprode bonding miimon=100 mode=0 is not enough, you also need to set the port of the switch.

From the principle analysis (bond runs under mode 0):
Mode 0 under Bond the IP of the NIC adapter is modified to the same MAC address, if these network cards are connected to the same switch, then the switch ARP table this MAC address corresponds to a number of ports, then the switch accepts to this MAC address of the packet should go to which port forwarding it? Normally the MAC address is the only one in the world, and a MAC address that corresponds to multiple ports definitely confuses the switch.
So mode0 bond If you connect to the switch, these ports of the switch should be aggregated (Cisco is called Ethernetchannel,foundry called PortGroup), since the switches are aggregated, Several ports under aggregation are also bundled into a MAC address

This article from "Guangzhou, Rain People" blog, please be sure to keep this source http://liulihuan.blog.51cto.com/8018739/1675722

Linux multi-NIC configuration and binding

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.