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 creating a localhost
interface, sometimes also called a l oopback interface , but more commonly referenced as lo
. The TCP/IP protocol (see "Networking with TCP/IP" later in this chapter) uses this interface to assign an IP address to your computer and is needed for Fedora to establish a PPP interface.
Checking for the Availability of the Loopback Interface
You should not normally have to manually create a loopback interface because Fedora 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
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)
What you see in this example is evidence that the loopback interface is present and active. It shows that 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 preceding one, 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 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.
The basic building block for any network based on UNIX hosts is the Transport Control Protocol/Internet Protocol (TCP/IP) suite of three protocols. The suite consists of the Internet Protocol (IP), Transport Control Protocol (TCP) , and Universal Datagram Protocol (UDP) . IP is the base protocol. The TCP/IP suite is packet-based, which means that data is broken into little chunks on the transmit end for transmission to the receiving end. Breaking data up into manageable packets allows for faster and more accurate transfers. In TCP/IP, all data travels via IP packets, which is why addresses are referred to as IP addresses. It is the lowest level of the suite.
TCP is a connection-based protocol. Before data is transmitted between two machines, a connection is established between them. When a connection is made, a stream of data is sent to the IP to be broken into the packets that are then transmitted. At the receiving end, the packets are put back in order and sent to the proper application port. TCP/IP forms the basis of the Internet; without it, the Internet would be a very different place indeed, if it even existed!
On the other hand, UDP is a connectionless protocol. Applications using this protocol just choose their destination and start sending. UDP is normally used for small amounts of data or on fast and reliable networks. If you are interested in the internals of TCP/IP, see the "Reference" section at the end of this chapter for places to look for more information.
Fedora and Networking
Chances are that your network card was configured during the installation of Fedora. You can, however, use the ifconfig
command at the shell prompt or Fedora's graphical network configuration tools, such as system-config-network,
to edit your system's network device information or to add or remove network devices on your system. Hundreds of networking commands and utilities are included with Fedora — far too many to cover in this chapter and more than enough for coverage in two or three volumes.
Nearly all ethernet cards can be used with Linux, along with many PCMCIA wired and wireless network cards. The great news is that many USB wireless network devices also work just fine with Linux, and more will be supported with upcoming versions of the Linux kernel. Check the Linux USB Project at http://www.linux-usb.org/ for the latest developments or to verify support for your device.
After reading this chapter, you might want to learn more about other graphical network clients for use with Linux. The GNOME ethereal
client, for example, can be used to monitor all traffic on your LAN or specific types of traffic. Another client, NmapFE, can be used to scan a specific host for open ports and other running services.
Читать дальше