PPP Configuration

It is beyond the scope of this document to describe setting up a modem, so it will be asumed that your modem is functioning, which can be verified with a terminal program such as minicom.

pppd searches /etc/ppp for dial scripts and the file "options."

Here's a sample /etc/ppp/options file:

/dev/modem 57600 crtscts modem noipdefault defaultroute idle-disconnect 300

Meaning:

/dev/modem
Usually a symbolic link to /dev/cuax, the serial port to which the modem is connected.
57600
Gets replaced by 115200 (spd_vhi-parameter in /etc/rc.d/rc.serial).
crtscts
Hardware handshake, RTS/CTS, as opposed to Xon-Xoff handshaking.
noipdefault
The IP address is assigned automatically when the connection is made.
defaultroute
Sets the default route to the ppp interface (ppp0) when the link is up.
idle-disconnect
ppp will automatically disconnect after the interface is idle for this many seconds.

Next, make a script called "default", which normally means your ISP. If you want to make other scripts for routes to specific hosts, create additional scripts and name them with the remote IP address. I suppose you would do this for high-cost/speed connections to certain hosts, like an ISDN line to another office, where you know the IP address you are going to reach.

/etc/ppp/default

'ABORT' 'BUSY'
'ABORT' 'ERROR'
'ABORT' 'NO CARRIER'
'ABORT' 'NO DIALTONE'
'ABORT' 'Invalid Login'
'ABORT' 'Login incorrect'
'' 'AT&F1S11=55'
'OK' 'ATDT5552000'
'CONNECT' ''
'ogin:' 'USER'
'word:' 'PASSWD'

Change the first AT string to include any modem initialization string you require. I use the S11=55 to speed up the dial tones. Also change the phone number from 5552000 to your ISP's modem access number. Change USER and PASSWD to be your actual userid and password at your ISP. Each expect/reply pair following the CONNECT line should be the prompt and response required for you to log in to the ppp server and start a session. For more information, see the ppp HOWTO.

Note to RedHat users: The above script is exactly the script generated by the GUI configuration tool off of the control-panel. You can make /etc/ppp/default a link to the generated file /etc/sysconfig/network-scripts/chat-ppp0 . Do this with the command

ln /etc/sysconfig/network-scripts/chat-ppp0 /etc/ppp/default

Now whenever you use the control-panel to edit your ppp script, it will still work for the on demand dialing.

Make another short script to make the ppp call:

/etc/ppp/ppp

#!/bin/sh
/usr/sbin/pppd connect '/usr/sbin/chat -v -f /etc/ppp/default'

You should be able to make a connection by running /etc/ppp/ppp. After the connection is made, check with ifconfig to make sure there is a ppp0 interface. Check for the default route with 'netstat -r'.

Be sure to put your nameserver in /etc/resolv.conf:

search so-and-so.domain
nameserver x.x.x.x

Dial On Demand

kerneld can be used to load modules, such as ppp, on demand. As described in the kerneld-HOWTO, it can also run a script if a particular network route is missing. kerneld will try to run '/sbin/request-route'. The following is the one I use.

/sbin/request-route:

#!/bin/sh
LOCK=/var/run/request-route.pid
PATH=/usr/sbin:$PATH    # for ppp-2.2*
export PATH

# Note: you are _not_ forced to use ppp!
# You can do whatever you want in order to satisfy the kernel route request.
# It might be a good idea to set up the route as the default route, in case
# you are using e.g. slip or plip or any other net driver...

#
# This script will be called from kerneld with the requested route as $1
# Create a chat script for your nameserver (as defined in /etc/resolv.conf)
#

#This script will be called from kerneld with the requested route as $1

chatfile=/etc/ppp/$1

# If no chatscript exists use a default value (symlink to preferred script):

[ ! -f $chatfile ] && chatfile=/etc/ppp/default

# Check if we're already running:

if [ ! -f $LOCK ]; then
        pppd connect "chat -f $chatfile" &

        # Timer to be killed by ip-up, tunable! Check kerneld delay as well
        sleep 60 &
        sleepid=$!
        echo $sleepid > $LOCK
        wait $sleepid
        rm -f $LOCK
        exit 0
fi
exit 1

kerneld will run this script using the missing route as an arugument:

/sbin/request-route x.x.x.x

After the link has been activated, pppd runs the script /etc/ppp/ip-up. Add commands you want to execute each time the link is brought up to /etc/ppp/ip-up.local. Here is mine:

/etc/ppp/ip-up.local:

#!/bin/bash
#
# $1    interface name
# $2    tty device
# $3    speed
# $4    local ip address
# $5    remote ip address

# wait 40 seconds and set the clock
# change x.x.x.x to an accurate time server. run rdate host to test it.
(sleep 40; /usr/bin/rdate -s x.x.x.x)&

The "idle-disconnect" option automatically disconnects the link after it is idle for the time specified. Use "ppp-off" to disconnect immediately:

/usr/sbin/ppp-off

#!/bin/sh
LOCK=/var/run/request-route.pid
DEVICE=ppp0

rm -f $LOCK

#
# If the ppp0 pid file is present then the program is running. Stop it.
#
if [ -r /var/run/$DEVICE.pid ]; then
    kill -INT 'cat /var/run/$DEVICE.pid'
    
#
# If unsuccessful, ensure that the pid file is removed.
#
	if [ ! "$?" = "0" ] ; then
		echo "removing stale $DEVICE pid file."
		rm -f /var/run/$DEVICE.pid
		exit 1
	fi

#
# Success. Terminate with proper status.
#
	echo "$DEVICE link terminated"
	exit 0
fi

#
# The link is not active
#
echo "$DEVICE link is not active"

exit 1

With this configured, any outgoing packet will cause the ppp link to come up. I have set up a crontab entry to cause the connection to come up every 15 minutes during the day by sending one ping to my nameserver. I do this so I can access my system within ten minutes. The connection is timed out after five minutes if there is no further activity. Add a crontab entry as follows:

crontab -e

# insert this line
*/15 6-23 * * 1-5 /bin/ping -c 1 x.x.x.x >& /dev/null

The meaning of this entry is: every 15 minutes from 0600 to 2359 Monday-Friday ping host x.x.x.x with one packet, sending stdout and stderr to /dev/null because I don't want an mail message every 15 minutes. See the crontab man page for more info.

Something else I would like to set up is a program to listen for the phone to ring once, wait a minute, then dial out. That way I could call my computer, and a couple minutes later be able to connect with it.

Previous | Main | Next