Configuring the Loopback Interface Manually

The localhost interface's IP address is specified in a text configuration file that is used by Ubuntu to keep record of various network wide IP addresses. The file is called /etc/hosts and usually exists on a system, even if it is empty. The file is used by the Linux kernel and other networking tools to enable them to access local IP addresses and hostnames. If you have not configured any other networking interfaces then you may find that the file only contains one line:

127.0.0.1 localhost.localdomain localhost

This line defines the special locaihost interface and assigns it an IP address of 127.0.0.1. You might hear or read about terms such as locaihost, loopback, and dummy interface; all these terms refer to the use of the IP address 127.0.0.1. The term loopback interface indicates that to Linux networking drivers, it looks as though the machine is talking to a network that consists of only one machine; the kernel sends network traffic to and from itself on the same computer. Dummy interface indicates that the interface doesn't really exist as far as the outside world is concerned; it exists only for the local machine.

Each networked Ubuntu machine on a LAN will use this same IP address for its localhost. If for some reason a Ubuntu computer does not have this interface, edit the /etc/hosts file to add the localhost enTRy, and then use the ifconfig and route commands as root to create the interface like this:

These commands will create the localhost interface in memory (all interfaces, such as eth0 or ppp0, are created in memory when using Linux), and then add the IP address 127.0.0.1 to an internal (inmemory) table so that the Linux kernel's networking code can keep track of routes to different addresses.

Use the ifconfig command as shown previously to test the interface.

You should now be able to use ping to check that the interface is responding properly like this (using either localhost or its IP address):

$ ping -c 3 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.036 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.028 ms 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.028 ms

--- localhost ping statistics --3 packets transmitted, 3 received, 0% packet loss, time 1999ms rtt min/avg/max/mdev = 0.028/0.030/0.036/0.007 ms

The -c option is used to set the number of pings, and the command, if successful (as it was previously), returns information regarding the round-trip speed of sending a test packet to the specified host.

4 PREV

Was this article helpful?

0 0

Post a comment