Ip route

From Noah.org
Jump to navigationJump to search


I keep running into situations where I'm having some sort of home network trouble so I will bring down my network interface and then bring it up again and afterward my routing table seems screwed up.

# ping www.noah.org
connect: Network is unreachable
# ping 4.2.2.2
connect: Network is unreachable

Things look OK from the LAN side:

# cat /etc/resolv.conf
nameserver 4.2.2.2
nameserver 192.168.1.1

# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:16:cb:aa:37:2a  
          inet addr:192.168.1.200  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::216:cbff:feaa:352a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:218524 errors:0 dropped:0 overruns:0 frame:0
          TX packets:162058 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:186251217 (186.2 MB)  TX bytes:26169040 (26.1 MB)
          Interrupt:16 

# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.801 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.760 ms
^C
# ping 192.168.1.105
PING 192.168.1.105 (192.168.1.105) 56(84) bytes of data.
64 bytes from 192.168.1.105: icmp_seq=1 ttl=64 time=7.02 ms
64 bytes from 192.168.1.105: icmp_seq=2 ttl=64 time=0.234 ms
^C
# ping 192.168.1.200
PING 192.168.1.200 (192.168.1.200) 56(84) bytes of data.
64 bytes from 192.168.1.200: icmp_seq=1 ttl=64 time=0.048 ms
64 bytes from 192.168.1.200: icmp_seq=2 ttl=64 time=0.049 ms
^C

I look at the routing... This doesn't look good:

# ip route
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.200

So I run `dhclient eth0` to force my machine to talk to the gateway again.

# dhclient eth0
Internet Systems Consortium DHCP Client V3.1.1
Copyright 2004-2008 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/

Listening on LPF/eth0/00:16:cb:aa:37:2a
Sending on   LPF/eth0/00:16:cb:aa:37:2a
Sending on   Socket/fallback
DHCPREQUEST of 192.168.1.200 on eth0 to 255.255.255.255 port 67
DHCPACK of 192.168.1.200 from 192.168.1.1
 * Reloading /etc/samba/smb.conf smbd only
   ...done.
bound to 192.168.1.200 -- renewal in 880348675 seconds.

OK, good. It gets a response and the DHCP acknowledges use of the same IP. Check ip route again and it's fixed:

# ip route show
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.200 
default via 192.168.1.1 dev eth0

It can see the world again:

# ping 4.2.2.2
PING 4.2.2.2 (4.2.2.2) 56(84) bytes of data.
64 bytes from 4.2.2.2: icmp_seq=1 ttl=54 time=18.5 ms
64 bytes from 4.2.2.2: icmp_seq=2 ttl=54 time=17.0 ms
^C
# ping www.kernel.org
PING pub.us.kernel.org (204.152.191.37) 56(84) bytes of data.
64 bytes from pub2.kernel.org (204.152.191.37): icmp_seq=1 ttl=56 time=18.4 ms
64 bytes from pub2.kernel.org (204.152.191.37): icmp_seq=2 ttl=56 time=37.2 ms
^C

This all seems to happen just on this one home machine. I understand why it isn't routing because of the tables, but it bugs me that it doesn't just fix itself. Maybe my `dhclient` is messed up on this machine. It doesn't stay running or doesn't check the lease or perhaps there is some way to get `dhclient` to automatically rebroadcast for DHCP server when the kernel gets an "unreachable" event... I'm missing something here. On my other machines the default route seems to fix itself when the interface is brought back up. I have to look into that. I never really dug into what networking does when you bring an interface back up... I bet this is the right direction. I probably disabled some udev thing or something that automatically runs and fixes things when an interface comes up. It's always been automatic so I never thought much about it... Until I found out, I can fix it manually:

# ip route add default via 192.168.1.1
# ip route
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.200 
default via 192.168.1.1 dev eth0
# ping www.kernel.org
PING pub.us.kernel.org (149.20.20.133) 56(84) bytes of data.
64 bytes from pub1.kernel.org (149.20.20.133): icmp_seq=1 ttl=55 time=18.3 ms
64 bytes from pub1.kernel.org (149.20.20.133): icmp_seq=2 ttl=55 time=18.2 ms
^C

Check which ip address and interface are associated with a route

ip route show dev eth0
show ip routes through this interface.
ip route show via 192.168.1.1
show interface for this route.