📄 672-674.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:SLIP and PPP</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=38//-->
<!--PAGES=672-674//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="669-672.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="674-676.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading8"></A><FONT COLOR="#000077">Dialing Out with chat</FONT></H4>
<P>PPP requires you to establish a modem connection to the remote machine before it can take over and handle the communications. There are several utilities available to do this, although the most commonly used is <TT>chat</TT>. The <TT>chat</TT> program is popular because it uses a scripting style similar to that used by UUCP.</P>
<P>To use <TT>chat</TT>, assemble a command line that looks almost the same as a UUCP <TT>/etc/Systems</TT> file entry. For example, to call a remote machine with a Hayes-compatible modem (using the AT command set) at the number 555-1234, use the following command. It is formatted as a <TT>chat</TT> script, UUCP style:</P>
<!-- CODE SNIP //-->
<PRE>
chat “” ATZ OK ATDT5551234 CONNECT “” login: ppp word: secret1
</PRE>
<!-- END CODE SNIP //-->
<P>All the entries are in UUCP’s send-expect format, with whatever you send to the specified remote located after what you receive from it. The <TT>chat</TT> script always starts with an <TT>expect</TT> string, which must be set to empty because the modem won’t respond without any signal to it. After the empty string, first send the <TT>ATZ</TT> (reset) command and wait for an <TT>OK</TT> back from the modem, then send the <TT>dial</TT> command. After a <TT>CONNECT</TT> message is received back from the modem, the login script for the remote machine is executed and goes like this: Send a blank character first, then the <TT>login:</TT> (login) prompt appears, next, send the login name <TT>ppp</TT>, wait for the <TT>word:</TT> (password) prompt, and finally, send the password (substituting your login name and password, of course). After the login is complete, <TT>chat</TT> terminates but leaves the line open.</P>
<P>If the other end of the connection doesn’t answer with a <TT>login</TT> script as soon as their modem answers, you may have to force a <TT>BREAK</TT> command down the line to jog the remote end. This is done with the following command:</P>
<!-- CODE SNIP //-->
<PRE>
chat -v “” ATZ OK ATDT5551234 CONNECT “” ogin:-BREAK-ogin: ppp word:
secret1
</PRE>
<!-- END CODE SNIP //-->
<P>There’s a security problem with this type of <TT>chat</TT> entry because any user doing a <TT>ps -ef</TT> command can see the entire command line (with its passwords). If you are the only user of your system this isn’t a concern, but to save yourself any problems, you can embed the script portion of the command in a file and read the file in to <TT>chat</TT>. This causes the script to not appear on a <TT>ps</TT> output. To call a file for use with <TT>chat</TT>, use the <TT>-f</TT> option:</P>
<!-- CODE SNIP //-->
<PRE>
chat -f chat_file
</PRE>
<!-- END CODE SNIP //-->
<P>The <TT>chat_file</TT> will contain the following line:</P>
<!-- CODE SNIP //-->
<PRE>
“” ATZ OK ATDT5551234 CONNECT “” login: ppp word: secret1
</PRE>
<!-- END CODE SNIP //-->
<P>The <TT>chat</TT> script can help you detect common error conditions such as a busy line or no connection established. The messages from your modem (the standard Hayes command set uses the messages <TT>BUSY</TT> and <TT>NO CARRIER</TT>, respectively) are embedded in the <TT>chat</TT> script with the <TT>ABORT</TT> option, which allows you to exit from the <TT>chat</TT> script gracefully if one of these error conditions occurs. To handle these abort conditions, embed the <TT>chat</TT> keyword <TT>ABORT</TT> followed by the message that should trigger an abort, prior to your normal <TT>chat</TT> script. For example, to modify the <TT>chat</TT> script above to abort on a <TT>BUSY</TT> or <TT>NO CARRIER</TT> message from the modem, the script looks like this:</P>
<!-- CODE SNIP //-->
<PRE>
ABORT BUSY ABORT ’NO CARRIER’ “” ATZ OK ATDT5551234 CONNECT “” login: ppp
word: secret1
</PRE>
<!-- END CODE SNIP //-->
<P>We needed two <TT>ABORT</TT> commands because each takes only one argument. The rest of the <TT>chat</TT> script is as usual. Note the need to put quotation marks around the <TT>NO CARRIER</TT> message because otherwise the space in the middle will confuse the script.</P>
<H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">Running pppd</FONT></H4>
<P>If you have a PPP connection already established and your machine is logged in to a remote using the PPP account, you can start the <TT>pppd</TT> daemon to control the PPP session. If your machine is using the device <TT>/dev/cua1</TT> (the Linux designation for the first serial port with modem control) for its PPP connection at 38400 baud, start the <TT>pppd</TT> daemon with the following command:</P>
<!-- CODE SNIP //-->
<PRE>
pppd /dev/cua1 38400 crtscts defaultroute
</PRE>
<!-- END CODE SNIP //-->
<P>This command tells the kernel to switch the interface on <TT>/dev/cua1</TT> to PPP and establish an IP link to the remote machine. The <TT>crtscts</TT> option, which is usually used on any PPP connection above 9600 baud, turns on handshaking.</P>
<P>The local system uses an IP address that is taken from the local hostname unless one is specified on the <TT>pppd</TT> command line (which you will seldom need to do because the local host IP address should be correct for the PPP line). If you want to force the local or remote IP addresses to be something other than the machine’s default values, you can add the addresses with an option to <TT>pppd</TT>. The general format is to specify the local IP address, a colon, then the remote IP address:</P>
<!-- CODE SNIP //-->
<PRE>
147.23.43.1:36.23.1.34
</PRE>
<!-- END CODE SNIP //-->
<P>When added to the <TT>pppd</TT> command line, the preceding option sets the local IP address as <TT>147.23.43.1</TT> and the remote IP address to <TT>36.23.1.34</TT>, regardless of what the local values are. If you want to modify only one IP address, leave the other portion blank:</P>
<!-- CODE SNIP //-->
<PRE>
147.23.43.1:
</PRE>
<!-- END CODE SNIP //-->
<P>This command sets the local IP address and accepts the remote IP address as whatever the machine sends.
</P>
<P>You can use <TT>chat</TT> to establish the connection in the first place, which allows you to embed the <TT>chat</TT> command as part of the <TT>pppd</TT> command. This is best done when reading the contents of the chat script from a file (using the <TT>-f</TT> option). For example, you can issue the <TT>pppd</TT> command:</P>
<!-- CODE SNIP //-->
<PRE>
pppd connect “chat -f chat_file” /dev/cua1 38400 -detach crtscts modem
defaultroute
</PRE>
<!-- END CODE SNIP //-->
<P><TT>chat_file</TT> holds the expect-send sequences looked at earlier. You will notice a few modifications to the <TT>pppd</TT> command other than the addition of the <TT>chat</TT> command in quotation marks. The <TT>-detach</TT> command tells <TT>pppd</TT> not to detach from the console and move to background. The <TT>modem</TT> keyword tells <TT>pppd</TT> to monitor the modem port (in case the line drops prematurely) and hang up the line when the call is finished.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="669-672.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="674-676.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 + -