Home > Operation and Maintenance > Linux Operation and Maintenance > Example tutorial on network interface configuration Bonding

Example tutorial on network interface configuration Bonding

PHP中文网
Release: 2017-06-21 13:46:03
Original
2370 people have browsed it

Bonding

is about binding the fast network card to the same IP address for external services, which can achieve high availability or load balancing. Of course, it is impossible to directly set the same IP address for two network cards. Through bonding, a virtual network card provides external connections, and the physical network card is modified to the same MAC address.

One Bonding working mode

Mode 0 (balance-rr)

Round-robin strategy: Send data packets sequentially from beginning to end on each slave interface. This mode provides load balancing and fault tolerance capabilities.

Mode 1 (active-backuop)

Active-backup (active-backup) strategy: In the binding, only one slave is activated when and only the active slave interface fails. Activate other slaves. In order to avoid confusion on the switch, the bound MAC address is only visible on one external port.

Mode 3 (broadcast)

Broadcast strategy: Send all messages on all slave interfaces. This mode provides fault tolerance.

Second Bonding configuration

1 Create the configuration file of the bonding device

[root@CentOS68 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
Copy after login

DEVICE=bond0

BOOTPROTO=none

BONDING_OPTS="miimon=100 mode=0"

IPADDR=200.200.200.200

PREFIX= 24

GATEWAY=200.200.200.1

miimon is the time to set the link detection, in milliseconds. If miimon=100, then the system checks the connection status of one side of the link every 100 milliseconds. If one line is unavailable, it will switch to another line.

mode is used to specify the mode

2 Create the slave configuration file

It is the configuration file of the network card to be added. Here we use eth1 and eth2 Two network cards, come down and modify the configuration of the two network cards

[root@CentOS68 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
Copy after login

DEVICE=eth1

TYPE=Ethernet

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=0

MASTER specifies which bond the test network card belongs to. SLAVE specifies the affiliation. USERCTL specifies whether the user has control permissions.

The configuration of eth2 and eth1 is similar

[root@CentOS68 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth2
Copy after login

DEVICE=eth2

TYPE=Ethernet

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=0

3 Restart the network service

[root@CentOS68 ~]# service NetworkManager stop #centos6上不稳定,建议关闭
[root@CentOS68 ~]# service network restart
Copy after login

Shutting down interface bond0: [ OK ]

Shutting down interface eth0: [ OK ]

Shutting down loopback interface: [ OK ]

Bringing up loopback interface: [ OK ]

Bringing up interface bond0: Determining if ip address 200.200.200.200 is already in use for device bond0...

[ OK ]

Bringing up interface eth0: Determining if ip address 192.168.29.68 is already in use for device eth0...

[ OK ]

You can see that it has been started successfully. Let’s look at the IP address and MAC

[root@CentOS68 ~]# ip a
Copy after login

[……]

7: eth1: mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000

link/ether 00:0c:29:74:74:45 brd ff:ff:ff:ff:ff:ff

8: eth2: mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000

link/ether 00:0c:29:74:74:45 brd ff:ff:ff:ff:ff:ff

9: bond0: mtu 1500 qdisc noqueue state UP

link/ether 00:0c:29:74:74:45 brd ff:ff:ff :ff:ff:ff

inet 200.200.200.200/24 ​​brd 200.200.200.255 scope global bond0

inet6 fe80::20c:29ff:fe74:7445/64 scope link tentative dadfailed

valid_lft forever preferred_lft forever

You can see that the IP address has taken effect and the MAC addresses are the same.

4 Check the status of bond0

[root@CentOS68 ~]# cat /proc/net/bonding/bond0
Copy after login

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: load balancing (round-robin)

MII Status: up

MII Polling Interval (ms): 100

Up Delay (ms): 0

Down Delay (ms): 0

Slave Interface: eth1

MII Status: up

Speed: 1000 Mbps

Duplex: full

Link Failure Count: 0

Permanent HW addr: 00:0c:29:74:74:45

Slave queue ID: 0

Slave Interface : eth2

MII Status: up

Speed: 1000 Mbps

Duplex: full

Link Failure Count: 0

Permanent HW addr: 00:0c:29:74:74:4f

Slave queue ID: 0

Okay, everything is going well

5 Delete bond

[root@CentOS68 ~]# ifconfig bond0 down

[root@CentOS68 ~]# rmmod bonding
Copy after login

Check if the deletion is successful,

[root@CentOS68 ~]# ifconfig bond0
Copy after login

bond0: error fetching interface information: Device not found

已经找不到bond0,说明删除成功。

详细帮助:/etc/share/doc/kernel-doc-version/Documentation/networking/bonding.txt

三 nmcli实现bonding

1 添加bonding接口

[root@centos7 ~]# nmcli connection add type bond con-name mybond0 ifname bond0 mode active-backup
Copy after login

Connection 'mybond0' (cc101e79-3dcb-49ee-8164-89c9e877c315) successfully added.

2添加从属接口

[root@centos7 ~]# nmcli connection add type bond-slave ifname ens34 master mybond0
Copy after login

Connection 'bond-slave-ens34' (9c8ff11a-72ef-4d63-a950-2ab777d2a1ea) successfully added.

[root@centos7 ~]# nmcli connection add type bond-slave ifname ens38 master mybond0
Copy after login

Connection 'bond-slave-ens38' (c40b3e6f-32f4-4d1a-a323-aed2519cf865) successfully added.

注意:如没有指定从属接口连接名,则该名称是接口名称加类型构成

3 启动从属接口

[root@centos7 ~]# nmcli connection up bond-slave-ens34
Copy after login

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/40)

[root@centos7 ~]# nmcli connection up bond-slave-ens38
Copy after login

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/41)

4 启动bonding 绑定

[root@centos7 ~]# nmcli connection up mybond0
Copy after login

Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/48)

5 查看绑定

[root@centos7 ~]# nmcli connection show
Copy after login

NAME UUID TYPE DEVICE

bond-slave-ens34 9c8ff11a-72ef-4d63-a950-2ab777d2a1ea 802-3-ethernet ens34

bond-slave-ens38 c40b3e6f-32f4-4d1a-a323-aed2519cf865 802-3-ethernet ens38

mybond0 cc101e79-3dcb-49ee-8164-89c9e877c315 bond bond0

6 添加IP地址

[root@centos7 ~]# nmcli connection modify mybond0 ipv4.method manual ipv4.addresses 200.1.1.1/24
Copy after login

7 删除bond绑定

(1)关闭bond

[root@centos7 ~]# nmcli connection down mybond0
Copy after login

Connection 'mybond0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/18)

[root@centos7 ~]#

(2)删除bond

[root@centos7 ~]# nmcli connection delete mybond0
Copy after login

Connection 'mybond0' (9ed2f027-bbb1-44d1-87fc-7f7275d7fe70) successfully deleted.

(3)删除从属接口

[root@centos7 ~]# nmcli connection delete bond-slave-ens34
Copy after login

Connection 'bond-slave-ens34' (a46ad620-d4b5-43f9-a73a-447785504a17) successfully deleted.

[root@centos7 ~]# nmcli connection delete bond-slave-ens38

Connection 'bond-slave-ens38' (66b1f44d-ad71-4576-8061-f6cba2b976e8) successfully deleted.

 

好了

The above is the detailed content of Example tutorial on network interface configuration Bonding. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template