Linux Virtual network Interface---bonding configuration

Source: Internet
Author: User
Tags get ip uuid

in daily life, everyone will encounter this situation, in the home can automatically get IP address, work when the company may be banned network, so will provide a private network address for everyone to use, but need everyone to connect the network, more trouble. This requires the configuration of two sets of scenarios for the device, it is convenient to set up a network interface to switch back and forth.

First, to understand the definition of bonding

Bonding is provided by connecting multiple physical network cards of the same device to a single virtual network card. For the outer end, multiple physical network cards share the IP and MAC address of the virtual network card, which is also represented as a network card device. High availability or load balancing can be achieved with bonding technology.

Bonding mode of operation:

Mode 0 Rotation strategy: Send packets on each of the slave interfaces sequentially from beginning to end. This mode provides load balancing and fault tolerance capabilities
Mode 1 (active-backup) activity-Backup (Master) policy: Only one slave is activated, and other slave are activated only if the active slave interface fails. To prevent the switch from confusing, the bound MAC address is visible on only one external port
Mode 3 (broadcast) broadcast strategy: delivers all messages on all slave interfaces, providing fault tolerance

Second, the configuration of Bonding (CENTOS6)

1. Manually add 2 NICs and set them to the same vmnet (VMNET3). Use Ifconfig to see if two NICs are joined

[[email protected] network-scripts]#ifconfigeth2 Link encap:ethernet HWaddr00:0c:29:8f:26: 2A up broadcast RUNNING SLAVE multicast MTU:Metric:1RX Packets:546 errors:0 dropped:0 overruns:0 frame:0TX Packets:errors:0 dropped:0 overruns:0 carrier:0Collisions:0 txqueuelen:1000RX Bytes:164116 (160.2 KiB) TX bytes:938 (938.0b) eth3 Link encap:ethernet HWaddr00:0c:29:8f:26: 2A up broadcast RUNNING SLAVE multicast MTU:Metric:1RX Packets:552 errors:0 dropped:0 overruns:0 frame:0TX Packets:0 errors:0 dropped:0 overruns:0 carrier:0Collisions:0 txqueuelen:1000RX Bytes:164476 (160.6 KiB) TX bytes:0 (0.0b) Lo Link encap:local Loopback inet addr:127.0.0.1 mask:255.0.0.0Inet6 Addr::: 1/128scope:host up LOOPBACK RUNNING MTU:65536 metric:1RX Packets:4 errors:0 dropped:0 overruns:0 frame:0TX Packets:4 errors:0 dropped:0 overruns:0 carrier:0Collisions:0 txqueuelen:0RX Bytes:(240.0 b) TX bytes:240 (240.0 b)

2. Create a configuration file for the bonding device bond0

[[Email protected] ~] # cd/etc/sysconfig/network-scripts/ [Root@centos6 network-scripts] # CP Ifcfg-eth0 Ifcfg-bond0 [[email protected] network-scripts] #  device=bond0 onboot=Yes bonding_opts="miimon=100 mode=1"  ipaddr=10.8.8.8 NETMASK=255.255.255.0 nm_controlled=no

The Miimon is used for link monitoring. If the miimon=100, then the system every 100MS monitoring link connection status, if one line is not connected to another line

Mode is the bonding pattern.

3. Configuring the Slave configuration file

[[email protected] network-scripts]#CP Ifcfg-eth0 Ifcfg-eth2[[email protected] network-scripts]#Vim Ifcfg-eth2Device=eth2 TYPE=Ethernet Onboot=Yes SLAVE=Yes MASTER=bond0 nm_controlled=No[root@centos6 Network-scripts]#CP Ifcfg-eth0 Ifcfg-eth3[Root@centos6 Network-scripts]#Vim Ifcfg-eth3Device=Eth3 TYPE=Ethernet Onboot=Yes SLAVE=Yes MASTER=bond0 nm_controlled=no

4. Restart the Network Service

[[email protected] network-scripts] # Service Network Restart

5. View the status of the bonding

[[email protected] network-scripts]#cat/proc/net/bonding/bond0Ethernet Channel Bonding driver:v3.7.1 (April 27, 2011) Bonding Mode:fault-tolerance (active-backup) Primary Slave:none currently Active slave:eth2 mii status:up mii Polling Interval (ms):100Up Delay (ms):0Down Delay (ms):0Slave interface:eth2mii status:up Speed:1000Mbps duplex:full Link Failure Count:0Permanent HW Addr:00:0c:29:8f:26: 2a Slave queue ID:0Slave interface:eth3 MII status:up Speed:1000Mbps duplex:full Link Failure Count:0Permanent HW Addr:00:0c:29:8f:26:20Slave

5. Change the BOND0 mode of operation

Directly modify mode in the Bond0 configuration file and restart the network service.

6. How to delete bond0 (first off and then delete)

[[email protected] network-scripts] # ifconfig bond0 down [[email protected] network-scripts] # rm–f  ifcfg-bond0

Remove Master from eth2, and slave

Third, Centos7 bonding configuration (centos7 in the command is stronger than CENTOS6)

1. Add 2 network cards in the same vmnet.

2. Using the NMCLI management tool

1) Create a logical NIC Bond0

[[email protected] network-scripts] # nmcli con Add type Bond con-name BOND0 ifname bond0 mode active-backup Connection ' bond0 ' (c505387c-6f85-4af5-bf50-7958d8cf39ef) successfully added.

#add equivalent to auto-generated configuration file

[[email protected] network-scripts] # nmcli con Modify bond0 ipv4.addresses 20.20.20.20/24 ipv4.dns 8.8.8.8 ipv4.gateway 20.20.20.1 ipv4.method manual  Connection.autoconnect yes;--setting bond0 IP

2) Add Slave network interface (add slave scheme to two new NIC)

[[email protected] network-scripts] #  Connection ' slave-38 ' (97708606-56ac-48aa-9014-c23a376c2379) successfully added. [Root@centos7 network-scripts]#   Connection ' slave-39 ' (608dc1a0-9407-45be-a720-4c415b4b8488 ) successfully added.

3. Direct activation of BOND0

[[email protected]  network-scripts]#  nmcli connection up bond0

4. Change the BOND0 mode

[[email protected]] # NMCLI Connection Modify BOND0 mode broadcast

5. Delete the same CENTOS6

IV. Create a network group networking teaming implement similar functions

Network Group: A method that aggregates multiple network cards together to achieve redundancy and increase throughput. But network groups are different from older versions of bonding technology, providing better performance and scalability.

1. Create a network group TEAM0

[[email protected] network-scripts] # NMCLI Connection Add type team con-name TEAM0 ifname team0 config ' {"runner": {"name": "LoadBalance"}} ' Connection ' Team0 ' (9a5ab96b-3cd3-412d-9532-1327c035367c) successfully added.

2. Add a Slave network interface

[[email protected] network-scripts] # nmcli Connection Add con-name slave-38 ifname ens38 type Team-slave master Team0 Connection ' slave-38 ' (e5182e70-86a6-480f-bc14-2d2055bfab9f) successfully added.[ Root@centos7 network-scripts]#  nmcli connection add con-name slave-39 ifname ens39 type team-slave mast Er team0 Connection ' slave-39 ' (e31b4880-0095-4322-af49-63094bbe873d) successfully added.

3. Set the IP of the TEAM0

[[email protected] network-scripts] #

4. Activating team0 and slave

[[email protected] network-scripts] # nmcli connection up Team0  for slaves) (D-bus active path:/org/freedesktop/networkmanager/activeconnection/13) [Root@centos7 Network-scripts]#  nmcli connection up slave-38 connection successfully activated (D-bus active path:/O Rg/freedesktop/networkmanager/activeconnection/16) [root@centos7 network-scripts]#  nmcli Connection up slave-39 connection successfully activated (D-bus active path:/org/freedesktop/networkmanager/ ACTIVECONNECTION/18)

5. Delete Team0

[[email protected] network-scripts]#nmcli connection down Team0Connection ' TEAM0 ' successfully deactivated (d-bus active path:/ORG/FREEDESKTOP/NETWORKMANAGER/ACTIVECONNECTION/13) [Root@centos7 Network-scripts]#nmcli connection down slave-38Connection ' slave-38 ' successfully deactivated (d-bus active path:/org/freedesktop/networkmanager/activeconnection/ 16) [Root@centos7 Network-scripts]#nmcli connection down slave-39Connection ' slave-39 ' successfully deactivated (d-bus active path:/org/freedesktop/networkmanager/activeconnection/ 19) [Root@centos7 Network-scripts]#rm-f ifcfg-slave-3*[[email protected] network-scripts]#rm-f Ifcfg-team0

Experiment: Using NMCLI to configure 2 sets of schemes for the network card, a static acquisition of a DHCP

1. Name of the old scheme (not required)

[[email protected] network-scripts] # nmcli Connection Modify ENS34 connection.id home

2. Automatically get IPv4 address for home scheme settings

[[email protected]] # nmcli Connection Modify Home Ipv4.method Auto

3. Bringing the programme into force

[[email protected] network-scripts] # nmcli connection up home Connection successfully activated (D-bus active path:/ORG/FREEDESKTOP/NETWORKMANAGER/ACTIVECONNECTION/9)

View Scenarios

[[email protected] network-scripts] #  NAME     UUID                                  TYPE      DEVICE ens33    dadb8960-c959-47f5-addb-13f8e439d72d  Ethernet  ens33home  482d5ab5-ac7d-4467-ac09-65440b174331  Ethernet  ens34  Virbr0   1eee137a-f1ea-4fe8-b387-5d0561d76aca  Bridge    

4. The new program is named Office

[[email protected] network-scripts] # NMCLI Connection Add con-name Office type Ethernet ifname ens34

5. Configure a static address for the new scenario

[[email protected] network-scripts] # NMCLI Connection Modify Office Ipv4.method manual Connection.autoconnect Yes ipv4.addresses 8.8.8.8/24 Ipv4.gateway 8 .8.8.1 Ipv4.dns 4.4.4.4

6. Switch to the new scheme and make it effective

[[email protected] network-scripts] # nmcli Connection up office

View Scenarios

[[email protected] network-scripts] #  NAME     UUID                                  TYPE      DEVICE ens33    dadb8960-c959-47f5-addb-13f8e439d72d  Ethernet  ens33office  482d5ab5-ac7d-4467-ac09-65440b174331  Ethernet  ens34  Virbr0   1eee137a-f1ea-4fe8-b387-5d0561d76aca  bridge    virbr0 home2ae365b6- AB9A-4882-8831-E38A362881E2  Ethernet  --     

If you manually modified the configuration file, the following

[[email protected] network-scripts] # Vim/etc/sysconfig/network-scripts/ifcfg-office ipaddr=8.8.8.8PREFIX=24GATEWAY=8.8.8.1DNS1=4.4.4.4

You need to use NMCLI connection reload to reread before you can nmcli connection up

Delete Scenario

[[email protected] network-scripts] # NMCLI Connection Delete office

Linux Virtual network Interface---bonding configuration

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.