When dealing with multiple network interfaces sharing the same gateway, Linux's default route selection can seem unpredictable. From your route -n
output, we can see both eth0 and eth1 have routes to the same network (173.246.100.0/22) with identical metrics (0), and both have default gateways pointing to 173.246.103.254.
# Current routing table showing the ambiguity
Destination Gateway Genmask Flags Metric Ref Use Iface
173.246.100.0 0.0.0.0 255.255.252.0 U 0 0 0 eth1
173.246.100.0 0.0.0.0 255.255.252.0 U 0 0 0 eth0
0.0.0.0 173.246.103.254 0.0.0.0 UG 0 0 0 eth1
0.0.0.0 173.246.103.254 0.0.0.0 UG 100 0 0 eth0
Linux selects default routes based on these factors in order:
- Route metric (lower is preferred)
- Route scope (smaller scope is preferred)
- Interface order in kernel (which varies on boot)
In your case, since both interfaces have routes with metric 0, the kernel falls back to interface order, which explains the random behavior after reboots.
For Ubuntu 10.04, we can modify interface metrics through the interfaces file:
# /etc/network/interfaces
auto eth0
iface eth0 inet static
address 173.246.103.x
netmask 255.255.252.0
gateway 173.246.103.254
metric 10
auto eth1
iface eth1 inet static
address 173.246.103.y
netmask 255.255.252.0
metric 100
For more control, we can use routing rules to prefer certain source addresses:
# Add to /etc/rc.local
ip rule add from 173.246.103.x table 100
ip route add default via 173.246.103.254 dev eth0 table 100
ip route flush cache
For modern Ubuntu systems using Netplan:
# /etc/netplan/01-netcfg.yaml
network:
version: 2
ethernets:
eth0:
addresses: [173.246.103.x/22]
routes:
- to: default
via: 173.246.103.254
metric: 10
eth1:
addresses: [173.246.103.y/22]
routes:
- to: default
via: 173.246.103.254
metric: 100
After applying changes, verify with:
ip route show
ip rule list
route -n
The output should clearly show eth0 as the preferred default route with a lower metric.
When dealing with multiple network interfaces sharing the same gateway in Linux, the system may unpredictably select the default route during boot. This becomes particularly problematic when one interface is significantly slower than the other (like your 100x speed difference between eth0 and eth1).
The kernel's route selection follows these priorities (in order):
- Route with the lowest metric value
- Route with the most specific destination
- Route that was added first in the routing table
In your case, both interfaces have the same gateway and similar routes, making the selection essentially random.
The most reliable way to control interface priority is through the metric value. Lower metrics have higher priority. Here's how to implement this on Ubuntu:
# Edit the interfaces file
sudo nano /etc/network/interfaces
# Configure eth0 (fast interface) with lower metric
auto eth0
iface eth0 inet static
address 173.246.100.x
netmask 255.255.252.0
gateway 173.246.103.254
metric 10
# Configure eth1 (slow interface) with higher metric
auto eth1
iface eth1 inet static
address 173.246.100.y
netmask 255.255.252.0
gateway 173.246.103.254
metric 100
If metrics don't work (some VPS providers override them), you can use routing rules:
# Delete existing default routes
sudo ip route del default via 173.246.103.254
# Add new routes with preferences
sudo ip route add default via 173.246.103.254 dev eth0 proto static metric 10
sudo ip route add default via 173.246.103.254 dev eth1 proto static metric 100
For Ubuntu 10.04, create a script in /etc/network/if-up.d/:
sudo nano /etc/network/if-up.d/fixroutes
#!/bin/sh
if [ "$IFACE" = "eth0" ] || [ "$IFACE" = "eth1" ]; then
ip route del default
ip route add default via 173.246.103.254 dev eth0 metric 10
fi
Make it executable:
sudo chmod +x /etc/network/if-up.d/fixroutes
After implementing these changes, verify with:
ip route show
You should see eth0 as the primary default route with lower metric.