⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lsg30.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 5 页
字号:


<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->


























<LINK REL="ToC" HREF="index.htm">







<LINK REL="Index" HREF="htindex.htm">







<LINK REL="Next" HREF="lsg31.htm">



















<A NAME="I0"></A>







<H2>Linux System Administrator's Survival Guide lsg30.htm</H2>







<P ALIGN=LEFT>







































<HR ALIGN=CENTER>







<P>







<UL>







<UL>







<UL>







<LI>







<A HREF="#E68E166" >Getting Ready to Configure TCP/IP</A>







<LI>







<A HREF="#E68E167" >Setting Up the Basics</A>







<UL>







<LI>







<A HREF="#E69E190" >Setting Up the Loopback Interface</A>







<LI>







<A HREF="#E69E191" >Setting Up an Ethernet Interface</A></UL>







<LI>







<A HREF="#E68E168" >Configuring PLIP</A>







<LI>







<A HREF="#E68E169" >Gateways</A>







<LI>







<A HREF="#E68E170" >Name Service and Name Resolver</A>







<UL>







<LI>







<A HREF="#E69E192" >The named Daemon and Name Servers</A>







<LI>







<A HREF="#E69E193" >The hosts.conf File and Resolver Variables</A>







<LI>







<A HREF="#E69E194" >Name Server Lookups: The resolv.conf File</A>







<LI>







<A HREF="#E69E195" >The /etc/named.boot File</A>







<LI>







<A HREF="#E69E196" >Resource Records</A>







<LI>







<A HREF="#E69E197" >Resource Record Files</A>







<LI>







<A HREF="#E69E198" >IN-ADDR-ARPA</A></UL>







<LI>







<A HREF="#E68E171" >Summary</A></UL></UL></UL>







<HR ALIGN=CENTER>







<A NAME="E66E34"></A>







<H1 ALIGN=CENTER>







<CENTER>







<FONT SIZE=6 COLOR="#FF0000"><B>Chapter 30</B></FONT></CENTER></H1>







<BR>







<A NAME="E67E37"></A>







<H2 ALIGN=CENTER>







<CENTER>







<FONT SIZE=6 COLOR="#FF0000"><B>Configuring TCP/IP</B></FONT></CENTER></H2>







<BR>







<P>Despite what you may have heard, configuring TCP/IP is an easy process requiring usually only a little preparation work and a couple of commands to install the network IP addresses and names. This chapter looks at the process, setting up the support files, TCP/IP route files, and a PLIP interface. It also looks at how to set up your system to act as a gateway between networks, or use another machine as a gateway. Most of the steps you have to go through in this chapter are required only when you initially set up the system or when you make a network configuration change.







<BR>







<P>The last section of this chapter deals with name service, which you may need to install and configure if your machine is connected to a lot of other networks and machines. The name service and name resolver that goes with it are optional and are not necessary for your configuration unless you feel they will add to the usefulness of the network. You'll find a short discussion about name service in the preamble to the configuration steps.







<BR>







<BR>







<A NAME="E68E166"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Getting Ready to Configure TCP/IP</B></FONT></CENTER></H3>







<BR>







<P>You must conduct a few housekeeping steps before you can configure your system's TCP/IP files. These are easy to accomplish and need only be done once. Some of the steps may have been done for you automatically when the system was installed, and others have been taken care of in earlier chapters of this book.







<BR>







<P>Some versions of Linux networking reply on the /proc filesystem (any Linux kernel that uses the Net-2 or later releases usually has this dependency). Most Linux kernels that support networking automatically create the /proc filesystem when the system is installed, so you shouldn't have to do anything more than make sure it is properly mounted by the kernel. The /proc filesystem is essentially a quick interface point for the kernel to obtain network information easily, as well as maintain important tables (which are usually kept in the subdirectory /proc/net, created by the network installation routine).







<BR>







<P>You should make sure the /proc filesystem is mounted automatically on your Linux system by examining the startup code for the kernel. To force the /proc filesystem to be mounted automatically, modify the /etc/fstab file and add the mount command there. (The /etc/fstab file was covered in more detail in <A HREF="lsg18.htm">Chapter 18</A>, &quot;Filesystems and Disks.&quot;) Check the entries in /etc/fstab for a line like this:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">none /proc proc defaults</FONT></PRE>







<P>If no such line exists, you should add it to the contents of the /etc/fstab file using an ASCII editor.







<BR>







<P>If the /proc filesystem is not created by your Linux kernel you will have to rebuild the kernel and select the /proc option. Change to the source directory (such as /usr/src/Linux) and run the configuration routine with the following command:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">make config</FONT></PRE>







<P>When you are asked whether you want the procfs (the /proc filesystem) support, answer y. If you do not get asked about the /proc filesystem support, and the /proc directory is not created on your filesystem, then you need to upgrade your kernel in order to support networking.







<BR>







<P>Another step you must take before configuring TCP/IP is to set the hostname. We examined this process in <A HREF="lsg17.htm">Chapter 17</A>, &quot;System Names and Access Permissions.&quot; To set the hostname, use the command







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">hostname name</FONT></PRE>







<P>where name is the system name you want for your local machine. If you have a full domain name assigned to your network and your machine, you can use that name for your system. For example, if your Linux machine is attached to the domain star.com and your machine's name is dark, you can set the full domain name using the command:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">hostname dark.star.com</FONT></PRE>







