Problem pinging localhost

Problem

I couldn't ping my external IP, 127.0.0.1 or localhost - pinging my external IP 192.168.0.50 returned an error message and pinging localhost just hung until ctrl-c.

# ping 192.168.0.50
connect: Invalid argument
# ping localhost   
PING localhost (127.0.0.1) 56(84) bytes of data.

--- localhost ping statistics ---
100 packets transmitted, 0 received, 100% packet loss, time 99028ms

Looking at the routing table, the loopback (127.0.0.1) route was missing.

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.0.254   0.0.0.0         UG    0      0        0 eth0

...it should have contained the line:

127.0.0.0       127.0.0.1       255.0.0.0       UG    0      0        0 lo

Attempting to add the route failed.

# route add 127.0.0.1
SIOCADDRT: No such device
#  /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 dev lo
SIOCADDRT: No such device

Checking my interface config, it seemed the loopback interface hadn't been started.

# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:10:5C:BB:81:A6  
          inet addr:192.168.0.50  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2516 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2416 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1683688 (1.6 Mb)  TX bytes:336189 (328.3 Kb)

Indeed, running ifconfig lo didn't show UP LOOPBACK RUNNING.

# ifconfig lo
lo        Link encap:Local Loopback  
          LOOPBACK  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

Solution

The solution was simply to start the loopback interface and add the loopback route to the routing table.

# ifconfig lo 127.0.0.1
# route add 127.0.0.1
SIOCADDRT: No such device
#  /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 dev lo
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         192.168.0.254   0.0.0.0         UG    0      0        0 eth0

Bob's your uncle, it worked!

# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.053 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.045 ms

--- localhost ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.045/0.049/0.053/0.004 ms
# ping 192.168.0.50
PING 192.168.0.50 (192.168.0.50) 56(84) bytes of data.
64 bytes from 192.168.0.50: icmp_seq=1 ttl=64 time=0.053 ms
64 bytes from 192.168.0.50: icmp_seq=2 ttl=64 time=0.043 ms

--- 192.168.0.50 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.043/0.048/0.053/0.005 ms

It turned out that net.lo had been removed from all runlevels (probably by me when I was screwing around with eth0/eth1). So, for gentoo, you can just start the loopback interface with /etc/init.d/net.lo start and add it to the boot runlevel with rc-update add net.lo boot.

References

Last modified: 17/04/2006 (most likely earlier as a site migration in 2006 reset some dates) Tags: (none)

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top