[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Set up PPP for two ISPs



My approach to two ISP's is a little different than the one David
described.  One of my ISP's is my employer (so I don't want my kids
connecting there by mistake), the other is Together Networks (a
Burlington, Vermont based ISP). 

I have duplicate sets of files for each ISP:

/etc/sendmail.cf
/etc/named.boot
/etc/resolv.conf
PPP options files

In my ppp-on script, I verify the person is really me to connect to my
employer (at least well enough that my kids can't get around it yet).
Depending on whether ppp-on is connecting to IBM or to Together Networks,
it will call pppd with different options (specifically the -file parameter
to specify which options file to read).

It is the job of my ip-up script to determine which network was connected
to and put the correct /etc/resolv.conf, named.boot, and sendmail.cf files
into place (with a stop/start for named and sendmail).

On the flip side, when ip-down gets called, it puts back my "local" files
so the name server won't hang me up forever when I send mail without being
connected anywhere.  I've also got a sendmail.cf file for when I'm not
connected that just queues the mail (and since I don't run the queue if
I'm not connected to one ISP or the other, it'll sit there until I do next
connect).

Here's my ip-up script (Warning: it's from a slackware distribution)

#!/bin/sh
#
# ip-up: shell script hook called by pppd when the interface is brought up
#
# Parameters are:
#   $0: name of the script (ip-up or ip-down)
#   $1: name of the network device (such as ppp0)
#   $2: name of the tty device (such as /dev/ttyS0)
#   $3: speed of the tty device in Bits Per Second (such as 115200)
#   $4: the local IP address in dotted decimal notation
#   $5: the remote IP address in dotted decimal notation
#
# /tmp/local_name is a file with my local machine name
# /etc/hosts.local is the default /etc/hosts file with
# 127.0.0.1 localhost as the only entry
#
# This script handles:
#    1) getting the correct /etc/resolv.conf (either ibm or together.net)
#    2) making it possible to ping my own address
#    3) updating my /etc/hosts file to have the address and name
#
#echo "ip-up parameters are: $*" >/dev/console
LOGGER="/usr/bin/logger -t pppd"

$LOGGER "ip-up parameters are: $*"

# 0) determine connect speed
CSpeed=`/usr/bin/grep ARQ /etc/ppp/ppp.log | /usr/bin/tail -1 | \
	/usr/bin/sed -e 's/.*: *//' -e 's|/.*||'`
#echo "Connected at $CSpeed" >/dev/console 

# 1) make it possible to ping my own address
/sbin/route add -host $4 lo

#
# 2) Determine whether this is my internal network or not
#
# Determine the network connected to
NETWORK=`/usr/local/bin/netmath -a $4 255.0.0.0`
if [ x$NETWORK != "x192.0.0.0" ]; then

    # 3) Set up /etc/resolv.conf and named.boot files based on
    #    the network connected to.
    #
    if [ x$NETWORK = "x9.0.0.0" ]; then
	/bin/cp -p /etc/resolv.ibm /etc/resolv.conf
	/bin/cp -p /etc/named.ibm /etc/named.boot
    else
    if [ x$NETWORK = "x204.0.0.0" ]; then
	/bin/cp -p /etc/resolv.together.net /etc/resolv.conf
	/bin/cp -p /etc/named.together.net /etc/named.boot
    else
    if [ x$NETWORK = "x207.0.0.0" ]; then
	/bin/cp -p /etc/resolv.together.net /etc/resolv.conf
	/bin/cp -p /etc/named.together.net /etc/named.boot
    else
    if [ x$NETWORK = "x208.0.0.0" ]; then
	/bin/cp -p /etc/resolv.together.net /etc/resolv.conf
	/bin/cp -p /etc/named.together.net /etc/named.boot
    else
	echo "Bad NETWORK value '$NETWORK'" >/dev/console
    fi
    fi
    fi
    fi

    # 4) Reload nameserver
    #  -- Debian version
    #/etc/init.d/bind reload
    #  -- Slackware version
    if [ -f /var/run/named.pid ]; then
#	echo "Reloading nameserver" >/dev/console
	kill `cat /var/run/named.pid`
	/usr/sbin/named
#	echo "Done... nameserver" >/dev/console
    fi

    # 5) update /etc/hosts file
    #
    # Put generic hosts file in place

    # Determine the name of my address
    /usr/bin/host $4 | fgrep Name | cut -c7- > /tmp/ip_name

    # Put my address in a file
    echo "$4" >/tmp/ip

    # Build a new line for /etc/hosts
    /usr/bin/paste /tmp/ip /tmp/ip_name /etc/hostname > /tmp/host_bottom

    # Build the new /etc/hosts file
    /bin/cat /tmp/host_bottom /etc/hosts.local > /etc/hosts

    # Update hostname
    #hostname `cat /tmp/ip_name`

    # Update /etc/sendmail.cw file
    cat /tmp/ip_name >>/etc/sendmail.cw

    # clean up
    /bin/rm -f /tmp/ip /tmp/ip_name /tmp/host_bottom

    # 6) Recycle the sendmail daemon:
    #  -- Debian version
    #/etc/init.d/sendmail stop
    #/etc/init.d/sendmail start
    #  -- Slackware version
    /bin/ps ax | /usr/bin/grep sendmail | /usr/bin/grep -v grep >/tmp/xx
    while read PID x; do
        if [ x$PID != "x" ]; then
	    kill $PID
        fi
    done </tmp/xx
    /usr/sbin/sendmail -bd -q10m

    # Now get rid of /tmp/xx
    /bin/rm -f /tmp/xx

fi # end of if [ x$NETWORK != x192.0.0.0 ]

# Tell everyone it's up
#echo "PPP link on interface $1 ($4<->$5) initiated" >/dev/console
$LOGGER "PPP link on interface $1 ($4->$5) initiated @ $CSpeed"

Frank


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-REQUEST@lists.debian.org . Trouble? e-mail to Bruce@Pixar.com


Reply to: