Implementing multi-NIC bindings under Linux

Source: Internet
Author: User

Bind multiple network cards with BIND

Because of the availability of the server on the requirements are relatively high, for each function will have a redundant design, such as disk, power, network card, and even the server itself, and so on, today try to do a network card binding implementation of network card redundancy.
The implementation of the NIC bindings looks somewhat like a hard disk implementing a logical volume, and is achieved by creating a logical device. The binding of the NIC is actually quite simple and easier to understand than a logical volume.
First, we create a file in the/etc/sysconfig/network-scripts/directory, the file name is usually called ifcfg-bondxx, in addition to the ifcfg-behind the content can be defined in fact, but usually written as bind, etc. The content of the file is actually the same as the contents of the normal NIC configuration file, just like this

DEVICE=bond1BOOTPROTO=staticIPADDR=172.20.16.121GATEWAY=172.20.0.1PREFIX=16BONDING_OPTS="miimon=100 mode=1"

The first line of device is the name you assign to the logical appliance, which is the same as the second half of the file name.
The second line is the acquisition of the specified IP, you can also write DHCP to get him automatically, if it is automatically obtained, then ipaddr, gateway and prefix do not need to fill
The last line is more important, must be filled, this is the option to bind the network card, mode represents the working mode of the binding network card, Miimon is a time interval, on behalf of the Backup network card every how often to query the work of the work card. Unit is MS
The above is only the first step, the logical network card has been created, the following will specify those network card belongs to this logical network card. Also very simple, as long as you want to join the logical network card of the physical network card configuration file slightly modified on it. Just like this.

TYPE="Ethernet"BOOTPROTO=staticNAME=eth1MASTER=bond1SLAVE=yesUSERCTL=noDEVICE=eth1ONBOOT=yesIPADDR=192.168.20.110GATEWAY=192.168.0.1PREFIX=16

In fact, the next three lines is invalid, but I am too lazy to delete, the more important is master=bond1,slave=yes, these two lines specify that the network card is a logical network card bond1 slave device, device is also necessary, it refers to the configuration file is to which network card used, The others are not, but it's recommended to write Onboot=yes.
Now that we have added the first NIC to the logical NIC, adding the second block is the same as the first one. Change a file. Not to say.
Then we can restart our network service, in CENTOS7 with Systemctl Restart network can see the results. If there is no problem, you will see the following after executing ifconfig:

[[email protected] network-scripts]# ifconfigbond1:flags=5187<up,broadcast,running,master,multicast> MTU inet 172.20.16.121 netmask 255.255.0.0 broadcast 172.20.255.255 INET6 fe80::250:56ff:fe3b:6a38 p Refixlen ScopeID 0x20<link> ether 00:50:56:3b:6a:38 txqueuelen (Ethernet) RX packets 212 B        Ytes 21252 (20.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX Packets bytes (1000.0 B)   TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0......eth1:flags=6211<up,broadcast,running,slave,multicast>        MTU ether 00:50:56:3b:6a:38 Txqueuelen (Ethernet) RX packets 1224 bytes 176616 (172.4 KiB)  RX errors 0 dropped 0 overruns 0 frame 0 TX Packets 265 bytes 73426 (71.7 KiB) TX errors 0 dropped 0 overruns 0 Carrier 0 collisions 0eth2:flags=6211<up,broadcast,running,slave,multicast> MTU ether 00:50:56:3b:6a:38 Txqueuelen 10XX (Ethernet) Rx Packets 286 Bytes 35478 (34.6 KiB) Rx errors 0 dropped 0 overruns 0 frame 0 TX Packets bytes 5878 (5.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

The most obvious is that there is a network card called BOND1, and there is IP, eth1 and 2 have the same MAC address, and no IP, we can see/proc/net/bonding/bond1 the contents of this file to see the work of Bond1, If you are happy, you can also manually offline a network card to see how this binding device works.
Remember the BOND1 configuration file bonding_opts= "miimon=100 mode=1" this line, in fact, there are several kinds of mode, but we often do not use much, such as Mode0 is the patrol represents the packet will go through each network card, This mode provides load balancing capability and a certain degree of fault tolerance, as well as MODE3, this mode packet will be independent through each network card, each network card will also give a response, that is, every request for data will receive multiple responses. If you want to know more, here's an official document.
Https://www.kernel.org/doc/Documentation/networking/bonding.txt

