Operations 18 min read

How to Configure Multiple Default Gateways and Dual NICs on Linux

Learn how to set up default gateways, manage multiple network interfaces, add static routes, and use iproute2 and bonding on Linux to achieve dual‑NIC configurations, load balancing and redundancy, with step‑by‑step commands and examples for various network scenarios.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Configure Multiple Default Gateways and Dual NICs on Linux

About Linux Default Gateway

A default gateway is the IP address of a router that a host sends packets to when no more specific route exists. It can be configured manually or obtained automatically. A host may have multiple network interfaces, but only one default gateway can be set globally.

Single NIC Configuration

For a single network card, set the address, netmask, and gateway, then restart the network service.

Dual NIC Scenarios

When two NICs are present there are three common cases:

One gateway : Assign an IP to each NIC but configure the gateway on only one interface. Traffic uses the gateway‑enabled NIC, while the other NIC can communicate within its local subnet.

Two gateways (complex) : Neither NIC has a default gateway; instead, use route to add specific routes for each subnet and designate one gateway as the default for the desired traffic.

Three NICs : Similar to the two‑NIC case; use iptables or policy routing to separate traffic.

Example of adding a default gateway and a static route:

route add default gw 224.224.224.224 eth0
route add -net 192.168.115.0/24 gw 192.168.1.254 eth1

Policy Routing with iproute2

Use separate routing tables and rules to bind each NIC to its own table. Example:

echo "210    local100" >> /etc/iproute2/rt_tables
echo "220    local200" >> /etc/iproute2/rt_tables

ip route add 192.168.1.0/24 dev wlo0 src 192.168.1.11 table local100
ip route add 192.168.1.0/24 dev eno1 src 192.168.1.22 table local200
ip route add default dev wlo0 table local100
ip route add default dev eno1 table local200

ip rule add from 192.168.1.11 table local100
ip rule add from 192.168.1.22 table local200
ip route flush cache

When one NIC fails, the system automatically selects the remaining NIC's routing table.

Dual NIC Benefits

Network isolation: separate public and private traffic.

Load balancing and redundancy.

Support for virtualized networks.

Bonding (Link Aggregation)

Linux bonding combines multiple NICs into a single logical interface (bond0). Different modes provide load balancing, active‑backup, XOR, broadcast, LACP, and adaptive load balancing.

Typical bonding configuration (CentOS):

# /etc/sysconfig/network-scripts/ifcfg-bond0
TYPE=Ethernet
BOOTPROTO=static
NAME=bond0
DEVICE=bond0
IPADDR="192.168.10.54"
NETMASK=255.255.255.0
GATEWAY=192.168.10.2
ONBOOT=yes
BONDING_OPTS="miimon=100 mode=6"

# Slave interfaces
TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
ONBOOT=yes
MASTER=bond0
SLAVE=yes

TYPE=Ethernet
BOOTPROTO=none
NAME=ens38
DEVICE=ens38
ONBOOT=yes
MASTER=bond0
SLAVE=yes

Load the bonding module and restart the network:

modprobe bonding miimon=100 mode=1
systemctl restart network

Verify the bond status with cat /proc/net/bonding/bond0 and observe which NIC handles traffic using ifconfig or ip addr.

bonding status
bonding status

Removing a Bond

To dismantle the bond, bring down bond0, delete its configuration file, remove it from /sys/class/net/bonding_masters, and reconfigure the slave NICs with static IP settings, then restart the network.

These commands and configurations enable Linux systems to handle multiple gateways, achieve load balancing, and provide redundancy for critical network services.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxNetworkingDefault GatewayBonding
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.