<P>If you don't have a fully qualified domain name (one approach by the Internet Network Information Center), you can make up your own domain name as long as you are not connected to the Internet in any way. Such a domain name will not have any meaning outside your local area network. Alternatively, you do not have to assign a domain at all for your machine, but simply enter the short name:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">hostname dark</FONT></PRE>







<P>When you set the local machine's name with the hostname command, an entry is usually made in the /etc/hosts file. You should verify that your machine name appears in that file.







<BR>







<P>You should also know the IP address assigned to your machine. We looked at IP addresses early in this section in <A HREF="lsg28.htm">Chapter 28</A>, &quot;TCP/IP and Networks.&quot; You should have a unique IP address ready for your local machine.







<BR>







<P>One file that may be handy for you if you plan to direct information across many networks is the /etc/networks file. This file contains a list of network names and their IP addresses. Applications on your machine can use this file to determine target networks based on their name. The file consists of two columns, one for the symbolic name of the remote network and the second for the IP address of the network (minus any host identifiers).







<BR>







<P>Most /etc/networks files have at least one entry for the loopback driver. The extract from an /etc/networks file looks like this:







<BR>







<PRE>







<FONT COLOR="#000080">loopback 127.0.0.0







merlin-net 147.154.12.0







BNR 47.0.0.0</FONT></PRE>







<P>This file has two networks entered in it with their network IP addresses. The entries are used primarily when the network boots, but can be used for other purposes including establishing routing.







<BR>







<BR>







<A NAME="E68E167"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Setting Up the Basics</B></FONT></CENTER></H3>







<BR>







<P>The first step in setting up TCP/IP on your Linux machine is to make the network interface accessible. This is done with the ifconfig command. When run, ifconfig essentially makes the network layer of the kernel work with the network interface by giving it an IP address, and then issuing the command to make the interface active. When the interface is active, the kernel can send and receive data through the interface.







<BR>







<P>You need to set up several interfaces for your machine, including the loopback driver and the Ethernet interface (or whatever other network interface you are using). The ifconfig command is used for each interface in turn. The general format of the ifconfig command is







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">ifconfig interface_type IP_Address</FONT></PRE>







<P>where interface_type is the interface's device driver name, such as lo for loopback, ppp for PPP, and eth for Ethernet. (See <A HREF="lsg29.htm">Chapter 29</A>, &quot;Configuring Hardware and the Kernel,&quot; for interface names.) The IP_Address is the IP address used by that interface.







<BR>







<P>Once the ifconfig command has been run and the interface is active, you must use the route command to add or remove routes in the kernel's routing table. This is needed to allow the local machine to find other machines. The general format of the route command is:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">route add|del IP_Address</FONT></PRE>







<P>where either add or del is specified to add or remove the route from the kernel's routing table, and IP_Address is the remote route being affected.







<BR>







<P>You can display the current contents of the kernel's routing table at any time by entering the command route all by itself on the command line. For example, if your system is set up only with the loopback driver, you will see an output like this:







<BR>







<PRE>







<FONT COLOR="#000080">$ route







Kernel Routing Table







Destination Gateway Genmask Flags MSS Window Use Iface







loopback * 255.0.0.0 U 1936 0 16 lo</FONT></PRE>







<P>The important columns are the destination name, which shows the name of the configured target (in this case only loopback), the mask to be used (Genmask), and the interface (Iface, in this case /dev/lo). You can force route to display the IP addresses instead of symbolic names by using the -n option:







<BR>







<PRE>







<FONT COLOR="#000080">$ route -n







Kernel Routing Table







Destination Gateway Genmask Flags MSS Window Use Iface







127.0.0.1 * 255.0.0.0 U 1936 0 16 lo</FONT></PRE>







<P>A typical Linux network configuration will include a couple of interfaces. The loopback interface should exist on every machine. The network interface, whether Ethernet or other device, is also present (unless you only want a loopback driver). This chapter assumes you want to set up your system for a loopback and an Ethernet card, both of which need to be done separately.







<BR>







<BR>







<A NAME="E69E190"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>Setting Up the Loopback Interface</B></FONT></CENTER></H4>







<BR>







<P>The loopback interface should exist on every networked machine (as well as machines that are stand-alone, for that matter). The loopback interface always has the IP address 127.0.0.1, so the /etc/hosts file should have an entry for this interface. The loopback driver may have been created by the kernel during software installation, so check the /etc/hosts file for a line similar to this:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">127.0.0.1 localhost</FONT></PRE>







<P>If the line exists, the loopback driver is in place. Make sure the line doesn't have a pound sign ahead of it to comment it out. If the line doesn't exist in the /etc/hosts file, add it using an ASCII editor.







<BR>







<P>If the loopback interface was not in the /etc/hosts file, you will need to create the interface as well using the ifconfig command. Issue the following command to complete the addition of the loopback driver:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">ifconfig lo 127.0.0.1</FONT></PRE>







<P>If you are not sure about the configuration, you can use the ifconfig command to display all the information it knows about the loopback driver. Use the following command:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">ifconfig lo</FONT></PRE>







<P>You should see several lines of information like the following:







<BR>







<PRE>







<FONT COLOR="#000080">merlin:~# ifconfig lo







lo Link encap:Local Loopback 







 inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -