Connecting with Linux via PPP to DAS <author>Steve Robbins <<tt/> <date>16 August, 1998 <abstract> This document describes how to get PPP up and running on your home linux box. If you are running a Microsoft operating system, please see the <url url="" name="instructions"> provided by the folks at the <url url="" name="McGill Computing Centre">. </abstract> <!-- Table of contents --> <toc> <!-- Begin the document --> <sect>Prerequisites <P>Before attempting to use PPP, you must check two things. <sect1>Ensure that the Modem Works <P>There are no instructions here for troubleshooting serial links. Test the modem installation using a terminal program such as <tt/minicom/. If you can dial the modem, and log into a remote site, (DAS, for example) the modem should work fine. <sect1>Ensure that the Networking Tools are Installed <P>At a minimum, you need: <tt>ifconfig</tt>, and <tt>route</tt>. These will suffice to get the link set up. <P>To actually <em/use/ the link, you'll need things like <tt/telnet/, <tt/rlogin/, a web browser, an ftp client, or the like. <sect>General Network Configuration <P>Since many people don't use the Linux networking code at all until they get a PPP link, this section describes generally what's needed to get things running. In principle none of this is special to PPP. For more details, you should consult the relevant Linux HOWTOs. If you already understand network setup, you can skip this section. <sect1>Boot Time Configuration (<tt>/etc/rc</tt> Scripts) <P>The first file that requires attention is the rc script that does network configuration at boot time, called <tt>/etc/</tt> or <tt>/etc/rc.d/{1,2}</tt> or something similar, depending on your Linux distribution. This file should <tt/ifconfig/ the loopback interface lo, and should add an interface route for it. These lines might look something like this: <code> $CONFIG lo $ROUTE add loopback </code> or <code> /sbin/ifconfig lo /sbin/route add </code> <P>However, it should <bf>not</bf> config an ethernet card or install any other routes (unless you actually have an ethernet card, in which case I'll assume you know what to do). Many distributions will provide scripts that expect you to have an ethernet card. <sect1>The Hosts File (<tt>/etc/hosts</tt>) <P>Next, you must ensure that <tt>/etc/hosts</tt> has at least the following line: <code> localhost </code> <sect1>Nameserver (DNS) Configuration <P>Finally, you need to configure the domain name system by putting appropriate lines in <tt>/etc/resolv.conf</tt>. It should look like this: <code> domain nameserver nameserver </code> <sect>Installing PPP <p>Linux PPP operations come in two parts: PPP support code in the kernel, and a PPP <em/daemon/. We will tackle each in turn. <sect1>Compiling PPP Support into the Kernel <p>Many distributions seem to provide PPP kernel support in their default installation kernels, but others do not. <p>If at boot your kernel reports messages like <tscreen><verb> PPP Dynamic channel allocation code copyright 1995 Caldera, Inc. PPP line discipline registered. </verb></tscreen> then your kernel <em>does</em> have PPP support compiled in. <!-- TIP --> You can check these boot-time messages using the command <tscreen><verb> dmesg </verb></tscreen> <p> If you do <em/not/ have kernel support for PPP, you will need to re-build the kernel. See your distribution's documentation, or the Kernel-HOWTO at <url url="" name="The Linux Kernel HOWTO"> for full details. <sect1>Obtaining and Installing the PPP Daemon <P>You will need version 2.0 or better of the PPP Daemon, <tt/pppd/. You can check if <tt/pppd/ is installed, and find out its version number using <tscreen><verb> pppd -version </verb></tscreen> (or maybe <tt>/usr/sbin/pppd -version</tt>). <p>If you need to install <tt/pppd/, look first on your distribution disks or web site. If your Linux distribution does not include the PPP software, you will need to obtain and compile <url url="" name="the Linux PPP daemon"> source code. Locate a file named <tt/ppp-X.Y.Z.tar.gz/, and choose the latest version (i.e., highest version X.Y.Z) available from this site. <p>The PPP package contains instructions on how to compile and install the software <bf/so this document does not/! <sect1>Configuring the Chat Script <P>Copy the following <url url="das-chat" name="chat script"> to <tt>/etc/ppp/chat/das</tt>. <tscreen><verb> ABORT BUSY ABORT 'NO DIALTONE' ABORT 'NO CARRIER' ABORT 'RING\r' '' ATZ OK-ATZ-OK ATM0D3988211 CONNECT \p\c TIMEOUT 10 name:--name:--name:--name: _your_das_username_here_ sword: _your_das_password_here_\q Box "ppp /compressed default" </verb></tscreen> Edit the script: <enum> <item>Replace the string <tt>_your_das_username_here_</tt> with your DAS user name. <item>Replace the string <tt>_your_das_password_here_</tt> with the password. Note that there is a trailing '\q' after the password <bf>with no space</bf> between the password and '\q'. Leave it there: it suppresses writing the password into log files. </enum> If you need to embed a space into either the username or the password, you can quote the string. For example: "this password has spaces". Finally, note that your DAS password is contained <bf/in cleartext/ in this file, so it must be protected: <tscreen><verb> chmod 600 /etc/chat/das </verb></tscreen> <sect1>Testing the PPP Daemon Manually <P>First, make sure you are logging debug-level syslog messages. If your <tt>/etc/syslog.conf</tt> does <bf>not</bf> have a line such as: <verb> *.debug;cron.none -/var/log/debug </verb> then put one there, and make syslog re-read the file with <tt>kill -HUP `cat /var/run/`</tt>, or similar. <P>Next, attempt to set up a PPP connection with a command such as: <tscreen><verb> pppd ttyS1 38400 modem crtscts defaultroute lock \ netmask \ connect "chat -v -f /etc/ppp/chat/das" </verb></tscreen> You must, of course, replace <tt/ttyS1/ with the name of the serial port to which your modem is connected. Remember, DOS <tt>COM</tt><em/n/ translates to <tt/ttyS/<em/n-1/ in linux. <P>The '-v' option for <tt/chat/ turns on verbose mode, in which the complete chat dialog is logged to syslog. After the above modification, debug-level syslog messages are being logged to the file <tt>/var/log/debug</tt>. You should <tt>tail -f /var/log/debug</tt> now to check the progress of the chat script. <P>Assuming all goes well, you will eventually see a message in the syslog similar to: <verb> Sep 19 12:25:27 hilbert pppd[17524]: Connect: ppp0 <--> /dev/ttyS3 Sep 19 12:25:30 hilbert pppd[17524]: local IP address Sep 19 12:25:30 hilbert pppd[17524]: remote IP address </verb> (The IP addresses will be different, of course) <P>You're on the net! Running <tt/ifconfig/ should show a <tt/ppp0/ interface. The net tools, such as telnet, should now work. Of course, there may be something amis with the nameserver at this point. So it is prudent to first try with an IP address: <tt/telnet If that works, try with the name: <tt/telnet nova/. <P>Your PPP connection is ended by: <tt>kill -HUP `cat /var/run/ppp*.pid`</tt>. The syslog should show the link going down. <sect>Scripts <P>In the previous section on installing PPP, the commands to set up and tear down the PPP link were given. However, these are a bit unwieldy, so I prefer to use the following two scripts: <tt>ppp-on</tt> to bring up the link, and <tt>ppp-off</tt> to tear it down again. <sect1><tt/ppp-on/ <P>Save <url url="ppp-on" name="the ppp-on script"> to <tt>/usr/sbin/ppp-on</tt>, and make it executable: <code> #! /bin/sh # # Script to set up a PPP link. # # Usage: ppp-on [-p port] [-s speed] [script] # # Set yer defaults here # port=/dev/modem script=das speed=38400 verbose= while [ -n "$1" ]; do case $1 in -p) shift; port=$1;; -s) shift; speed=$1;; -v) verbose=-v;; *) break;; esac shift done if [ $# -gt 0 ]; then script=$1 shift fi pppd $port $speed modem crtscts defaultroute lock \ netmask "$@" \ connect "chat $verbose -f /etc/ppp/chat/$script" </code> <sect1><tt/ppp-off/ <P>Save <url url="ppp-off" name="the ppp-off script"> to <tt>/usr/sbin/ppp-off</tt>, and make it executable: <code> #! /bin/sh # # Take down PPP links. # # Usage: ppp-off [interface ...] # - if no interface specified, will kill 'em all! # cd /var/run if [ $# -gt 0 ]; then for int in $*; do echo "Taking down $int." kill -HUP `cat $` done else echo "Taking down all interfaces." kill -HUP `cat ppp*.pid` fi </code> <sect>Installing <tt>diald</tt> <P>Using the scripts <tt/ppp-on/ and <tt/ppp-off/ can be a bit tedious. One might forget to bring up the link before starting up the browser, and find out that no sites are reachable. Or worse: forgetting to shut down the link when done will keep your phone line occupied, and rack up connect charges. <P>The solution to this is <em/dial-on-demand/ networking. The idea is to run a daemon that will sense when you are using the network, and start up PPP itself. When the daemon detects that the net link is idle, it brings the link down again. <P>These tasks are handled by the <url url="" name="diald daemon">. If your distribution does not include <tt/diald/, its web pages contain links to the diald source code, and instructions on how to build it. When installed, diald can be started at boot time with the <url url="diald" name="following script">. This script is a SysV-style init.d script, and it can also be called by (after the loopback interface is configured). <code> #! /bin/sh # # skeleton Example file to build /etc/init.d scripts. # # Version: @(#) /etc/init.d/skeleton 1.01 26-Oct-1993 # # Author: Miquel van Smoorenburg, <> # PIDFILE="" FIFO="diald.ctl" ACCLOG="/var/log/diald" # See how we were called. case "$1" in start) cd /var/run rm $PIDFILE $FIFO 2>/dev/null mknod $FIFO p # # Uncomment the next lines & substitute the desired group for "dialout". # This restricts access to the diald control channel to root and the members # of the stated group. For a single-user system, this is unimportant. # # chown root.dialout $FIFO # chmod 660 $FIFO diald pidfile $PIDFILE fifo $FIFO accounting-log $ACCLOG \ connect "chat -v -f /etc/ppp/chat/das" \ local remote defaultroute ;; stop) kill `cat /var/run/diald*.pid` ;; *) # Oops someone made a typo. echo "Usage: /etc/init.d/diald {start|stop}" exit 1 esac exit 0 </code> <sect>Acknowledgements <P>Large chunks of the text were directly borrowed from <url url="http://services.CS.McGill.CA/LDP/HOWTO/PPP-HOWTO.html" name="the PPP HowTo document">, and from the <tt>pppd</tt> FAQ file. </article>