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

📄 483-486.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Special Edition Using Linux, Fourth Edition:Configuring a TCP/IP Network</TITLE>

<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>

 -->




<!--ISBN=0789717468//-->

<!--TITLE=Special Edition Using Linux, Fourth Edition//-->

<!--AUTHOR=Jack Tackett//-->

<!--AUTHOR=Jr.//-->

<!--AUTHOR=Steve Burnett//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Que//-->

<!--CHAPTER=24//-->

<!--PAGES=483-486//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch23/481-482.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="486-488.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 24<BR>Configuring a TCP/IP Network

</FONT></H2>

<P><I>by Steve Burnett</I></P>

<DL>

<DT><B><BIG>I</BIG>n this chapter

</B><DT>Understanding the TCP/IP Configuration Files

<DT>Initializing Ethernet Interfaces

<DT>Understanding TCP/IP Routing

<DT>Monitoring a TCP/IP Network with <TT>netstat</TT>

</DL>

<P>Configuring a TCP/IP network is one of the more common tasks you&#146;ll face when administering Linux machines. In the most basic cases, it&#146;s not very complex, but it does require a bit of thought on the design of your network and knowledge of a small number of programs and configuration files.

</P>

<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Understanding the TCP/IP Configuration Files</FONT></H3>

<P>TCP/IP networking in Linux is controlled by a set of configuration files in the <I>/etc</I> directory. These files tell Linux what its IP address, host name, and domain name are and also control the network interfaces. Table 24.1 shows you what each file does; the following sections discuss these files in detail.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 24.1</B> Linux TCP/IP Networking Configuration Files

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="40%" ALIGN="LEFT">File

<TH WIDTH="60%" ALIGN="LEFT">Description

<TR>

<TD COLSPAN="2"><HR>

<TR>

<TD>/etc/hosts

<TD>Maps host names to IP addresses

<TR>

<TD>/etc/networks

<TD>Maps domain names to network addresses

<TR>

<TD VALIGN="TOP">/etc/rc.d/rc3.d/S10network

<TD>Configures and activates your Ethernet interfaces at boot time

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<H4 ALIGN="LEFT"><A NAME="Heading3"></A><FONT COLOR="#000077">The /etc/hosts File</FONT></H4>

<P>Every computer on a TCP/IP network has an IP address, canonical host name, and zero or more host name aliases. The /etc/hosts file is the original method for mapping host names to IP addresses.

</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>All host names, domain names, and IP addresses used in this chapter are fictitious and don&#146;t reflect <TT>any</TT> true network on the Internet.<HR></FONT>

</BLOCKQUOTE>

<P>For illustrative purposes, look at the network that Burwell, Inc. has built. This network consists of the single class B network address assigned to Burwell by InterNIC (the organization that controls Internet addresses); this network has been split into two class C subnetworks. The format for the hosts file is as follows:

</P>

<!-- CODE //-->

<PRE>

# /etc/hosts for linux1.burwell.com

#

# For loopbacking.

127.0.0.1     localhost



# This machine

166.82.1.21     linux1.burwell.com linux1     # the local machine



# Other hosts on our network

166.82.1.20     server.burwell.com server     # the server

166.82.1.22     wk1.burwell.com               # workstation 1

166.82.1.10     netpr1.burwell.com netpr1     # networked printer

166.82.1.1     gateway.burwell.com gateway     # the router

166.82.1.1     gate-if1               # 1st interface on gateway

166.82.2.1     gate-if2               # 2nd interface on gateway

166.82.1.30     linux2.burwell.com linux2     # Laptop via PLIP



# end of hosts file

</PRE>

<!-- END CODE //-->

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>TIP:&nbsp;&nbsp;</B>Notice that the preceding gateway has two host names for the IP address 166.82.1.1. Giving a unique name to each network interface on a machine is a good idea. Doing so makes it easier to see what&#146;s going on when you use the <TT>ifconfig</TT> and <TT>route</TT> commands.<HR></FONT>

</BLOCKQUOTE>

<P>The format of the hosts file consists of one IP address per line beginning in the first column, the canonical host name associated with that address, and then zero or more aliases. The fields are separated by spaces or tabs. Empty lines and text following a # character are treated as comments and are ignored.

</P>

<P>The IP address 127.0.0.1 is known as the <I>local loopback address</I> and is reserved for this purpose. It&#146;s normally assigned the name localhost. If you&#146;re going to use your machine only as a standalone system or use SLIP or PPP to connect to the outside world, you need only the localhost address in your hosts file.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>The function of the /etc/hosts file has been mostly taken over by Domain Name Service (DNS) on machines connected to the Internet or large internal networks. DNS isn&#146;t available during boot or when you&#146;re running in single-user mode, however, so it&#146;s a good idea to place the information for essential machines such as servers and gateways in /etc/hosts.<P>On a network with only a few machines that aren&#146;t connected to the Internet, it&#146;s easier to keep a complete listing of all hosts in /etc/hosts rather than configure and maintain DNS. <HR></FONT>

</BLOCKQUOTE>

</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>TIP:&nbsp;&nbsp;</B>Naming your networks makes it convenient to do things such as static routing that take a host name or network name. You don&#146;t have to remember the subnets by their IP addresses, just their names.<HR></FONT>

</BLOCKQUOTE>

<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">The /etc/networks File</FONT></H4>

<P>Just as hosts have names and IP addresses, networks and subnets can be named. This naming is handled by the /etc/networks file. The IP addresses in the networks file include only the network address portion plus the subnetwork byte. The following is an example file for burwell.com:

</P>

<!-- CODE SNIP //-->

<PRE>

# /etc/networks for burwell.com



localnet     127.0.0.0      # software loopback network

burwell-c1     166.82.1     # Development Group Network, Class C

burwell-c2     166.82.2     # MIS Network, Class C



# end of networks file

</PRE>

<!-- END CODE SNIP //-->

<P>First is the localnet name and IP address, 127.0.0.0. If you aren&#146;t connecting your Linux machine to a TCP/IP network or are using only SLIP or PPP, all you need to put in this file is the localnet name and IP address.

</P>

<P>The next lines identify the two class C subnetworks that Burwell has made from its class B network.</P>

<H3><A NAME="Heading5"></A><FONT COLOR="#000077">Initializing Ethernet Interfaces</FONT></H3>

<P>The <TT>ifconfig</TT> program makes network interfaces such as the software loopback and Ethernet cards known to the Linux kernel, so that Linux can use them. The <TT>ifconfig</TT> program is also used to monitor and change the state of network interfaces. A simple invocation of <TT>ifconfig</TT> is</P>

<!-- CODE SNIP //-->

<PRE>

ifconfig <I>interface address</I>

</PRE>

<!-- END CODE SNIP //-->

<P>which activates the specified network interface and assigns an IP address to it. This is called <I>bringing up an interface.</I> The generalized calling syntax for <TT>ifconfig</TT> is as follows:</P>

<!-- CODE SNIP //-->

<PRE>

ifconfig <I>interface</I> [<I>aftype</I> ] [<I>options</I> ] |  <I>address</I>

</PRE>

<!-- END CODE SNIP //-->

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch23/481-482.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="486-488.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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