Centos7--shell script automatically implements bond configuration

Source: Internet
Author: User

#!/bin/bash# Create a link interface named Bond0 ip=$1gate=192.168.18.1eth1=eno1eth2=eno2#eth3=eno3#eth4=eno4modprobe bonding# Back up the NIC 1 file cp /etc/sysconfig/network-scripts/ifcfg-$ETH 1 ifcfg-$ETH 1.bak# Modify the NIC Profile function bond0 () { Cat<<eof > /etc/sysconfig/network-scripts/ifcfg-bond0device=bond0type=bondname=bond0bonding _master=yesbootproto=staticuserctl=noonboot=yesipaddr= $IPNETMASK =255.255.255.0gateway= $GATEBONDING _opts= "mode= 4 miimon=100 "Eof}bond0function eth1 () {cat<<eof > /etc/sysconfig/network-scripts/ ifcfg-$ETH 1type=ethernetbootproto=nonedevice= $ETH 1onboot=yesmaster=bond0slave=yeseof}eth1function eth2 () { cat<<eof > /etc/sysconfig/network-scripts/ifcfg-$ETH 2type=ethernetbootproto=nonedevice=$ eth2onboot=yesmaster=bond0slave=yeseof}eth2systemctl stop networkmanager.servicesystemctl  disable networkmanager.servicesystemctl restart network.serviceping  $GATE  -c 1

Execute directly after download: Bash file name. SH IP Address

such as: 192.168.10.10

Execution: Bash bond.sh 192.168.10.10

Server: DELL r730xd NIC is dual gigabit, double gigabit

Operating system: CENTOS7

Implementation: Automatic bond configuration after automated installation


The below script is the network Port 1 and the network Port 2 to achieve bond, if you have special requirements to remove comments. The details of the bond pattern are placed behind the script,

For everyone's reference.

* Configuration mode is bond4,bond4 need to coordinate with the switch's aggregation LACP mode, if you need to modify the mode, change the script red

Numbers can



the seven modes of bond are:
1. mode=0 (BALANCE-RR) (Balanced rotation strategy)
Link load balancing increases bandwidth, supports fault tolerance, and a link failure automatically switches the normal link. The switch needs to configure the aggregation port, Cisco is called the Port channel.
Features: transmission packet sequence is transmitted sequentially (that is: the 1th packet to go eth0, the next package will go eth1 ....), which provides load balancing and fault tolerance until the last transmission is complete); but we know that if a connection
Or a session of the packet from a different interface, and then through a different link, the client is likely to have a packet out of order to arrive at the problem, and the unordered arrival of the packet needs to be sent again, so that the network throughput will fall


This is the main standby mode, Only one network card is active, the other is a spare standby, all traffic is processed on the active link, the switch is configured to bind the word will not work, because the switch to two network card bundle, half of the packet is discarded.
only one device is active, When one goes down the other is immediately converted from backup to primary device. The MAC address is externally visible, and from the outside, the MAC address of the bond is unique to avoid the switch from confusing.


means XOR Hash load sharing, and the aggregation of the switch to force the non-negotiation mode of cooperation. (Requires xmit_hash_policy, switch configuration port channel)
transmits packets based on the specified transport hash policy. The default policy is: (Source MAC address XOR destination MAC address)% slave number. Other transport policies can be specified through the Xmit_hash_policy option, which provides load balancing and fault tolerance


means all packets are emitted from all network interfaces , this unbalanced, only redundant mechanism, but too wasteful of resources. This mode is suitable for the financial industry because they require a highly reliable network and do not allow any problems. The aggregation of the switch needs to be forced to mate with the non-negotiated mode.
transmits each packet on each slave interface, This mode provides fault tolerance


means support for 802.3AD protocol, and aggregation of switches L ACP mode Fit (requires Xmit_hash_ Policy). Standard requires all devices to be in the same rate and duplex mode when aggregating operations, and, as with other bonding load balancing modes other than BALANCE-RR mode, no connection can use more than one interface's bandwidth.
creates an aggregation group that shares the same rate and duplex settings. Multiple slave are working under the same active aggregate according to the 802.3AD specification.


slave is selected according to the load situation of each slave To send, using the current turn of the slave when it is received. This mode requires some kind of ethtool support for the network device driver of the Slave interface, and ARP monitoring is not available.
does not require any special switch (switch) The supported channel bonding. Out-of-office traffic is allocated on each slave based on the current load (calculated based on speed). If the slave that is accepting data fails, the other slave takes over the MAC address of the failed slave.

ethtool support for getting the rate per slave

7, Mode=6 (BALANCE-ALB) (Adapter Adaptive load balancer)
RLB (Receive load-balanced receive-load balance) was added on a 5 TLB basis. No switch support is required. Receive load balancing is implemented through ARP negotiation.
Features:This mode includes the BALANCE-TLB mode, plus receive load balancing for IPV4 traffic (receive load balance, RLB), and does not require any switch (switch) support. Receive load balancing is implemented through ARP negotiation. The bonding driver intercepts the ARP response sent by the native and overwrites the source hardware address with the unique hardware address of one of the slave in bond, allowing different peer-to-peer communication using different hardware addresses.
Receive traffic from the server side is also balanced. When the native sends an ARP request, the bonding driver copies and saves the IP information from the ARP packet to the peer. When the ARP response arrives from the peer, the bonding driver extracts its hardware address and initiates an ARP response to one of the slave in Bond.
One problem with the use of ARP negotiation for load balancing is that the hardware address of the bond is used every time the ARP request is broadcast, so when the peer learns the hardware address, the incoming traffic will flow to the current slave. This problem can be resolved by sending updates (ARP responses) to all the peers, which contain their unique hardware address, which results in the redistribution of traffic.
When a new slave is added to bond, or an inactive slave is reactivated, the incoming traffic is also re-distributed. The received load is distributed sequentially (round robin) on the highest speed slave in bond
When a link is re-connected, or a new slave is added to bond, the receive traffic is redistributed in all currently active slave, initiating an ARP reply to each client by using the specified MAC address. The Updelay parameter described below must be set to a value that is greater than or equal to the switch forwarding delay to ensure that the ARP response destined to the peer is not blocked by the switch.


This article is from the "Silver Luo nine tian" blog, please be sure to keep this source http://luojiutian.blog.51cto.com/4719819/1982015

Centos7--shell script automatically implements bond configuration

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.