📄 lsg30.htm
字号:
UP BROADCAST LOOPBACK RUNNING MTU:2000 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0
TX packets:12 errors:0 dropped:0 overruns:0</FONT></PRE>
<P>If you get an error message such as unknown interface, the loopback driver does not exist and must be added.
<BR>
<P>Once the ifconfig routine has been checked, add the loopback driver to the kernel routing tables with one of these two commands:
<BR>
<PRE>
<FONT COLOR="#000080">route add 127.0.0.1
route add localhost</FONT></PRE>
<P>It doesn't matter which command you use because they both refer to the same thing. The command essentially tells the kernel that it can use the route for address 127.0.0.1 or the name localhost.
<BR>
<P>As a quick check that all is correct with the loopback driver, you can use the ping command to check the routing (see <A HREF="lsg32.htm">Chapter 32</A>, "Network Utilities," for more information on ping). For example, if you issue either of these two commands
<BR>
<PRE>
<FONT COLOR="#000080">ping localhost
ping 127.0.0.1</FONT></PRE>
<P>you should see output like this:
<BR>
<PRE>
<FONT COLOR="#000080">PING localhost: 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0. ttl=255 time=1 ms
64 bytes from 127.0.0.1: icmp_seq=1. ttl=255 time=1 ms
64 bytes from 127.0.0.1: icmp_seq=2. ttl=255 time=1 ms
64 bytes from 127.0.0.1: icmp_seq=3. ttl=255 time=1 ms
64 bytes from 127.0.0.1: icmp_seq=4. ttl=255 time=1 ms
64 bytes from 127.0.0.1: icmp_seq=5. ttl=255 time=1 ms
64 bytes from 127.0.0.1: icmp_seq=6. ttl=255 time=1 ms
64 bytes from 127.0.0.1: icmp_seq=7. ttl=255 time=1 ms
^C
--- localhost PING Statistics ---
7 packets transmitted, 7 packets received, 0% packet loss
round-trip (ms) min/avg/max = 1/1/1</FONT></PRE>
<P>The ping command's progress was interrupted by the user issuing a Ctrl-C after seven transmissions. You can let as many transmissions as you want go by. If you get a "no replies" from the ping command, then the address 127.0.0.1 or the name localhost wasn't recognized and you should check the configuration files and route entry again.
<BR>
<P>If the configuration files look correct and the route command was accepted properly, but the ping command still doesn't produce the proper results, then you have a serious problem. In some cases, the network kernel is not properly configured and the entire process must be conducted again. Sometimes a mismatch in versions of kernel drivers and network utilities can cause hang-ups with the ping routine, as well.
<BR>
<BR>
<A NAME="E69E191"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Setting Up an Ethernet Interface</B></FONT></CENTER></H4>
<BR>
<P>Now that the loopback driver is installed and operational, you can do the same configuration process with the Ethernet driver (or whatever driver you are using). The process is exactly the same: use ifconfig to tell the kernel about the interface, and then add the routes to the remote machines on the network. If the network is attached, you can then test the connections with ping.
<BR>
<P>To begin, set up the Ethernet interface using ifconfig. To make the interface active, use the ifconfig command with the Ethernet device name and your local IP address. For example, use the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">ifconfig eth0 147.123.20.1</FONT></PRE>
<P>to set up the local machine with the IP Address 147.123.20.1. The interface is to the Ethernet device /dev/eth0. You don't have to specify the network mask with the ifconfig command, because it will deduce the proper value from the IP address entered. If you want to explicitly provide the network mask value, append it to the command line with the keyword netmask:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">ifconfig eth0 147.123.20.1 netmask 255.255.255.0</FONT></PRE>
<P>This command explicitly sets the network mask to 255.255.255.0. You can then check the interface with the ifconfig command using the interface name:
<BR>
<PRE>
<FONT COLOR="#000080">$ ifconfig eth0
eth0 Link encap 10Mps: Ethernet Hwaddr
inet addr 147.123.20.1 Bcast 147.123.1.255 Mask 255.255.255.0
UP BROADCAST RUNNING MTU 1500 Metric 1
RX packets:0 errors:0 dropped:0 overruns:0
TX packets:0 errors:0 dropped:0 overruns:0</FONT></PRE>
<P>You may have noticed in the output from the command that the broadcast address was set based on the local machine's IP address. This is used by TCP/IP to access all machines on the local area network at once. The Message Transfer Unit (MTU) size is usually set to the maximum value of 1500 (for Ethernet networks).
<BR>
<P>Next, you need to add an entry to the kernel routing tables that let the kernel know about the local machine's network address. That lets it send data to other machines on the same network. The IP address that is used with the route command to do this is not your local machine's IP address, but that of the network as a whole without the local identifier. To set the entire local area network at once, the -net option of the route command is used. In the case of the IP addresses shown previously, the command would be:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">route add -net 147.123.20.0</FONT></PRE>
<P>This command adds all the machines on the network identified by the network address 147.123.20 to the kernel's list of accessible machines. If you didn't do it this way, you would have to manually enter the IP address of each machine on the network. An alternative method is to use the /etc/networks file which can contain a list of network names and their IP addresses. If you have an entry in the /etc/networks file for a network called foobar_net, you could add the entire network to the routing table with the command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">route add foobar_net</FONT></PRE>
<P>Once the route has been added to the kernel routing tables, you can try the Ethernet interface out. This step assumes, of course, that you are connected to other machines and that you know the IP address of one of them. If your network isn't installed yet or you are not connected to another machine that is running TCP/IP, you can't try this step now. To ping another machine, you need either its IP address or its local name. Suppose you know the IP address and want to ping the machine 142.12.130.12. The command and output looks like the following:
<BR>
<PRE>
<FONT COLOR="#000080">tpci_sco1-45> ping 142.12.130.12
PING 142.12.130.12: 64 data bytes
64 bytes from 142.12.130.12: icmp_seq=0. time=20. ms
64 bytes from 142.12.130.12: icmp_seq=1. time=10. ms
64 bytes from 142.12.130.12: icmp_seq=2. time=10. ms
64 bytes from 142.12.130.12: icmp_seq=3. time=20. ms
64 bytes from 142.12.130.12: icmp_seq=4. time=10. ms
64 bytes from 142.12.130.12: icmp_seq=5. time=10. ms
64 bytes from 142.12.130.12: icmp_seq=6. time=10. ms
^C
--- 142.12.130.12 PING Statistics ---
7 packets transmitted, 7 packets received, 0% packet loss
round-trip (ms) min/avg/max = 10/12/20</FONT></PRE>
<P>Again, the ping routine was interrupted after seven attempts. You can see the diagnostic messages and summaries as ping sends a request to the remote machine and waits for a reply.
<BR>
<P>If you don't get anything back from the remote machine, verify that the remote is connected and you are using the proper IP address. If all is well there, check the configuration and route commands. If that checks out, try pinging another machine. If that fails, you can resort to the netstat utility, discussed in more detail in <A HREF="lsg32.htm">Chapter 32</A>, "Network Utilities."
<BR>
<BR>
<A NAME="E68E168"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Configuring PLIP</B></FONT></CENTER></H3>
<BR>
<P>The PLIP (parallel port IP) interface is used to connect only two machines through their parallel ports. (<A HREF="lsg29.htm">Chapter 29</A> looked briefly at PLIP.) Configuring PLIP is different from configuring TCP/IP, especially since the interface is not a standard TCP/IP interface and only two machines are involved.
<BR>
<P>Suppose that there is a simple PLIP interface between your local Linux machine called darkstar and a sibling's machine called x-wing. The two are connected by a null-parallel cable (see the previous chapter for wiring specifications). Both machines have only one parallel port used for PLIP. When PLIP is configured as shown in <A HREF="lsg29.htm">Chapter 29</A>, "Configuring Hardware and the Kernel for Networking," the devices are set up as /dev/plip1 on both machines.
<BR>
<P>To configure the PLIP interface between the two machines, use the ifconfig command again, although this uses a special keyword called "pointopoint" (a condensed and confusing form of point-to-point, which describes the network type). The ifconfig command needed for the connection is:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">ifconfig plip1 x-wing pointopoint darkstar</FONT></PRE>
<P>Note that the device is /dev/plip1, the remote machine is x-wing, and your local machine is darkstar. The order of arguments must be exact for the command to work properly.
<BR>
<P>Once the ifconfig command has been issued, you can follow it with an update of the kernel routing table with the route command. The command is:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">route add x-wing gw darkstar</FONT></PRE>
<P>The gw keyword indicates that darkstar is a gateway to the x-wing machine. The next section covers gateways in more detail.
<BR>
<P>The same sort of entries must be made on the other machine to enable two-way communications. In this case, the remote machine would have entries like this:
<BR>
<PRE>
<FONT COLOR="#000080">ifconfig plip1 darkstar pointopoint x-wing
route add darkstar gw x-wing</FONT></PRE>
<P>Once both configurations are completed, you should be able to use the PLIP interface to send data between the two machines.
<BR>
<BR>
<A NAME="E68E169"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Gateways</B></FONT></CENTER></H3>
<BR>
<P>Local area networks are connected by a gateway. The gateway is one machine that acts as the connection between the two networks, routing data between the two based on the IP address of the destination machine. The simplest use of a gateway is to connect to the rest of the world through the Internet. A machine that connects into the Internet can then connect to any other network on the Internet.
<BR>
<P>You have to make some changes to the network configuration files whenever your local machine is going to use a gateway, as well as if your machine is going to act as a gateway. To use the services of another machine as a gateway, you have to tell the routing tables about the gateway and the networks it connects to by using the route command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">route add default gw net_gate</FONT></PRE>
<P>where net_gate is the name of the machine on your local area network that acts as the gateway out. The gateway machine follows the keyword gw in the route command. The use of the word default in the command indicates that the kernel's routing table should assume all networks can be reached through that gateway. (Physically, the default network setting translates to an IP address of 0.0.0.0.)
<BR>
<P>If you want to configure a gateway to another network, the name of that network should be in the /etc/networks file (see earlier in this chapter for details of the /etc/networks file). For example, if you have a gateway machine called gate_serv that leads from your own local area network to a neighboring network called big_corp (and an entry exists in the /etc/networks file for big_corp with their network IP address), you could configure the routing tables on your local machine to use gate_serv to access big_corp machines with this command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">route add big_corp gw gate_serv</FONT></PRE>
<P>An entry should be made on the remote network's routing table to reflect your network's address, otherwise you would only be able to send data and not receive it.
<BR>
<P>If you want to set up your local machine to act as a gateway itself, you need to configure the two network connections that your machine is joining. This usually requires two network boards, PPP connections, or SLIP connections in some combination. Assume your machine is going to act as a simple gateway between two networks called small_net and big_net, and you have two Ethernet cards installed in your machine. You configure both Ethernet interfaces separately with their respective network IP addresses, as you saw in <A HREF="lsg29.htm">Chapter 29</A>, "Configuring Hardware and the Kernel." (For example, your machine many have an IP address on big_net of 163.12.34.36 and have the IP address 147.123.12.1 on small_net.)
<BR>
<P>Add the two IP addresses to your /etc/hosts file to simplify resolution. For the networks and IP addresses mentioned previously, you will have the following two entries in the /etc/hosts file:
<BR>
<PRE>
<FONT COLOR="#000080">163.12.34.36 merlin.big_net.com merlin-iface1
147.123.12.1 merlin.small_net.com merlin-iface</FONT></PRE>
<P>In this case, the fully qualified domain names have been added to the /etc/hosts file (this example assumes the machine has the name merlin on both networks, which is perfectly legal). You can also add shorter forms of the name, as well (such as merlin, merlin.big_net, and so on). Finally, the interface names have been included for convenience (so merlin-iface1 is the first interface on merlin, while merlin-iface2 is the second).
<BR>
<P>You then use the ifconfig commands to set up the connections between the interface and the names used in the /etc/hosts file:
<BR>
<PRE>
<FONT COLOR="#000080">ifconfig eth0 merlin-iface1
ifconfig eth1 merlin-iface2</FONT></PRE>
<P>These commands assume that the Ethernet device /dev/eth0 is for the interface to big_net, and /dev/eth1 is for small_net. Of course, you could have used the IP addresses of the networks instead of the interface name, as you saw earlier in this chapter.
<BR>
<P>Finally, the kernel routing table must be updated to reflect the two network names. The commands for this example are:
<BR>
<PRE>
<FONT COLOR="#000080">route add big_net
route add small_net</FONT></PRE>
<P>When these steps are completed, you must make sure that IP Forwarding has been enabled in the kernel. You can enable IP Forwarding by rebuilding the kernel. Once the kernel supports IP Forwarding, you can use your machine as a gateway between the two networks. Other machines on either network can also use your machine as a gateway between the two networks.
<BR>
<P>Although the examples shown here are for Ethernet connections to two networks, you could have any kind of interface. You could, for example, use an Ethernet card for your local area network, and then use a SLIP or PPP connection to another network (including the Internet).
<BR>
<BR>
<A NAME="E68E170"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Name Service and Name Resolver</B></FONT></CENTER></H3>
<BR>
<P>TCP/IP uses the /etc/hosts file to resolve symbolic names into IP addresses. For example, when you specify the name darkstar for a target machine, TCP/IP will examine the /etc/hosts file for a machine of that name, and then read off the IP address. If the name isn't in the file, you can't send data to it. Suppose you connect to a lot of different machines, though. Your local area network may have dozens of machines on it, and your friend's network may have more. Adding all those entries to the /etc/hosts file can be tiresome and difficult, and maintaining the file as changes occur in the networks can be even more bothersome. To solve this problem, a couple of services were developed.
<BR>
<P>BIND (Berkeley Internet Name Domain service) was developed to help resolve the IP addresses of remote machines. BIND was later developed into DNS (Domain Name Service). Most Linux network systems implement the BIND version, although a few DNS-specific versions of software are appearing. Both BIND and DNS are complex subjects and involve many details that simply are not of interest to most Linux users. In this section, we will look at the necessary basics to get your Linux machine using BIND or DNS, and then leave it at that.
<BR>
<P>Configuring BIND or DNS can be a bothersome process and should only be done if your /etc/hosts file can't handle your requirements. For example, if you only connect to about a dozen machines, maintaining the /etc/hosts file is much easier than configuring BIND. For larger systems, or if you want to run the full Internet services available to your Linux machine, you need to configure BIND properly. Luckily, BIND usually has to be configured only once, and then it can be ignored. (If you do go through the process of configuring BIND, make sure you have backups!)
<BR>
<P>You will need the BIND software, which is usually included in the distribution software of most Linux recent releases. The BIND package includes all the files and executables, as well as a copy of the BOG (BIND Operator's Guide). Without the BIND software you can't configure your Linux system to use BIND or DNS.
<BR>
<BR>
<A NAME="E69E192"></A>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -