Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of how to bind dual network cards to the same IP under CentOS6 system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

The following will give you a detailed explanation of how to bind dual NICs to the same IP under the CentOS6 system, hoping to bring some help to you in practical application. Load balancing involves more things, there are not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

I just shared with you how to bind dual NICs to the same IP in CentOS6 system a few days ago to achieve network load balancing and high availability. A lot of people must be thinking about how to achieve it in CentOS7, so today I'll share with you how to use the network group of CentOS7 system to achieve the same effect. Netgroup is a technical means to aggregate multiple network cards together to achieve redundancy and improve throughput, but it is different from the old version of bonding technology, which provides better performance and scalability. Netgroup is implemented by kernel drivers and teamd daemons. Next, I'm going to show you how to do it.

I. Environmental needs

Switch equipment: two switches that support dynamic chain aggregation or one ordinary switch

Network card equipment: two network cards

Operation: Centos7.2

2. Introduction of the model

Broadcast-Simple runner which directs the team device to transmit packets via all ports.

Roundrobin-Simple runner which directs the team device to transmits packets in a round-robin fashion.

Activebackup-Watches for link changes and selects active port to be used for data transfers.

Loadbalance-To do passive load balancing, runner only sets up BPF hash function which will determine

Port for packet transmit. To do active load balancing, runner moves hashes among available ports trying

To reach perfect balance.

Lacp-Implements 802.3ad LACP protocol. Can use same Tx port selection possibilities as loadbalance

Runner.

Third, specific creation steps

Step 1: create the netgroup file team0

Nmcli con add type team con-name team0 config'{"runner": {"name": "activebackup", "hwaddr_policy": "by_active"}'

[root@centos7 network-scripts] # nmcli dev status

DEVICE TYPE STATE CONNECTION

Virbr0 bridge connected virbr0

Eno16777728 ethernet connected eno16777728

Eno33554960 ethernet connected Wired connection 1

Virbr0-nic tap connected virbr0-nic

Lo loopback unmanaged--

[root@centos7 network-scripts] # nmcli con add type team con-name team0 config'{"runner": {"name": "activebackup", "hwaddr_policy": "by_active"}'

Connection 'team0' (527769ff-02de-411c-9b26-2725a74cd6e9) successfully added.

[root@centos7 network-scripts] #

What I create here is an active-backup policy, but I specify an extra "hwaddr_policy": "by_active" here. I have also seen many bloggers write about this active backup strategy, but I have never seen anyone point out this option. In fact, it is impossible not to add this option to get a hot replacement of one of the dual network cards. So for those of you who can read my blog, you are happy (because it took me a day and a half to study this option to come to this conclusion)

Step 2: configure static IP and gateway for team0 to boot automatically

[root@centos7 network-scripts] # nmcli con mod team0 connection.autoconnect yes ipv4.method manual ipv4.addresses "10.1.254.254) 16" ipv4.gateway "10.1.0.1"

[root@centos7 network-scripts] # cat ifcfg-team0

The configuration of nmcli will produce the configuration file ifcfg-team* file under / etc/sysconfig/network-scripts, and you can view the configuration results directly.

[root@centos7 network-scripts] # cat ifcfg-team0

DEVICE=team0

TEAM_CONFIG= "{\" runner\ ": {\" name\ ":\" activebackup\ ",\" hwaddr_policy\ ":\" by_active\ "}"

DEVICETYPE=Team

BOOTPROTO=none

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

NAME=team0

UUID=c1726372-479f-4ebe-aa12-7e76d702ddd0

ONBOOT=yes

IPADDR=10.1.254.254

PREFIX=16

GATEWAY=10.1.0.1

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

[root@centos7 network-scripts] #

Step 3: create two port files for team0

Nmcli con add type team-slave con-name team0-port# ifname eno# master team0

Create a port1 file

[root@centos7 network-scripts] # nmcli con add type team-slave con-name team0-port1 ifname eno16777728 master team0

Connection 'team0-port1' (a88c6e0c-5f0c-4d24-a285-2089f7a6e68b) successfully added.

Create a port2 file

[root@centos7 network-scripts] # nmcli con add type team-slave con-name team0-port2 ifname eno33554960 master team0

Connection 'team0-port2' (a103239b-0980-4e63-a465-bc90a8b0958b) successfully added.

[root@centos7 network-scripts] #

Step 4: start the netgroup nmcli con up team#

Nmcli con up team0-- > nmcli con up team0-port1-- > nmcli con up team0-port2

[root@centos7 network-scripts] # nmcli con up team0

[root@centos7 network-scripts] # nmcli con up team0

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

[root@centos7 network-scripts] # nmcli con up team0-port1

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

[root@centos7 network-scripts] # nmcli con up team0-port2

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

[root@centos7 network-scripts] #

Step 5: view the final effect of the configuration

View the current running status of the netgroup

[root@centos7 Desktop] # teamdctl team0 state

Setup:

Runner: activebackup

Ports:

Eno16777728

Link watches:

Link summary: up

Instance[link _ watch_0]:

Name: ethtool

Link: up

Down count: 0

Eno33554960

Link watches:

Link summary: up

Instance[link _ watch_0]:

Name: ethtool

