Sub topic 13
Aggregating Links on a Linux Server
This chapter assumes you know how a port channel works on a switch, including LACP negotiation and hash-based member selection from earlier chapters. It also assumes you can use ip commands and read basic output from /proc. The goal is to build an 802.3ad bond on a Linux host, read its status, and understand where it can go wrong.
Bonding in Linux
Linux calls a link aggregation group a bond. The kernel bonding driver creates a virtual interface, such as bond0, and enslaves physical NICs to it. The bond carries the IP address, VLAN sub-interfaces and routes. The member NICs carry no IP configuration of their own.
The driver supports several modes. Only some of them need cooperation from the switch.
| Mode | Name | Switch support needed | Behavior |
|---|---|---|---|
| 0 | balance-rr | Static port channel | Sends packets round-robin over members. Can reorder packets within a flow. |
| 1 | active-backup | None | One member is active and the others wait. |
| 2 | balance-xor | Static port channel | Picks a member by hash. |
| 4 | 802.3ad | LACP port channel | Negotiates with LACP and picks a member by hash. |
| 5 | balance-tlb | None | Adaptive transmit load balancing. |
| 6 | balance-alb | None | Adaptive transmit and receive load balancing. |
Mode 4 is the Linux counterpart of the switch configuration channel-group 1 mode active. This chapter uses mode 4.
Creating an 802.3ad bond
The following commands create the bond, add two NICs, and display its status. Run them as root. Replace eth0 and eth1 with your interface names.
ip link add bond0 type bond mode 802.3ad miimon 100 lacp_rate fast xmit_hash_policy layer3+4
ip link set eth0 down
ip link set eth0 master bond0
ip link set eth1 down
ip link set eth1 master bond0
ip link set bond0 up
cat /proc/net/bonding/bond0Each parameter has a specific job:
mode 802.3adenables LACP.miimon 100makes the driver check the carrier state of each member every 100 ms. This is how the bond notices a link that has gone down.lacp_rate fastasks the partner to send LACPDUs every 1 second. The default,slow, uses 30 seconds. Fast detects a silent partner sooner.xmit_hash_policy layer3+4hashes IP addresses and TCP/UDP ports to pick the outgoing member.
The kernel requires a member to be down when you enslave it. That is why each ip link set ... down precedes master. The bond brings the member up itself.
The bond can then be configured like any interface. For example, add an address with ip addr add 192.0.2.10/24 dev bond0. These ip commands do not survive a reboot. For persistent configuration use your distribution's tool, such as NetworkManager, systemd-networkd, or netplan, and set the same bond parameters there.
What the switch side must look like
The switch port channel must use LACP, in active or passive mode. At least one side must be active, because two passive sides never start negotiating. The Linux bond in 802.3ad mode behaves as an active LACP speaker.
The member ports on the switch must also match each other in speed, duplex, VLAN and trunk settings, as covered in the member requirements chapter. Use the switch configuration from the earlier chapter:
interface range GigabitEthernet0/1 - 2
switchport mode trunk
switchport trunk allowed vlan 10,20
channel-group 1 mode active
!
interface Port-channel1
switchport mode trunk
switchport trunk allowed vlan 10,20Both NICs of the server must connect to the same switch, or to switches that form a multi-chassis group. Plain 802.3ad bonds across two independent switches do not bundle, because each switch sees a different system ID from the server's perspective only if the partner differs. The driver then keeps one aggregator and leaves the other member unbundled.
Reading the bond status
/proc/net/bonding/bond0 is the Linux equivalent of show etherchannel summary and show lacp neighbor combined. A healthy two-member bond looks like this, abbreviated:
Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer3+4 (1)
MII Status: up
MII Polling Interval (ms): 100
LACP active: on
LACP rate: fast
Min links: 0
Aggregator selection policy (ad_select): stable
802.3ad info
Active Aggregator Info:
Aggregator ID: 1
Number of ports: 2
Actor Key: 9
Partner Key: 1
Partner Mac Address: 00:11:22:33:44:55
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Aggregator ID: 1
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Aggregator ID: 1Check these fields in order:
- Mode and hash policy. Confirm they are what you set.
- Partner Mac Address. If it is
00:00:00:00:00:00, no LACPDUs have arrived from the switch. The partner is not speaking LACP, or the cable goes to the wrong port. - Number of ports under the active aggregator. It should equal the number of members you expect.
- Aggregator ID on each member. Members with different IDs are in different aggregators. The one that does not match the active aggregator is not carrying traffic.
- Speed and duplex. A member that negotiated 100 Mbps cannot join an aggregator of gigabit links.
Two more views help. ip -d link show bond0 shows the bond parameters as the kernel holds them. ip -s link show eth0 shows per-member packet counters, which tell you how traffic is spread.
ip -d link show bond0
ip -s link show eth0
ip -s link show eth1Choosing the transmit hash
xmit_hash_policy controls only traffic leaving the server. The switch uses its own port-channel load-balance setting for traffic toward the server. The two directions are independent, and you often need to tune both.
| Policy | Inputs | Notes |
|---|---|---|
| layer2 | Source and destination MAC | Default. Poor spread if all traffic goes through one gateway MAC. |
| layer2+3 | MAC and IP addresses | Better spread with many peers. |
| layer3+4 | IP addresses and ports | Best spread for many TCP or UDP flows. Fragmented packets may hash differently. |
| encap2+3 and encap3+4 | Inner headers of tunnels | Useful for VXLAN or GRE traffic. |
With layer2, a server whose traffic all passes through a single router MAC sends everything out of one member. That is the most common cause of one link running hot while the other is idle.
The same rule from the distribution chapter applies here. A hash maps a given flow to one member, so a single TCP stream never exceeds the speed of one member. The model below shows why. The same flow tuple gives the same member every time.
import zlib
def pick_member(src_ip, dst_ip, src_port, dst_port, proto, n_links):
key = f"{src_ip}|{dst_ip}|{src_port}|{dst_port}|{proto}".encode()
return zlib.crc32(key) % n_links
# The same flow always maps to the same member link.
flow = ("10.0.0.5", "10.0.1.9", 50000, 443, "tcp")
print(pick_member(*flow, n_links=2) == pick_member(*flow, n_links=2))The Linux kernel uses its own hash function, not CRC32, so this code predicts the principle and not the exact member chosen.
Failure behavior
When a member loses carrier, miimon notices within its polling interval, and the driver removes the member from the aggregator. Flows that hashed to it are rehashed onto the remaining members. TCP sessions typically survive with a brief pause.
The min_links parameter sets how many members must be in the active aggregator for the bond to report carrier. For example, min_links 2 takes the whole bond down if only one member remains. Use this when a single remaining link would be overloaded and you prefer to fail over to another path.
You can also lose a bundle without any carrier change. If the switch stops sending LACPDUs, the member times out after three missed LACPDUs, which is about 3 seconds with lacp_rate fast and about 90 seconds with slow. This is why the fast rate matters when miimon cannot see the fault, such as with a media converter or a misconfigured switch in the middle.
Common problems
| Symptom | Likely cause | What to check |
|---|---|---|
| Partner MAC is all zeros | Switch is not sending LACPDUs | Switch uses `mode on` or the ports are not in a channel group |
| One member has a different Aggregator ID | Member connects to a different switch, or has a different speed | Cabling, `Speed:` line, switch member settings |
| One member carries nearly all traffic | Hash policy has too little variety | Change to `layer3+4`, then compare `ip -s link` counters |
| Bond works one way only | Hash policy differs between server and switch | Check `show etherchannel load-balance` on the switch |
| Bond fails after reboot | Configuration was entered with `ip` only | Move to persistent network configuration |
Exercise
A two-member 802.3ad bond reports Partner Mac Address: 00:00:00:00:00:00 and each member shows a different Aggregator ID. Both cables run to the same switch. Name two checks you would make and the commands you would use.
Show answer
First, on the switch, run show etherchannel summary and show lacp neighbor to confirm the two ports are in a channel group with mode active or passive, not mode on, and that they are sending LACPDUs. Second, on the server, read /proc/net/bonding/bond0 to confirm the mode is 802.3ad and the members are up at the same speed and duplex. An all-zero partner MAC means no LACPDUs are arriving, so the switch side is the most likely cause.
Exercise
A server has a bond with xmit_hash_policy layer2. All its traffic goes to a single default gateway, and eth0 carries all of it while eth1 is idle. Which change fixes this, and does it also change the traffic that the switch sends toward the server?
Show answer
Change the policy to layer3+4 so the hash includes IP addresses and ports, which vary per flow. This affects only server-to-switch traffic. Traffic toward the server is spread by the switch's port-channel load-balance setting, which you must tune separately.