To bind multiple network cards with a team

You can also use bond for multiple NIC bindings in Centos7, but there are better implementations in CENTOS7 that are recommended for use in CENTOS7. First, the method of modifying the configuration file is bound. The format and steps are no different from bond. Look at the file format.
The first is TEAM0, which is the format of the logical NIC configuration file.

DEVICE=team0DEVICETYPE=TeamTEAM_CONFIG="{\"runner\":{\"name\":\"activebackup\"}}"BOOTPROTO=noneIPADDR=172.20.16.121PREFIX=16NAME=team0ONBOOT=yes

Most of the content is the same, only the third row of team_config some differences, but the third line in addition to activebackup the word, the other parts are not required to change, the word corresponds to the mode section, such as activebackup corresponding Mode1, Other examples include: Broadcast roundrobin Activebackup loadbalance
Then is the configuration from the network card, is similar

DEVICE=eth1DEVICETYPE=TeamPortTEAM_MASTER=team0NAME=eth1ONBOOT=yes

After the configuration file is modified, you can restart the Network service to take effect. There is not much difference between the ifconfig after completion and the previous:

[[email protected] network-scripts]# ifconfigeth1:flags=4163<up,broadcast,running,multicast> MTU 1500  Ether Be:27:a5:16:09:f8 Txqueuelen (Ethernet) Rx Packets bytes 182697 (178.4 KiB) Rx Errors 0 Dropped 0 overruns 0 frame 0 TX Packets 299 bytes 75980 (74.1 KiB) TX errors 0 dropped 0 overruns 0 car RieR 0 Collisions 0eth2:flags=4163<up,broadcast,running,multicast> MTU ether Be:27:a5:16:09:f8 txque        Uelen (Ethernet) Rx Packets 359 bytes 42823 (41.8 KiB) Rx errors 0 dropped 0 overruns 0 frame 0 TX Packets Bytes 6582 (6.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ... team0: Flags=4163<up,broadcast,running,multicast> MTU inet 172.20.16.121 netmask 255.255.0.0 broadcast 172.2 0.255.255 inet6 fe80::bc27:a5ff:fe16:9f8 prefixlen scopeid 0x20<link> ether Be:27:a5:16:09:f8 TX Queuelen (Ethernet) Rx Packets Bytes 3261 (3.1 KiB) Rx errors 0 dropped 0 overruns 0 frame 0 TX Packets bytes S 1326 (1.2 KiB) TX errors 0 dropped 2 overruns 0 carrier 0 collisions 0

Alternatively, you can use the NMCLI command to generate the corresponding configuration file directly

nmcli con add type team con-name team0 ifname team0 config ‘{"runner": {"name": "loadbalance"}}‘nmcli con mod team0 ipv4.addresses 192.168.1.100/24nmcli con mod team0 ipv4.method manualnmcli con add con-name eth1 type team-slave ifname eth1 master team0nmcli con add con-name eth2 type team-slave ifname eth2 master team0nmcli con up team0nmcli con up eth1nmcli con up eth2

The first three lines above can be composed of one line, but it's too long,
Add is added
The type team indicates that the addition of a team type
Con-name Team0 specifying the connection name
IfName TEAM0 represents the specified interface,
Config This part is the configuration information, and the previous handwriting configuration file content format is the same
MoD is to modify the specified connection
Ipv4.addresses Specify IP Address
Ipv4.method manual indicates that IP is specified manually and is automatically selected if it is empty (this option must be added if a manual IP is used)
The next two lines
Type team-slave indicates that the device is a slave device
Master TEAM0 Specifies who the device connection belongs to
The last three lines enable the associated device.
Use TEAMDCTL team0 stat to view details of team connections

Implementing multi-NIC bindings under Linux

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.