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

RE: PPP options for different providers - how ? (LONG Re:)



Sorry for being so late in getting this response out, but I was quite busy
and away from my machine last week, so here it is for anyone wants it.

In my situation I connect to two different ISP's.  pppconfig works great
for setting up the connection, but fails to handle /etc/hosts and
/etc/resolv.conf so I wrote a little perl script to be called by
ip-up/ip-down to take care of things.  Included in this message is perl
script and sample scripts for the ip-up.d and ip-down.d directories.  I
run a cache only nameserver on my machine while disconnected or connected
to ISP-1, when I am connected to ISP-2 I use their nameservers.  With this
setup I do have to modify the files in /etc/ppp/peers created by pppconfig
and make sure the ipparm option is included.  (I remember when pppd didn't
have that option and I had to figure out which ISP I was connected to by
examining the local IP address, ipparam is much nicer.)  So without
further ado here are my sample scripts and the mkhost.pl script.  Good
Luck and Have FUN!!!

D.L.

 - - - ip-up.d/00config-isp1
#!/bin/bash
#
# This script will set up our networking parameters for ISP-1.
#

# First bail out if this is not the connection to ISP-1!
if [ $PPP_IPPARAM != "ISP-1" ]; then
  exit 0
fi

# Use my handy-dandy mkhost.pl script to adjust /etc/hosts and resolv.conf
logger -p local2.info -t ip-up -i "Setting up network files for ISP-1"
/etc/ppp/mkhost.pl --ip=$PPP_LOCAL --domain=isp-1.com --name=`hostname` --nameserver=127.0.0.1

 - - - ip-up.d/00config-isp2
#!/bin/bash
#
# This script will set up our networking parameters for ISP-2.
#

# First bail out if this is not the connection to ISP-2!
if [ $PPP_IPPARAM != "ISP-2" ]; then
  exit 0
fi

# Use my handy-dandy mkhost.pl script to adjust /etc/hosts and resolv.conf
logger -p local2.info -t ip-up -i "Setting up network files for ISP-2"
/etc/ppp/mkhost.pl --ip=$PPP_LOCAL --domain=isp-2.com --name=`hostname` --nameserver=nnn.nnn.nnn.nnn --nameserver=nnn.nnn.nnn.nnn

 - - - ip-down.d/00config-restore
#!/bin/bash
#
# This script will restore us to a non-networking mode
#

logger -p local2.info -t ip-down -i "Restoring network config files"
/etc/ppp/mkhost.pl --ip=127.0.0.1 --name=`hostname` --domain=private.net --nameserver=127.0.0.1

 - - - /etc/ppp/mkhost.pl
#! /usr/bin/perl
#
# mkhost.pl
# David Lutz (lutzd@pobox.com)
#
# This program is free for everybody (in every sense of the word).
# Anybody can use/modify this program as they best see fit.
# Have Fun and don't blame me if it deletes your root file system.
#
# Auto-Generate /etc/hosts and /etc/resolv.conf from template files.
#  Maybe even update /etc/hostname and set hostname(1).
#
# required:
# --ip          ip address in dotted four
# --domain      domain name
# --name        short hostname
# --nameserver  ip address of nameserver, can be listed multiple times
#
# optional:
# --hostsfile   template file for /etc/hosts
# --resolvfile  template file for /etc/resolv.conf
#
# These files can contain the follow macros which will be expanded.
#  %%IPADDR%%  => --ip parameter
#  %%DOMAIN%%  => --domain parameter
#  %%NAME%%    => --name parameter
#  %%NSx%%     => the x'th --nameserver parameter
#
# If --hostsfile or --resolvfile is specified these templates will
# be used to auto-generate the output.
# /etc/hosts:
#   127.0.0.1    localhost
#   %%IPADDR%%   %%NAME%%.%%DOMAIN%%  %%NAME%%
#
# /etc/resolv.conf
#   domain       %%DOMAIN%%
#   nameserver   %%NS1%%
#   nameserver   %%NS2%%
#   nameserver   %%NS3%%
#
# When creating /etc/resolv.conf any line that expands to
#   nameserver   (null)
# will not be included in the output.  So you don't have to specify
# all three nameservers.
#

use Getopt::Long;

GetOptions(
	"ip=s"         => \$Opt_ip,
	"domain=s"     => \$Opt_domain,
	"name=s"       => \$Opt_name,
	"nameserver=s" => \@Opt_nameserver,
	"hostsfile=s"  => \$Opt_hostsfile,
	"resolvfile=s" => \$Opt_resolvfile,
	);

if( !defined $Opt_ip || !defined $Opt_domain ||
    !defined $Opt_name || !defined $Opt_nameserver[0] )
{
  die "You must specify ip, name, domain, and nameserver(s)";
}

open HOSTS, ">/etc/hosts" or
 die "I can't open /etc/hosts: $!";

open RESOLV, ">/etc/resolv.conf" or
 die "I can't open /etc/resolv.conf: $!";

# Work on /etc/hosts first
if( defined $Opt_hostsfile )
{
  open HOSTTMPL, "<$Opt_hostsfile" or
    die "I can't open $Opt_hostsfile: $!";

  while( <HOSTTMPL> )
  {
    s/%%IPADDR%%/$Opt_ip/g;
    s/%%DOMAIN%%/$Opt_domain/g;
    s/%%NAME%%/$Opt_name/g;
    s/%%NS(\d)%%/$Opt_nameserver[${1}-1]/g;

    print HOSTS $_;
  }
}
else
{
  print HOSTS <<"EOH";
127.0.0.1\tlocalhost
$Opt_ip\t$Opt_name.$Opt_domain $Opt_name
EOH
}

# Now lets do /etc/resolv.conf
if( defined $Opt_resolvfile )
{
  open RESOLVTMPL, "<$Opt_resolvfile" or
    die "I can't open $Opt_resolvfile: $!";

  while( <RESOLVTMPL> )
  {
    s/%%IPADDR%%/$Opt_ip/g;
    s/%%DOMAIN%%/$Opt_domain/g;
    s/%%NAME%%/$Opt_name/g;
    s/%%NS(\d)%%/$Opt_nameserver[${1}-1]/g;

    print RESOLV $_ unless /\s*nameserver\s*/i;
  }
}
else
{
  print RESOLV "domain\t$Opt_domain\n";
  foreach $NS (@Opt_nameserver)
  {
    print RESOLV "nameserver\t$NS\n";
  }
}

 - - -

/  David Lutz  ---  lutzd@pobox.com  ---  http://www.pobox.com/~lutzd  \
|  Those of you who think you know everything : KD6GNS   Portland, OR  |
\  are annoying those of us who really do.    : '97 Toyota Tacoma SR5  /


Reply to: