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

📄 ch43.htm

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


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:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">$ hostname



merlin.tpci.com



$ uname -n



merlin



</FONT></PRE>



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



<H3 ALIGN="CENTER"><A NAME="Heading9<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.



<H4 ALIGN="CENTER"><A NAME="Heading10<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'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, then check a good UNIX networking book. Communications End Points 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's a



truncated sample output:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">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  *.*                    *.*



</FONT></PRE>



<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. Network Interface Statistics



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 (<TT>RX-DRP</TT>), and the number of packets that



could not be received (<TT>RX-OVR</TT>). This is followed by the same statistics



for sent packets. The following is a sample output from a <TT>netstat -i</TT> command:<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">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



</FONT></PRE>



<P>Routing Table Information 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.<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">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



</FONT></PRE>



<H4 ALIGN="CENTER"><A NAME="Heading11<FONT COLOR="#000077">ping</FONT></H4>



<P>The <TT>ping</TT> (Packet Internet Groper) program is used to query another system



and ensure that a connection is active. The <TT>ping</TT> program operates by sending



a request to the destination machine for a reply. If the destination machine's IP



software receives the request, it issues a reply immediately.</P>



<P>The sending machine will continue to send requests until the <TT>ping</TT> program



is terminated with a break sequence. After termination, <TT>ping</TT> displays a



set of statistics. A sample <TT>ping</TT> session is shown as follows:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">prudie&gt; ping merlin



PING merlin: 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



-- merlin PING Statistics --



7 packets transmitted, 7 packets received, 0% packet loss



round-trip (ms) min/avg/max = 10/12/20



</FONT></PRE>



<P>If <TT>ping</TT> was unable to reach the remote machine, it will display error



messages. You can also <TT>ping</TT> the <TT>localhost</TT>, which will show if there



is an error in the loopback driver configuration files.</P>



<P>The <TT>ping</TT> program is useful because it provides four important pieces



of information: whether the TCP/IP software is functioning correctly, whether a local



network device can be addressed (validating its address), whether a remote machine



can be accessed (again validating the address and testing the routing), and verifying



the software on the remote machine.



<H3 ALIGN="CENTER"><A NAME="Heading12<FONT COLOR="#000077">SLIP Connections</FONT></H3>



<P>SLIP connections are configured in much the same manner as the TCP/IP connections



described earlier. SLIP is one method of using a modem (or other serial port device)



to communicate instead of a network card. SLIP is especially useful for connecting



to the Internet through service providers such as UUNET Technologies or NetCom.</P>



<P>For SLIP connections, two Linux programs are involved: <TT>dip</TT> and <TT>slattach</TT>.



Both programs can be used to initiate the SLIP connection. You cannot dial into a



SLIP line with a standard communications program because of the special system calls



SLIP uses.</P>



<P><TT>dip</TT> and <TT>slattach</TT> have different purposes. The <TT>slattach</TT>



program, which simply connects to the serial device, is used when there is a permanent



connection to the SLIP server (no modem or setup handshaking is required). The <TT>dip</TT>



program handles the initiation of the connection, the login, and connection handshaking.



If you use a modem to connect to a SLIP server, you should use <TT>dip</TT>. The



<TT>dip</TT> program can also be used to configure your own system as a SLIP server,



allowing others to call in to it.</P>



<P>SLIP is a fairly simple network protocol because only two devices are involved:



yours and the server's. When the connection is established, SLIP sends an IP address



that will be used for that connection. Some systems use the same IP address (static),



while others will have a different IP address each time a connection is made (dynamic).



The configuration is slightly different for each type.



<H4 ALIGN="CENTER"><A NAME="Heading13<FONT COLOR="#000077">Static IP Addresses</FONT></H4>



<P>A static connection requires that the IP addresses be included in the same files



as for an Ethernet network connection. Your machine's IP address should be in the



files <TT>/etc/hosts</TT>, <TT>rc.inet1</TT>, <TT>rc.inet2</TT>, <TT>host.conf</TT>,



and <TT>resolv.conf</TT>. The gateway address should be the IP address of the SLIP



server. The SLIP device names used are <TT>sl0</TT>, <TT>sl1</TT>, <TT>sl2</TT>,



and so on.</P>



<P>The only difference in configuration between Ethernet and SLIP is in the <TT>rc.inet1</TT>



file, where you only want to execute the <TT>ifconfig</TT> and <TT>route</TT> programs



for the loopback driver. If you use <TT>dip</TT> to establish the SLIP connection,



it will probably take care of this for you, although some problems are occasionally



encountered. In these cases, manual changes to the file should be made to allow <TT>ifconfig</TT>



and <TT>route</TT> to be executed manually from the shell, or from inside a shell



script.</P>



<P>The <TT>ifconfig</TT> routine might need to be modified with the argument <TT>pointopoint</TT>.



SLIP is a variation of Point-to-Point Protocol (PPP). The line would look like this:<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">ifconfig sl0 147.123.12.2 pointopoint 121.12.234.2



</FONT></PRE>



<P>The first IP address (<TT>147.123.12.2</TT>) is your machine's IP address, and



the numbers following the argument (<TT>121.12.234.2</TT>) are the IP address of



the SLIP server.</P>



<P>If you have a dedicated connection to the SLIP server and you want to use <TT>slattach</TT>,



the <TT>rc.inet1</TT> file is modified to have the following lines in it:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">IPADDR=&quot;123.12.3.1&quot;          # Your machine's IP address



REMADDR=&quot;142.12.3.12&quot;  # The SLIP server IP address







slattach -p cslip -s 19200 /dev/ttyS0     # set baud and port as needed



/etc/ifconfig sl0 $IPADDR pointopoint $REMADDR up



/etc/route add default gw $REMADDR



</FONT></PRE>



<P>These lines, or very similar lines, will appear in most <TT>rc.inet1</TT> or <TT>rc.inet</TT>



files, usually commented out. Amend the information to show the proper IP addresses,



ports, and baud rates. The <TT>cslip</TT> argument for <TT>slattach</TT> tells the



program to use <TT>slip</TT> with header compression. If this causes problems, change



it to <TT>slip</TT>.



<H4 ALIGN="CENTER"><A NAME="Heading14<FONT COLOR="#000077">Dynamic IP Addresses</FONT></H4>



<P>If the SLIP server you are connecting to allocates IP addresses dynamically, you



can't put an IP address in the configuration files, because it will change each time.



Most SLIP servers display a message with the IP address when you connect, and <TT>dip</TT>



can capture these numbers and use them to alter the system parameters appropriately.



<H4 ALIGN="CENTER"><A NAME="Heading15<FONT COLOR="#000077">dip</FONT></H4>



<P>The <TT>dip</TT> program greatly simplifies the connection to a SLIP server. To



use it, you need a chat script that contains all the commands used to establish communications



with the SLIP server during login. The chat script usually includes your login and



password too, automating the login process.</P>



<P>A sample <TT>dip</TT> chat script is included in the man pages for <TT>dip</TT>,



so you should display the man page and read the contents, then save the file (by



redirection or copying the man page source) and edit the script. Here's a sample



chat script that you can enter by hand if necessary, making sure you put in your



own data:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF"># Connection script for SLIP



# Fetch the IP address of our target host.



main:



  # Set the desired serial port and speed.



  port /dev/cua0

⌨️ 快捷键说明

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