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

📄 659-661.html

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

<HEAD>

<TITLE>Linux Unleashed, Third Edition:Networking</TITLE>

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

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

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

<!--IMPRINT=Sams//-->

<!--CHAPTER=37//-->

<!--PAGES=659-661//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="656-658.html">Previous</A></TD>

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

<TD><A HREF="662-663.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<P><FONT SIZE="+1"><B>/etc/services</B></FONT></P>

<P>The <TT>/etc/services</TT> file identifies the existing network services. This file is maintained by software as it is installed or configured.</P>

<P>This file consists of the service name, a port number, and the protocol type. The port number and protocol type are separated by a slash, following the conventions mentioned in previous chapters. Any optional service alias names follow. Here&#146;s a short extract from a sample <TT>/etc/services</TT> file:</P>

<!-- CODE //-->

<PRE>

# network services

echo     7/tcp

echo     7/udp

discard  9/tcp   sink null

discard  9/udp   sink null

ftp      21/tcp

telnet   23/tcp

smtp     25/tcp   mail mailx

tftp     69/udp

# specific services

login    513/tcp

who      513/udp   whod

</PRE>

<!-- END CODE //-->

<P>You shouldn&#146;t change this file at all, but you do need to know what it is and why it is there to help you understand TCP/IP a little better.

</P>

<P><FONT SIZE="+1"><B>/etc/hostname or /etc/HOSTNAME</B></FONT></P>

<P>The file <TT>/etc/hostname</TT> or <TT>/etc/HOSTNAME</TT> is used to store the name of the system you are on. (Slackware Linux uses the uppercase version of the name.) This file should have your local machine&#146;s name in it:</P>

<!-- CODE SNIP //-->

<PRE>

merlin.tpci

</PRE>

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

<P>That&#146;s all it needs. The hostname is used by most protocols on the system and many applications, so it is important for proper system operation. The hostname can be changed by editing the system file and rebooting the machine, although many distributions provide a utility program to ensure that this process is performed correctly.

</P>

<P>Linux systems have a utility called <TT>hostname</TT>, which displays the current setting of the system name, as well as the <TT>uname</TT> program, which can give the node name with the command <TT>uname -n</TT>. When issued, the <TT>hostname</TT> and <TT>uname</TT> commands echo the local machine name, as the following sample session shows:</P>

<!-- CODE SNIP //-->

<PRE>

&#36; hostname

merlin.tpci.com

&#36; uname -n

merlin

</PRE>

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

<P>Some Linux versions of <TT>hostname</TT> show only the name without the domain name attached. All the configuration files necessary for TCP/IP to function have now been set properly, so you should be able to reboot the machine and see what happens.</P>

<H3><A NAME="Heading8"></A><FONT COLOR="#000077">Testing and Troubleshooting</FONT></H3>

<P>To try out TCP/IP, reboot your machine and carefully watch the messages displayed on-screen. If you see any error messages, they may help guide you to the faulty file or process. Otherwise, you will see the TCP/IP daemons load one after another.

</P>

<H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">The netstat Command</FONT></H4>

<P>Probably the best approach to checking on TCP/IP is to use the <TT>netstat</TT> command, which gives you many different summaries of all network connections and their status. The <TT>netstat</TT> program provides comprehensive information. It&#146;s the program most commonly used by administrators to quickly diagnose a problem with TCP/IP.</P>

<P>There are many more <TT>netstat</TT> options than the ones mentioned in the next sections. For more information on <TT>netstat</TT>, start with the man page on the Linux system and then check a good UNIX networking book.</P>

<P><FONT SIZE="+1"><B>Communications End Points</B></FONT></P>

<P>The <TT>netstat</TT> command with no options shows information on all active communications end points (where data is actually being transferred or communications are established). To display all end points (active and passive), <TT>netstat</TT> uses the <TT>-a</TT> option.</P>

<P>The <TT>netstat</TT> output is formatted in columns that show the protocol (<TT>Proto</TT>), the amount of data in the receive and send queues (<TT>Recv-Q</TT> and <TT>Send-Q</TT>), the local and remote addresses, and the current state of the connection. Here&#146;s a truncated sample output:</P>

<!-- CODE //-->

<PRE>

merlin&gt; netstat -a

Active Internet connections (including servers)

Proto Recv-Q Send-Q  Local Address       Foreign Address     (state)

ip       0     0     *.*                 *.*

tcp      0  2124     tpci.login          oscar.1034         ESTABL.

tcp      0     0     tpci.1034           prudie.login        ESTABL.

tcp  11212     0     tpci.1035           treijs.1036         ESTABL.

tcp      0     0     tpci.1021           reboc.1024

;TIME_WAIT

tcp      0     0     *.1028              *.*                 LISTEN

tcp      0     0     *.*                 *.*                 CLOSED

udp      0     0     localhost.1036      localhost.syslog

udp      0     0     *.1034              *.*

udp      0     0     *.*                 *.*

udp      0     0     *.*                 *.*

</PRE>

<!-- END CODE //-->

<P>This excerpt has three active TCP connections, as identified by the state <TT>ESTABL.</TT>, with one that has data being sent (as shown in the <TT>Send-Q</TT> column). An asterisk means that no end point is yet associated with that address.</P>

<P><FONT SIZE="+1"><B>Network Interface Statistics</B></FONT></P>

<P>The behavior of the network interface (such as the network interface card) can be shown with the <TT>netstat -i</TT> option. This quickly shows administrators whether there are major problems with the network connection.</P>

<P>The <TT>netstat -i</TT> command displays the name of the interface, the maximum number of characters a packet can contain (<TT>MTU</TT>), the number of input packets received error free (<TT>RX-OK</TT>), number of received packets with errors (<TT>RX-ERR</TT>), number of received packets dropped (RX-DRP), and the number of packets that could not be received (RX-OVR). This is followed by the same statistics for sent packets. The following is a sample output from a <TT>netstat -i</TT> command:</P>

<!-- CODE SNIP //-->

<PRE>

merlin&gt; netstat -i

Kernel Interface table

Iface   MTU Met  RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR

Flags

lo     2000   0      0      0      0      0    12      0      0      0

BLRU

eth0   1500   0    218      0      0      0   144      0      0      0

BRU

</PRE>

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

<P><FONT SIZE="+1"><B>Routing Table Information</B></FONT></P>

<P>Routing tables are continually updated to reflect connections to other machines. To obtain information about the routing tables (if there are any on your system), the <TT>netstat -r</TT> option is used.</P>

<P>Columns show the destination machine, the address of the gateway to be used, a flag to show whether the route is active (<TT>U</TT>) and whether it leads to a gateway (<TT>G</TT>) or a machine (<TT>H</TT> for host), a reference counter (<TT>Refs</TT>) that specifies how many active connections may use that route simultaneously, the number of packets that have been sent over the route (<TT>Use</TT>), and the interface name.</P>

<!-- CODE SNIP //-->

<PRE>

merlin&gt; netstat -r

Kernel routing table

Destination     Gateway      Genmask       Flags Metric Ref Use

Iface

localnet        *            255.255.0.0   U      0     0   262 eth0

loopback        *            255.0.0.0     U      0     0    12 lo

default         *            0.0.0.0       U      0     0     0 eth0

</PRE>

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

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="656-658.html">Previous</A></TD>

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

<TD><A HREF="662-663.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 + -