update for rename of docs/user/DebugKernelCrashDumps.mdwn to docs/user/list/DebugKern...
[ikiwiki.git] / docs / handbook / handbook-ppp.mdwn
1 \r
2 \r
3 ## 18.3 Using Kernel PPP \r
4 \r
5 ***Parts originally contributed by Gennady B. Sorokopud and Robert Huff. ***\r
6 \r
7 ### 18.3.1 Setting Up Kernel PPP \r
8 \r
9 Before you start setting up PPP on your machine, make sure that `pppd` is located in `/usr/sbin` and the directory `/etc/ppp` exists.\r
10 \r
11 `pppd` can work in two modes:\r
12 \r
13   1. As a ***client*** -- you want to connect your machine to the outside world via a PPP serial connection or modem line.\r
14   1. As a ***server*** -- your machine is located on the network, and is used to connect other computers using PPP.\r
15 \r
16 In both cases you will need to set up an options file (`/etc/ppp/options` or `~/.ppprc` if you have more than one user on your machine that uses PPP).\r
17 \r
18 You will also need some modem/serial software (preferably [`comms/kermit`](http://pkgsrc.se/comms/kermit)), so you can dial and establish a connection with the remote host.\r
19 \r
20 ### 18.3.2 Using `pppd` as a Client \r
21 \r
22 ***Based on information provided by Trev Roydhouse. ***\r
23 \r
24 The following `/etc/ppp/options` might be used to connect to a Cisco terminal server PPP line.\r
25 \r
26     \r
27     crtscts         # enable hardware flow control\r
28     modem           # modem control line\r
29     noipdefault     # remote PPP server must supply your IP address\r
30                     # if the remote host does not send your IP during IPCP\r
31                     # negotiation, remove this option\r
32     passive         # wait for LCP packets\r
33     domain ppp.foo.com      # put your domain name here\r
34     \r
35     :<remote_ip>    # put the IP of remote PPP host here\r
36                     # it will be used to route packets via PPP link\r
37                     # if you didn't specified the noipdefault option\r
38                     # change this line to <local_ip>:<remote_ip>\r
39     \r
40     defaultroute    # put this if you want that PPP server will be your\r
41                     # default router\r
42 \r
43 \r
44 To connect:\r
45 \r
46   1. Dial to the remote host using  **kermit**  (or some other modem program), and enter your user name and password (or whatever is needed to enable PPP on the remote host).\r
47   1. Exit  **kermit**  (without hanging up the line).\r
48   1. Enter the following:\r
49       \r
50       # /usr/src/usr.sbin/pppd.new/pppd `***/dev/tty01***` `***19200***`\r
51   \r
52   Be sure to use the appropriate speed and device name.\r
53 \r
54 Now your computer is connected with PPP. If the connection fails, you can add the `debug` option to the `/etc/ppp/options` file, and check console messages to track the problem.\r
55 \r
56 Following `/etc/ppp/pppup` script will make all 3 stages automatic:\r
57 \r
58     \r
59     #!/bin/sh\r
60     ps ax |grep pppd |grep -v grep\r
61     pid=`ps ax |grep pppd |grep -v grep|awk '{print $1;}'`\r
62     if [ "X${pid}" != "X" ] ; then\r
63             echo 'killing pppd, PID=' ${pid}\r
64             kill ${pid}\r
65     fi\r
66     ps ax |grep kermit |grep -v grep\r
67     pid=`ps ax |grep kermit |grep -v grep|awk '{print $1;}'`\r
68     if [ "X${pid}" != "X" ] ; then\r
69             echo 'killing kermit, PID=' ${pid}\r
70             kill -9 ${pid}\r
71     fi\r
72     \r
73     ifconfig ppp0 down\r
74     ifconfig ppp0 delete\r
75     \r
76     kermit -y /etc/ppp/kermit.dial\r
77     pppd /dev/tty01 19200\r
78 \r
79 \r
80 `/etc/ppp/kermit.dial` is a  **kermit**  script that dials and makes all necessary authorization on the remote host (an example of such a script is attached to the end of this document).\r
81 \r
82 Use the following `/etc/ppp/pppdown` script to disconnect the PPP line:\r
83 \r
84     \r
85     #!/bin/sh\r
86     pid=`ps ax |grep pppd |grep -v grep|awk '{print $1;}'`\r
87     if [ X${pid} != "X" ] ; then\r
88             echo 'killing pppd, PID=' ${pid}\r
89             kill -TERM ${pid}\r
90     fi\r
91     \r
92     ps ax |grep kermit |grep -v grep\r
93     pid=`ps ax |grep kermit |grep -v grep|awk '{print $1;}'`\r
94     if [ "X${pid}" != "X" ] ; then\r
95             echo 'killing kermit, PID=' ${pid}\r
96             kill -9 ${pid}\r
97     fi\r
98     \r
99     /sbin/ifconfig ppp0 down\r
100     /sbin/ifconfig ppp0 delete\r
101     kermit -y /etc/ppp/kermit.hup\r
102     /etc/ppp/ppptest\r
103 \r
104 \r
105 Check to see if `pppd` is still running by executing `/usr/etc/ppp/ppptest`, which should look like this:\r
106 \r
107     \r
108     #!/bin/sh\r
109     pid=`ps ax| grep pppd |grep -v grep|awk '{print $1;}'`\r
110     if [ X${pid} != "X" ] ; then\r
111             echo 'pppd running: PID=' ${pid-NONE}\r
112     else\r
113             echo 'No pppd running.'\r
114     fi\r
115     set -x\r
116     netstat -n -I ppp0\r
117     ifconfig ppp0\r
118 \r
119 \r
120 To hang up the modem, execute `/etc/ppp/kermit.hup`, which should contain:\r
121 \r
122     \r
123     set line /dev/tty01 ; put your modem device here\r
124     set speed 19200\r
125     set file type binary\r
126     set file names literal\r
127     set win 8\r
128     set rec pack 1024\r
129     set send pack 1024\r
130     set block 3\r
131     set term bytesize 8\r
132     set command bytesize 8\r
133     set flow none\r
134     \r
135     pau 1\r
136     out +++\r
137     inp 5 OK\r
138     out ATH0\13\r
139     echo \13\r
140     exit\r
141 \r
142 \r
143 Here is an alternate method using `chat` instead of `kermit`:\r
144 \r
145 The following two files are sufficient to accomplish a `pppd` connection.\r
146 \r
147 `/etc/ppp/options`:\r
148 \r
149     \r
150     /dev/cuaa1 115200\r
151     \r
152     crtscts             # enable hardware flow control\r
153     modem               # modem control line\r
154     connect "/usr/bin/chat -f /etc/ppp/login.chat.script"\r
155     noipdefault # remote PPP serve must supply your IP address\r
156                 # if the remote host doesn't send your IP during\r
157                     # IPCP negotiation, remove this option\r
158     passive         # wait for LCP packets\r
159     domain <your.domain>  # put your domain name here\r
160     \r
161     :           # put the IP of remote PPP host here\r
162                 # it will be used to route packets via PPP link\r
163                     # if you didn't specified the noipdefault option\r
164                     # change this line to <local_ip>:<remote_ip>\r
165     \r
166     defaultroute        # put this if you want that PPP server will be\r
167                 # your default router\r
168 \r
169 \r
170 `/etc/ppp/login.chat.script`:\r
171 \r
172  **Note:** The following should go on a single line.\r
173 \r
174     \r
175     ABORT BUSY ABORT 'NO CARRIER' "" AT OK ATDT<phone.number>\r
176       CONNECT "" TIMEOUT 10 ogin:-\\r-ogin: <login-id>\r
177       TIMEOUT 5 sword: <password>\r
178 \r
179 \r
180 Once these are installed and modified correctly, all you need to do is run `pppd`, like so:\r
181 \r
182     \r
183     # pppd\r
184 \r
185 \r
186 ### 18.3.3 Using `pppd` as a Server \r
187 \r
188 `/etc/ppp/options` should contain something similar to the following:\r
189 \r
190     \r
191     crtscts                         # Hardware flow control\r
192     netmask 255.255.255.0           # netmask (not required)\r
193     192.114.208.20:192.114.208.165  # IP's of local and remote hosts\r
194                                     # local ip must be different from one\r
195                                     # you assigned to the ethernet (or other)\r
196                                     # interface on your machine.\r
197                                     # remote IP is IP address that will be\r
198                                     # assigned to the remote machine\r
199     domain ppp.foo.com              # your domain\r
200     passive                         # wait for LCP\r
201     modem                           # modem line\r
202 \r
203 \r
204 The following `/etc/ppp/pppserv` script will tell  **pppd**  to behave as a server:\r
205 \r
206     \r
207     #!/bin/sh\r
208     ps ax |grep pppd |grep -v grep\r
209     pid=`ps ax |grep pppd |grep -v grep|awk '{print $1;}'`\r
210     if [ "X${pid}" != "X" ] ; then\r
211             echo 'killing pppd, PID=' ${pid}\r
212             kill ${pid}\r
213     fi\r
214     ps ax |grep kermit |grep -v grep\r
215     pid=`ps ax |grep kermit |grep -v grep|awk '{print $1;}'`\r
216     if [ "X${pid}" != "X" ] ; then\r
217             echo 'killing kermit, PID=' ${pid}\r
218             kill -9 ${pid}\r
219     fi\r
220     \r
221     # reset ppp interface\r
222     ifconfig ppp0 down\r
223     ifconfig ppp0 delete\r
224     \r
225     # enable autoanswer mode\r
226     kermit -y /etc/ppp/kermit.ans\r
227     \r
228     # run ppp\r
229     pppd /dev/tty01 19200\r
230 \r
231 \r
232 Use this `/etc/ppp/pppservdown` script to stop the server:\r
233 \r
234     \r
235     #!/bin/sh\r
236     ps ax |grep pppd |grep -v grep\r
237     pid=`ps ax |grep pppd |grep -v grep|awk '{print $1;}'`\r
238     if [ "X${pid}" != "X" ] ; then\r
239             echo 'killing pppd, PID=' ${pid}\r
240             kill ${pid}\r
241     fi\r
242     ps ax |grep kermit |grep -v grep\r
243     pid=`ps ax |grep kermit |grep -v grep|awk '{print $1;}'`\r
244     if [ "X${pid}" != "X" ] ; then\r
245             echo 'killing kermit, PID=' ${pid}\r
246             kill -9 ${pid}\r
247     fi\r
248     ifconfig ppp0 down\r
249     ifconfig ppp0 delete\r
250     \r
251     kermit -y /etc/ppp/kermit.noans\r
252 \r
253 \r
254 The following  **kermit**  script (`/etc/ppp/kermit.ans`) will enable/disable autoanswer mode on your modem. It should look like this:\r
255 \r
256     \r
257     set line /dev/tty01\r
258     set speed 19200\r
259     set file type binary\r
260     set file names literal\r
261     set win 8\r
262     set rec pack 1024\r
263     set send pack 1024\r
264     set block 3\r
265     set term bytesize 8\r
266     set command bytesize 8\r
267     set flow none\r
268     \r
269     pau 1\r
270     out +++\r
271     inp 5 OK\r
272     out ATH0\13\r
273     inp 5 OK\r
274     echo \13\r
275     out ATS0#1\13   ; change this to out ATS00\13 if you want to disable\r
276                     ; autoanswer mode\r
277     inp 5 OK\r
278     echo \13\r
279     exit\r
280 \r
281 \r
282 A script named `/etc/ppp/kermit.dial` is used for dialing and authenticating on the remote host. You will need to customize it for your needs. Put your login and password in this script; you will also need to change the input statement depending on responses from your modem and remote host.\r
283 \r
284     \r
285     ;\r
286     ; put the com line attached to the modem here:\r
287     ;\r
288     set line /dev/tty01\r
289     ;\r
290     ; put the modem speed here:\r
291     ;\r
292     set speed 19200\r
293     set file type binary            ; full 8 bit file xfer\r
294     set file names literal\r
295     set win 8\r
296     set rec pack 1024\r
297     set send pack 1024\r
298     set block 3\r
299     set term bytesize 8\r
300     set command bytesize 8\r
301     set flow none\r
302     set modem hayes\r
303     set dial hangup off\r
304     set carrier auto                ; Then SET CARRIER if necessary,\r
305     set dial display on             ; Then SET DIAL if necessary,\r
306     set input echo on\r
307     set input timeout proceed\r
308     set input case ignore\r
309     def \%x 0                       ; login prompt counter\r
310     goto slhup\r
311     \r
312     :slcmd                          ; put the modem in command mode\r
313     echo Put the modem in command mode.\r
314     clear                           ; Clear unread characters from input buffer\r
315     pause 1\r
316     output +++                      ; hayes escape sequence\r
317     input 1 OK\13\10                ; wait for OK\r
318     if success goto slhup\r
319     output \13\r
320     pause 1\r
321     output at\13\r
322     input 1 OK\13\10\r
323     if fail goto slcmd              ; if modem doesn't answer OK, try again\r
324     \r
325     :slhup                          ; hang up the phone\r
326     clear                           ; Clear unread characters from input buffer\r
327     pause 1\r
328     echo Hanging up the phone.\r
329     output ath0\13                  ; hayes command for on hook\r
330     input 2 OK\13\10\r
331     if fail goto slcmd              ; if no OK answer, put modem in command mode\r
332     \r
333     :sldial                         ; dial the number\r
334     pause 1\r
335     echo Dialing.\r
336     output atdt9,550311\13\10               ; put phone number here\r
337     assign \%x 0                    ; zero the time counter\r
338     \r
339     :look\r
340     clear                           ; Clear unread characters from input buffer\r
341     increment \%x                   ; Count the seconds\r
342     input 1 {CONNECT }\r
343     if success goto sllogin\r
344     reinput 1 {NO CARRIER\13\10}\r
345     if success goto sldial\r
346     reinput 1 {NO DIALTONE\13\10}\r
347     if success goto slnodial\r
348     reinput 1 {\255}\r
349     if success goto slhup\r
350     reinput 1 {\127}\r
351     if success goto slhup\r
352     if < \%x 60 goto look\r
353     else goto slhup\r
354     \r
355     :sllogin                        ; login\r
356     assign \%x 0                    ; zero the time counter\r
357     pause 1\r
358     echo Looking for login prompt.\r
359     \r
360     :slloop\r
361     increment \%x                   ; Count the seconds\r
362     clear                           ; Clear unread characters from input buffer\r
363     output \13\r
364     ;\r
365     ; put your expected login prompt here:\r
366     ;\r
367     input 1 {Username: }\r
368     if success goto sluid\r
369     reinput 1 {\255}\r
370     if success goto slhup\r
371     reinput 1 {\127}\r
372     if success goto slhup\r
373     if < \%x 10 goto slloop         ; try 10 times to get a login prompt\r
374     else goto slhup                 ; hang up and start again if 10 failures\r
375     \r
376     :sluid\r
377     ;\r
378     ; put your userid here:\r
379     ;\r
380     output ppp-login\13\r
381     input 1 {Password: }\r
382     ;\r
383     ; put your password here:\r
384     ;\r
385     output ppp-password\13\r
386     input 1 {Entering SLIP mode.}\r
387     echo\r
388     quit\r
389     \r
390     :slnodial\r
391     echo \7No dialtone.  Check the telephone line!\7\r
392     exit 1\r
393     \r
394     ; local variables:\r
395     ; mode: csh\r
396     ; comment-start: "; "\r
397     ; comment-start-skip: "; "\r
398     ; end:\r
399 \r
400 \r
401 \r
402 \r
403 CategoryHandbook\r
404 CategoryHandbook-pppandslip\r