Re: Bit Twister: Is this the dhclient-exit-hooks you were talking about?
- From: Bit Twister <BitTwister@xxxxxxxxxxxxxxxx>
- Date: Fri, 22 Sep 2006 21:06:16 -0500
On Sat, 23 Sep 2006 00:43:08 +0000 (UTC), Ohmster wrote:
Hey Bit Twister,
I went looking at the google search you sent me on and found this script,
is this what you were suggesting that I run for my computer
That was a script I was running awhile back. This week has been spent
getting Mandriva 2007 Release Candiate 2 working on my firewall.
I have had to change hooks for the new ifcfg-eth0 formats.
and if so, where can I get a good copy of it without line wrap
issues that may be apparent from copying it from a google search?
Here is this weeks copy. Remember, the hooks script is for
whatever you want it to do. What I have done is for my setup.
#*******************************************************************
#*
#* dhclient-exit-hooks - Post processing dhcp client processor
#*
#* Updates /etc/sysconfig/network GATEWAY=new gateway ip address
#* /etc/hosts gets host ip address
#* /etc/resolv.conf has search/domain line removed.
#* and if postix resolv.conf exits, gets new resolv.conf
#* and /etc/hosts file if they differ.
#*
#* This script is called from /sbin/dhclient-script.
#* The variables: exit_status, reason, interface, and new*
#* are set in /sbin/dhclient-script.
#*
#*
#* NOTE:
#* You need to set _lan_nic to your's (eth0, eth1,..)
#*
#*
#* Install:
#* chmod +x dhclient-exit-hooks
#* cp dhclient-exit-hooks /etc/dhclient-exit-hooks
#*
#*
#*******************************************************************
_lan_nic=eth0
if [ $exit_status -eq 0 ] ; then
case $reason in
BOUND|RENEW|REBIND|REBOOT)
#******** change GATEWAY IP in /etc/sysconfig/network ******
_in_fn=/etc/sysconfig/network
_tmp_fn=/tmp/network
/bin/grep -v "GATEWAY=" $_in_fn > $_tmp_fn
/bin/echo "GATEWAY=$new_routers" >> $_tmp_fn
/usr/bin/cmp -s $_tmp_fn $_in_fn
if [ $? -ne 0 ] ; then
/bin/cp $_tmp_fn $_in_fn
fi
#******** change GATEWAY IP in ifcfg-$_lan_nic ******
_in_fn=/etc/sysconfig/network-scripts/ifcfg-$_lan_nic
_tmp_fn=/tmp/ifcfg
_count=$(/bin/grep --count "GATEWAY=" $_in_fn )
if [ $_count -gt 0 ] ; then
/bin/grep -v "GATEWAY=" $_in_fn > $_tmp_fn
/bin/echo "GATEWAY=$new_routers" >> $_tmp_fn
/bin/cp $_tmp_fn $_in_fn
if [ $? -ne 0 ] ; then
/bin/cp $_tmp_fn $_in_fn
fi
fi
#******** change NS_DNSx IPs in ifcfg-$_lan_nic ******
_in_fn=/etc/sysconfig/network-scripts/ifcfg-$_lan_nic
_tmp_fn=/tmp/ifcfg
_count=$(/bin/grep --count "MS_DNS" $_in_fn )
if [ $_count -gt 0 ] ; then
/bin/grep -v "MS_DNS" $_in_fn > $_tmp_fn
_count=0
for d in $new_domain_name_servers ; do
_count=$(( $_count + 1))
/bin/echo "MS_DNS${_count}=$d" >> $_tmp_fn
done
/bin/cp $_tmp_fn $_in_fn
if [ $? -ne 0 ] ; then
/bin/cp $_tmp_fn $_in_fn
fi
fi
#******** strip out search/domain line in /etc/resolv.conf ******
/bin/grep -iv search /etc/resolv.conf \
| /bin/grep -iv domain > /tmp/resolv.conf
/bin/echo "nameserver 66.93.87.2" >> /tmp/resolv.conf
/usr/bin/cmp -s /tmp/resolv.conf /etc/resolv.conf
if [ $? -ne 0 ] ; then
/bin/cp /tmp/resolv.conf /etc/resolv.conf
fi
#********* update postfix with new conf files ****************
if [ -e /var/spool/postfix/etc/resolv.conf ] ; then
/usr/bin/cmp -s /etc/resolv.conf /var/spool/postfix/etc/resolv.conf
if [ $? -ne 0 ] ; then
/bin/cp /etc/resolv.conf /var/spool/postfix/etc/resolv.conf
fi
/usr/bin/cmp -s /etc/hosts /var/spool/postfix/etc/hosts
if [ $? -ne 0 ] ; then
/bin/cp /etc/hosts /var/spool/postfix/etc/hosts
fi
fi
#********* update shorewall files ****************
#******************************************************
#* Strip PATH from dhcp.env
#******************************************************
env | sort | grep -v "bin" | sed "s/ /,/g" > /tmp/dhcp.env
chmod 755 /tmp/dhcp.env
/site/bin/update_shorewall $interface
esac
fi
/bin/true
#************* end /etc/dhclient-exit-hooks **************************
I want my hostname to be ohmster.com so will this script not allow me to
do that?
You change the script to do what you want it to do.
Where can I instert my wgets call to bring up my wgets text file
to update my domain IP addresses?
if [ $exit_status -eq 0 ] ; then
if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
[ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
-------- Your code here. ------
fi
fi
Or new and improved
if [ $exit_status -eq 0 ] ; then
case $reason in
BOUND|RENEW|REBIND|REBOOT)
-------- Your code here. ------
esac
fi
What is this script for, where did it come from?
That script used to change the ip address in /etc/hosts file
setting my ISP gateway in /network and changing values
in /etc/shorewall/params file.
The params file is read by the firewall manager shorewall.
Out of my head.
.
- Follow-Ups:
- References:
- Prev by Date: Re: Can I use /etc/dhclient-exit-hooks to run an IP updater?
- Next by Date: Ubuntu and Gnome=>KDE?
- Previous by thread: Bit Twister: Is this the dhclient-exit-hooks you were talking about?
- Next by thread: Re: Bit Twister: Is this the dhclient-exit-hooks you were talking about?
- Index(es):
Relevant Pages
|