📄 ppp.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>使用内核级PPP</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD 使用手册" href="index.html" /><link rel="UP" title="PPP 和 SLIP" href="ppp-and-slip.html" /><link rel="PREVIOUS" title="使用用户级PPP" href="userppp.html" /><link rel="NEXT" title="Troubleshooting PPP Connections" href="ppp-troubleshoot.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD 使用手册</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="userppp.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 18. PPP 和 SLIP</td><td width="10%" align="right" valign="bottom"><a href="ppp-troubleshoot.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="PPP" name="PPP">18.3. 使用内核级PPP</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Parts originally contributed by</span>Gennady B. Sorokopud and Robert Huff.</i> <div class="SECT2"><h2 class="SECT2"><a id="AEN24161" name="AEN24161">18.3.1. 设立内核级PPP</a></h2><p>在开始设置内核级PPP时, 需要确信<tt class="COMMAND">pppd</tt>已经被定位在<ttclass="FILENAME">/usr/sbin</tt> 中 且存在<tt class="FILENAME">/etc/ppp</tt>目录 .</p><p><tt class="COMMAND">pppd</tt>能在两种模式下工作:</p><ol type="1"><li><p>作为一个``客户'' -- 你要通过PPP串行线或modem线把你的机器连接到互联网上 .</p></li><li><p>作为``服务器'' --计算机已经位于网络上,且被用于通过PPP与其它计算机连接.</p></li></ol><p>两种情况你都需要设立一个选项文件, (<tt class="FILENAME">/etc/ppp/options</tt> 或者是<tt class="FILENAME">~/.ppprc</tt> 如果你的计算机有多个用户使用PPP).</p><p>你还需要一些modem/serial软件(<ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/comms/kermit/pkg-descr"><ttclass="FILENAME">comms/kermit</tt></a>就很适合), 使你能够拨号并与远程主机建立连接.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN24187" name="AEN24187">18.3.2. 使用<ttclass="COMMAND">pppd</tt>作为客户端</a></h2><i class="AUTHORGROUP"><span class="CONTRIB">Based on information provided by</span> TrevRoydhouse.</i> <p>下面这个 <ttclass="FILENAME">/etc/ppp/options</tt>选项文件能够被用来与CISCO终端服务器的PPP线连接.</p><pre class="PROGRAMLISTING">crtscts # enable hardware flow controlmodem # modem control linenoipdefault # remote PPP server must supply your IP address # if the remote host does not send your IP during IPCP # negotiation, remove this optionpassive # wait for LCP packetsdomain ppp.foo.com # put your domain name here:<remote_ip> # put the IP of remote PPP host here # it will be used to route packets via PPP link # if you didn't specified the noipdefault option # change this line to <local_ip>:<remote_ip>defaultroute # put this if you want that PPP server will be your # default router</pre><p>连接:</p><div class="PROCEDURE"><ol type="1"><li><p>使用<b class="APPLICATION">kermit</b>(或其它的拨号软件)拨号到远程主机,然后键入用户名和密码 (或者其它).</p></li><li><p>退出<b class="APPLICATION">kermit</b> (不挂断连接).</p></li><li><p>键入下面这行:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">/usr/src/usr.sbin/pppd.new/pppd <varclass="REPLACEABLE">/dev/tty01</var> <var class="REPLACEABLE">19200</var></kbd></pre><p>一定要使用正确的速度和设备名.</p></li></ol></div><p>现在你的计算机已经用PPP连接. 如果连接失败 , 你可在文件<ttclass="FILENAME">/etc/ppp/options</tt>中添加 <varclass="OPTION">debug</var>选项,察看控制台信息以跟踪问题.</p><p>下面这个<tt class="FILENAME">/etc/ppp/pppup</tt>脚本能自动完成这三个步骤:</p><pre class="PROGRAMLISTING">#!/bin/shps ax |grep pppd |grep -v greppid=`ps ax |grep pppd |grep -v grep|awk '{print $1;}'`if [ "X${pid}" != "X" ] ; then echo 'killing pppd, PID=' ${pid} kill ${pid}fips ax |grep kermit |grep -v greppid=`ps ax |grep kermit |grep -v grep|awk '{print $1;}'`if [ "X${pid}" != "X" ] ; then echo 'killing kermit, PID=' ${pid} kill -9 ${pid}fiifconfig ppp0 downifconfig ppp0 deletekermit -y /etc/ppp/kermit.dialpppd /dev/tty01 19200</pre><p><tt class="FILENAME">/etc/ppp/kermit.dial</tt>是一个 <bclass="APPLICATION">kermit</b>脚本,它用于向远程主机进行拨号和验证(在文档的最后有这个脚本的例子).</p><p>使用下面这个脚本<tt class="FILENAME">/etc/ppp/pppdown</tt>断开PPP连线:</p><pre class="PROGRAMLISTING">#!/bin/shpid=`ps ax |grep pppd |grep -v grep|awk '{print $1;}'`if [ X${pid} != "X" ] ; then echo 'killing pppd, PID=' ${pid} kill -TERM ${pid}fips ax |grep kermit |grep -v greppid=`ps ax |grep kermit |grep -v grep|awk '{print $1;}'`if [ "X${pid}" != "X" ] ; then echo 'killing kermit, PID=' ${pid} kill -9 ${pid}fi/sbin/ifconfig ppp0 down/sbin/ifconfig ppp0 deletekermit -y /etc/ppp/kermit.hup/etc/ppp/ppptest</pre><p>通过执行<tt class="FILENAME">/usr/etc/ppp/ppptest</tt>,看看<ttclass="COMMAND">pppd</tt> 是否仍在运行:</p><pre class="PROGRAMLISTING">#!/bin/shpid=`ps ax| grep pppd |grep -v grep|awk '{print $1;}'`if [ X${pid} != "X" ] ; then echo 'pppd running: PID=' ${pid-NONE}else echo 'No pppd running.'fiset -xnetstat -n -I ppp0ifconfig ppp0</pre><p>执行脚本 <tt class="FILENAME">/etc/ppp/kermit.hup</tt>以挂起moderm,这个文件包含:</p><pre class="PROGRAMLISTING">set line /dev/tty01 ; put your modem device hereset speed 19200set file type binaryset file names literalset win 8set rec pack 1024set send pack 1024set block 3set term bytesize 8set command bytesize 8set flow nonepau 1out +++inp 5 OKout ATH0\13echo \13exit</pre><p>也可以用<tt class="COMMAND">chat</tt> 代替<tt class="COMMAND">kermit</tt>:</p><p>以下两个文件用以建立<tt class="COMMAND">pppd</tt>连接.</p><p><tt class="FILENAME">/etc/ppp/options</tt>:</p><pre class="PROGRAMLISTING">/dev/cuaa1 115200crtscts # enable hardware flow controlmodem # modem control lineconnect "/usr/bin/chat -f /etc/ppp/login.chat.script"noipdefault # remote PPP serve must supply your IP address # if the remote host doesn't send your IP during # IPCP negotiation, remove this optionpassive # wait for LCP packetsdomain <your.domain> # put your domain name here: # put the IP of remote PPP host here # it will be used to route packets via PPP link # if you didn't specified the noipdefault option # change this line to <local_ip>:<remote_ip>defaultroute # put this if you want that PPP server will be # your default router</pre><p><tt class="FILENAME">/etc/ppp/login.chat.script</tt>:</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> 以下的内容应该放在一行内.</p></blockquote></div><pre class="PROGRAMLISTING">ABORT BUSY ABORT 'NO CARRIER' "" AT OK ATDT<phone.number> CONNECT "" TIMEOUT 10 ogin:-\\r-ogin: <login-id> TIMEOUT 5 sword: <password></pre><p>一旦这些被安装且修改正确,你所要做的就是运行<tt class="COMMAND">pppd</tt>,就像这样:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">pppd</kbd></pre></div><div class="SECT2"><h2 class="SECT2"><a id="AEN24263" name="AEN24263">18.3.3. 使用<ttclass="COMMAND">pppd</tt>作为服务器</a></h2><p><tt class="FILENAME">/etc/ppp/options</tt>要包括下面这些内容:</p><pre class="PROGRAMLISTING">crtscts # Hardware flow controlnetmask 255.255.255.0 # netmask (not required)192.114.208.20:192.114.208.165 # IP's of local and remote hosts # local ip must be different from one # you assigned to the ethernet (or other) # interface on your machine. # remote IP is IP address that will be # assigned to the remote machinedomain ppp.foo.com # your domainpassive # wait for LCPmodem # modem line</pre><p>下面这个脚本<tt class="FILENAME">/etc/ppp/pppserv</tt> 使<bclass="APPLICATION">pppd</b>以服务器方式启动:</p><pre class="PROGRAMLISTING">#!/bin/shps ax |grep pppd |grep -v greppid=`ps ax |grep pppd |grep -v grep|awk '{print $1;}'`if [ "X${pid}" != "X" ] ; then echo 'killing pppd, PID=' ${pid} kill ${pid}fips ax |grep kermit |grep -v greppid=`ps ax |grep kermit |grep -v grep|awk '{print $1;}'`if [ "X${pid}" != "X" ] ; then echo 'killing kermit, PID=' ${pid} kill -9 ${pid}fi# reset ppp interfaceifconfig ppp0 downifconfig ppp0 delete# enable autoanswer modekermit -y /etc/ppp/kermit.ans# run ppppppd /dev/tty01 19200</pre><p>使用脚本<tt class="FILENAME">/etc/ppp/pppservdown</tt>停止服务器:</p><pre class="PROGRAMLISTING">#!/bin/shps ax |grep pppd |grep -v greppid=`ps ax |grep pppd |grep -v grep|awk '{print $1;}'`if [ "X${pid}" != "X" ] ; then echo 'killing pppd, PID=' ${pid} kill ${pid}fips ax |grep kermit |grep -v greppid=`ps ax |grep kermit |grep -v grep|awk '{print $1;}'`if [ "X${pid}" != "X" ] ; then echo 'killing kermit, PID=' ${pid} kill -9 ${pid}fiifconfig ppp0 downifconfig ppp0 deletekermit -y /etc/ppp/kermit.noans</pre><p>The following <b class="APPLICATION">kermit</b> script (<ttclass="FILENAME">/etc/ppp/kermit.ans</tt>) will enable/disable autoanswer mode on yourmodem. It should look like this:</p><pre class="PROGRAMLISTING">set line /dev/tty01set speed 19200set file type binaryset file names literalset win 8set rec pack 1024set send pack 1024set block 3set term bytesize 8set command bytesize 8set flow nonepau 1out +++inp 5 OKout ATH0\13inp 5 OKecho \13out ATS0=1\13 ; change this to out ATS0=0\13 if you want to disable ; autoanswer modeinp 5 OKecho \13exit</pre><p>一个名为<tt class="FILENAME">/etc/ppp/kermit.dial</tt>的脚本用于向远程主机进行拨号和验证.你要根据需要定制它.要加入你的登寻名和密码.你还要根据modem和远程主机的反应更改输入语句.</p><pre class="PROGRAMLISTING">;; put the com line attached to the modem here:;set line /dev/tty01;; put the modem speed here:;set speed 19200set file type binary ; full 8 bit file xferset file names literalset win 8set rec pack 1024set send pack 1024set block 3set term bytesize 8set command bytesize 8set flow noneset modem hayesset dial hangup offset carrier auto ; Then SET CARRIER if necessary,set dial display on ; Then SET DIAL if necessary,set input echo onset input timeout proceedset input case ignoredef \%x 0 ; login prompt countergoto slhup:slcmd ; put the modem in command modeecho Put the modem in command mode.clear ; Clear unread characters from input bufferpause 1output +++ ; hayes escape sequenceinput 1 OK\13\10 ; wait for OKif success goto slhupoutput \13pause 1output at\13input 1 OK\13\10if fail goto slcmd ; if modem doesn't answer OK, try again:slhup ; hang up the phoneclear ; Clear unread characters from input bufferpause 1echo Hanging up the phone.output ath0\13 ; hayes command for on hookinput 2 OK\13\10if fail goto slcmd ; if no OK answer, put modem in command mode:sldial ; dial the numberpause 1echo Dialing.output atdt9,550311\13\10 ; put phone number hereassign \%x 0 ; zero the time counter:lookclear ; Clear unread characters from input bufferincrement \%x ; Count the secondsinput 1 {CONNECT }if success goto slloginreinput 1 {NO CARRIER\13\10}if success goto sldialreinput 1 {NO DIALTONE\13\10}if success goto slnodialreinput 1 {\255}if success goto slhupreinput 1 {\127}if success goto slhupif < \%x 60 goto lookelse goto slhup:sllogin ; loginassign \%x 0 ; zero the time counterpause 1echo Looking for login prompt.:slloopincrement \%x ; Count the secondsclear ; Clear unread characters from input bufferoutput \13;; put your expected login prompt here:;input 1 {Username: }if success goto sluidreinput 1 {\255}if success goto slhupreinput 1 {\127}if success goto slhupif < \%x 10 goto slloop ; try 10 times to get a login promptelse goto slhup ; hang up and start again if 10 failures:sluid;; put your userid here:;output ppp-login\13input 1 {Password: };; put your password here:;output ppp-password\13input 1 {Entering SLIP mode.}echoquit:slnodialecho \7No dialtone. Check the telephone line!\7exit 1; local variables:; mode: csh; comment-start: "; "; comment-start-skip: "; "; end:</pre></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="userppp.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="ppp-troubleshoot.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">使用用户级PPP</td><td width="34%" align="center" valign="top"><a href="ppp-and-slip.html"accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Troubleshooting <acronymclass="ACRONYM">PPP</acronym> Connections</td></tr></table></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -