Laying the Foundation: The localhost Interface


Laying the Foundation: The localhost Interface

The first thing that needs to happen before you can successfully connect to a network or even to the Internet is to create a localhost interface, sometimes also called a loopback interface, but more commonly referenced as lo. The TCP/IP protocol (see "Networking with TCP/IP" later on in this chapter) uses this interface to assign an IP address to your computer and is needed for Ubuntu to establish a PPP interface.

Checking for the Availability of the Loopback Interface

You should not normally have to manually create a loopback interface as Ubuntu creates one automatically for you during installation. To check that one is set up, you can use the ifconfig command while working as root to show something similar to this:

$ ifconfig lo        Link encap:Local Loopback           inet addr:127.0.0.1  Mask:255.0.0.0           inet6 addr: ::1/128 Scope:Host           UP LOOPBACK RUNNING  MTU:16436  Metric:1           RX packets:13 errors:0 dropped:0 overruns:0 frame:0           TX packets:13 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:0           RX bytes:832 (832.0 b)  TX bytes:832 (832.0 b) 


What you see in this example is evidence that the loopback interface is present and active. The inet addr is the IP number assigned to the localhost, typically 127.0.0.1 along with the broadcast mask of 255.255.255.0 and that there has been little activity on this interface (RX = receive and TX = transmit). If your output does not look like the one above, you must hand-configure the localhost interface after you finish the rest of this section.

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 localhost interface and assigns it an IP address of 127.0.0.1. You might hear or read about terms such as localhost, 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:

# /sbin/ifconfig lo 127.0.0.1 # /sbin/route add 127.0.0.1 lo 


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 (in-memory) 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.



Ubuntu Unleashed
Ubuntu Unleashed 2011 Edition: Covering 10.10 and 11.04 (6th Edition)
ISBN: 0672333449
EAN: 2147483647
Year: 2006
Pages: 318

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net