Laying the Foundation: The localhost Interface

 < Day Day Up > 

Laying the Foundation: The localhost Interface

Prior to connecting to the Internet or network, you must create a dummy or localhost interface. This interface, known as lo (the loopback interface), is used by the TCP/IP protocol to assign an IP address to your machine and is required for establishing a PPP interface. The lo interface is also used by many network-aware applications and is easy to set up.

Checking for the Availability of the Loopback Interface

Fedora Core normally takes care of setting up this interface during the installation. You can use the ifconfig command as root to see if it is already available. The command and its response will look similar to this if lo is available:

 # /sbin/ifconfig lo        Link encap:Local Loopback           inet addr:127.0.0.1  Mask:255.0.0.0           UP LOOPBACK RUNNING  MTU:16436  Metric:1           RX packets:12 errors:0 dropped:0 overruns:0 frame:0           TX packets:12 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:0           RX bytes:760 (760.0 b)  TX bytes:760 (760.0 b) 

The sample output shows that the loopback interface is active and running, that it has been assigned the typical loopback IP address 127.0.0.1, that the broadcast mask of 255.0.0.0 is used, and that the interface hasn't had much traffic (RX = receive and TX = transmit). If you don't see something similar to the example, you'll need to configure the localhost interface by hand after reading the remainder of this section. Otherwise, you can skip to the next section.

Configuring the Loopback Interface Manually

The localhost interface's IP address is defined in a text file that can be used by Fedora Core Linux to store network IP address information. This file is called /etc/hosts and should exist on a system even if it's empty. The file provides IP addresses and associated hostnames to the Linux kernel and other network-related utilities. Prior to configuring network interfaces, you might find that the /etc/hosts file only contains a single 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. You can read more about networking in Chapter 17.

Each networked Fedora Core Linux machine on a LAN will use this same IP address for its localhost. If for some reason a Fedora Core Linux 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 the ping to check that the interface is responding properly like this (using either localhost or its IP address):

 # /bin/ping -c 3 localhost PING localhost.localdomain (127.0.0.1) from 127.0.0.1 : 56(84) bytes of data. 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=0 ttl=255 time=212 \ usec 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=1 ttl=255 time=80 usec 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=2 ttl=255 time=50 usec --- localhost.localdomain ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max/mdev = 0.050/0.114/0.212/0.070 ms 

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

     < Day Day Up > 


    Red Hat Fedora 4 Unleashed
    Red Hat Fedora 4 Unleashed
    ISBN: 0672327929
    EAN: 2147483647
    Year: 2006
    Pages: 361

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