 |
linux howto - fabio de lorenzo personal informations and experiences kernel modules and software
|
| View previous topic :: View next topic |
| Author |
Message |
root Site Admin
Joined: 27 Apr 2004 Posts: 156
|
Posted: Mon Jul 04, 2005 1:34 pm Post subject: ip-up parameters and example |
|
|
#!/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" |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|