Книга: Fedora™ Unleashed, 2008 edition
Configuring the Loopback Interface Manually
Configuring the Loopback Interface Manually
The localhost
interface's IP address is specified in a text configuration file that is used by Fedora to keep record of various networkwide 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, 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 Fedora machine on a LAN will use this same IP address for its localhost.
If for some reason a Fedora 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:
# ifconfig lo 127.0.0.1
# route add 127.0.0.1 lo
These commands create the localhost
interface in memory (all interfaces, such as eth0
or ppp0
, are created in memory with 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.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), returns information regarding the round-trip speed of a test packet sent to the specified host.
- Laying the Foundation: The localhost Interface
- Checking for the Availability of the Loopback Interface
- 4.4.4 The Dispatcher
- About the author
- Chapter 7. The state machine
- Chapter 5 Installing and Configuring VirtualCenter 2.0
- Chapter 15. Graphical User Interfaces for Iptables
- Appendix E. Other resources and links
- Example NAT machine in theory
- The final stage of our NAT machine
- Compiling the user-land applications
- The conntrack entries