Link: up

Down count: 0

Runner:

Active port: eno16777728

[root@centos7 Desktop] # ifconfig

View the configuration details of the network card

[root@centos7 Desktop] # ifconfig

Eno16777728: flags=4163 mtu 1500

Ether 00:0c:29:06:f9:87 txqueuelen 1000 (Ethernet)

RX packets 1463 bytes 105137 (102.6 KiB)

RX errors 0 dropped 121 overruns 0 frame 0

TX packets 79 bytes 5744 (5.6KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Eno33554960: flags=4163 mtu 1500

Ether 00:0c:29:06:f9:91 txqueuelen 1000 (Ethernet)

RX packets 1510 bytes 108863 (106.3 KiB)

RX errors 0 dropped 126 overruns 0 frame 0

TX packets 214bytes 17571 (17.1 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Lo: flags=73 mtu 65536

Inet 127.0.0.1 netmask 255.0.0.0

Inet6:: 1 prefixlen 128 scopeid 0x10

Loop txqueuelen 0 (Local Loopback)

RX packets 16 bytes 1072 (1.0 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 16 bytes 1072 (1.0 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Team0: flags=4163 mtu 1500

Inet 10.1.254.254 netmask 255.255.0.0 broadcast 10.1.255.255

Inet6 fe80::20c:29ff:fe06:f991 prefixlen 64 scopeid 0x20

Ether 00:0c:29:06:f9:87 txqueuelen 0 (Ethernet)

RX packets 2000 bytes 117274 (114.5 KiB)

RX errors 0 dropped 247 overruns 0 frame 0

TX packets 293 bytes 22841 (22.3KiB)

TX errors 0 dropped 3 overruns 0 carrier 0 collisions 0

Virbr0: flags=4099 mtu 1500

Inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255

Ether 52:54:00:3a:39:12 txqueuelen 0 (Ethernet)

RX packets 0 bytes 0 (0.0B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@centos7 Desktop] #

Step 6: disable one of the network cards at will and test whether the network has high availability

Disable port1 (network card 1) to see if packets are lost during ping (normally 3-4 packets will be lost)

[root@centos7 network-scripts] # nmcli dev dis eno16777728

Device 'eno16777728' successfully disconnected.

[root@centos7 network-scripts] # teamdctl team0 state

Setup:

Runner: activebackup

Ports:

Eno33554960

Link watches:

Link summary: up

Instance[link _ watch_0]:

Name: ethtool

Link: up

Down count: 0

Runner:

Active port: eno33554960

[root@centos7 network-scripts] #

Enable port1, disable port2 (network card 2), and continue to observe the process of ping (normally 3-4 packets will be lost)

[root@centos7 network-scripts] # nmcli con up team0-port1

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

[root@centos7 network-scripts] # nmcli dev dis eno33554960

Device 'eno33554960' successfully disconnected.

[root@centos7 network-scripts] # teamdctl team0 state

Setup:

Runner: activebackup

Ports:

Eno16777728

Link watches:

Link summary: up

Instance[link _ watch_0]:

Name: ethtool

Link: up

Down count: 0

Runner:

Active port: eno16777728

[root@centos7 network-scripts] #

Step 7: if you want to change to another strategy, it is easiest to modify the ifcfg-team0 file directly (pay attention to TEAM_CONFIG=... A change in one line)

[root@centos7 network-scripts] # cat ifcfg-team0

DEVICE=team0

TEAM_CONFIG= "{\" runner\ ": {\" name\ ":\" roundrobin\ "}"

DEVICETYPE=Team

BOOTPROTO=none

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

NAME=team0

UUID=c1726372-479f-4ebe-aa12-7e76d702ddd0

ONBOOT=yes

IPADDR=10.1.254.254

PREFIX=16

GATEWAY=10.1.0.1

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

[root@centos7 network-scripts] #

Disable Nic 1-> disable Nic 2-- > close team0 connection-- > re-enable team0-- > enable port1-- > enable port2

Check the effect of the change (here it is modified into a roundrobin rotation policy, and two network cards need to be connected to two switches that support dynamic chain aggregation to experience the effect of rotation, which cannot be verified by virtual machines)

[root@centos7 network-scripts] # teamdctl team0 state

Setup:

Runner: roundrobin

Ports:

Eno16777728

Link watches:

Link summary: up

Instance[link _ watch_0]:

Name: ethtool

Link: up

Down count: 0

Eno33554960

Link watches:

Link summary: up

Instance[link _ watch_0]:

Name: ethtool

Link: up

Down count: 0

[root@centos7 network-scripts] #

IV. matters needing attention

Starting the netgroup interface does not automatically start the port interface in the netgroup

Starting the port interface in the netgroup interface does not automatically start the netgroup interface

Disabling the netgroup interface automatically disables the port interface in the netgroup

A netgroup interface without a port interface can start a static IP connection

When DHCP connections are enabled, network groups without port interfaces wait for port interfaces to join

After reading the above detailed explanation on how to bind dual network cards to the same IP under the CentOS6 system, if you have anything else you need to know, you can find what you are interested in in the industry information or find our professional and technical engineer to answer, the technical engineer has more than ten years of experience in the industry.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report