The system in question has two network interfaces with the following configuration:
eth0:
- IP: 192.168.36.132
- Netmask: 255.255.254.0 (/23)
- Broadcast: 192.168.37.255
eth1:
- Public IP: 116.xx.xx.xx
- Netmask: 255.255.255.192 (/26)
The administrator attempted to add a static route for network 10.248.12.0/28 via gateway 192.168.36.254 on eth0 interface:
route add -net 10.248.12.0 netmask 255.255.255.240 gw 192.168.36.254 dev eth0
This resulted in the SIOCADDRT: Network is unreachable error, indicating the gateway isn't accessible through the specified interface.
The current routing table shows:
Kernel IP routing table
Destination Gateway Genmask Flags Iface
116.xx.xx.xx 0.0.0.0 255.255.255.192 U eth1
192.168.238.0 192.168.36.254 255.255.255.0 UG eth0
192.168.239.0 192.168.36.254 255.255.255.0 UG eth0
192.168.36.0 192.168.36.254 255.255.254.0 UG eth0
169.254.0.0 0.0.0.0 255.255.0.0 U eth0
127.0.0.0 0.0.0.0 255.0.0.0 U lo
0.0.0.0 116.xx.xx.xx 0.0.0.0 UG eth1
The error occurs because the gateway 192.168.36.254 isn't directly reachable through eth0's network configuration. The system doesn't have a direct route to this gateway within the 192.168.36.0/23 subnet it belongs to.
Here are several ways to resolve this issue:
Method 1: Add a Host Route First
Before adding the network route, first ensure the gateway is reachable:
# Add a host route to the gateway
ip route add 192.168.36.254/32 dev eth0
# Then add the network route
ip route add 10.248.12.0/28 via 192.168.36.254 dev eth0
Method 2: Verify Interface Configuration
Check if the eth0 interface is properly configured:
# Verify interface status
ip link show eth0
# Check IP configuration
ip addr show eth0
# Test basic connectivity
ping -c 3 192.168.36.254
Method 3: Alternative Route Syntax
Try using the iproute2 syntax which often provides better error messages:
ip route add 10.248.12.0/28 via 192.168.36.254
For a persistent solution, add the route to your network configuration:
# For Debian/Ubuntu systems: /etc/network/interfaces
post-up ip route add 10.248.12.0/28 via 192.168.36.254
# For RHEL/CentOS systems: /etc/sysconfig/network-scripts/route-eth0
10.248.12.0/28 via 192.168.36.254
Useful commands for diagnosing routing issues:
# Show all routes
ip route show table all
# Check ARP cache
ip neigh show
# Trace route path
traceroute 10.248.12.1
# Check kernel logs
dmesg | grep -i route
When attempting to add a static route to route traffic through eth0 interface in a Linux system with dual NIC configuration, you encounter the error:
route add -net 10.248.12.0 netmask 255.255.255.240 gw 192.168.36.254 dev eth0
SIOCADDRT: Network is unreachable
The network configuration shows:
eth0: 192.168.36.132/23 (mask 255.255.254.0)
eth1: 116.xx.xx.xx/26 (public IP)
Default gateway: 116.xx.xx.xx via eth1
The error occurs because your system cannot reach the gateway (192.168.36.254) you're trying to use for the new route. This typically happens when:
- The gateway IP isn't in any directly connected network
- There's no existing route to reach the gateway
- The interface specified isn't properly configured
First, verify if your gateway is reachable:
ping 192.168.36.254
arp -n | grep 192.168.36.254
If these fail, you'll need to establish basic connectivity to the gateway before adding routes through it.
Solution 1: Add Direct Network Route First
# Add route to the gateway's network first
ip route add 192.168.36.0/23 dev eth0 proto kernel scope link src 192.168.36.132
# Then add your desired route
ip route add 10.248.12.0/28 via 192.168.36.254 dev eth0
Solution 2: Use ip route instead of route
The modern ip route
command often handles these cases better:
ip route add 10.248.12.0/28 via 192.168.36.254 dev eth0
Solution 3: Check Interface State
Verify eth0 is up and configured properly:
ip link show eth0
ip addr show eth0
If needed, bring it up:
ip link set eth0 up
For persistent routes across reboots, add to /etc/network/interfaces (Debian) or create a route-eth0 file:
# /etc/sysconfig/network-scripts/route-eth0 (RHEL/CentOS)
10.248.12.0/28 via 192.168.36.254 dev eth0
- Check kernel logs:
dmesg | grep eth0
- Verify ARP table:
ip neigh show
- Test connectivity:
traceroute 192.168.36.254
- Check firewall rules that might block traffic
If the gateway truly isn't reachable, you may need to:
- Physically verify the network connection
- Check switch/router configurations
- Confirm the gateway IP is correct
- Test with a different cable or port