Suggested Change: dhcp client_S_ and /etc/hosts

DJ Lucas dj at lucasit.com
Tue May 20 01:10:50 PDT 2003


DJ Lucas wrote:

 >
 > I just love repling to my own posts it seems :-)

Still holds true here!

 >
 > ifup-eth0 creation should be:
 >
----------------------------------------------------------------
cat > /etc/sysconfig/network-devices/ifup-eth0 << "EOF"
#!/bin/sh
# Begin network-devices/ifup-eth0

source /etc/sysconfig/rc || exit
source $rc_functions || exit
source $network_devices/ifconfig.eth0 || exit

echo "Bringing up the eth0 interface..."
modprobe eth0
$DHCP_PROG $DHCP_START

echo "Seting up the /etc/hosts file..."
if [ $(basename $DHCP_PROG) == "dhcpcd" ]
then
     source /var/lib/dhcpc/dhcpcd-eth0.info
     sed "s/0.0.0.0/$IPADDR/" \
     /etc/sysconfig/network-devices/hosts.dhcp > /etc/hosts
     evaluate_retval
else
     if [ $(basename $DHCP_PROG) == "dhclient" ]
     then
         IPADDR=$(sed -n 's/;//;/fixed-address/s/.* //p' \
             /var/state/dhcp/dhclient.leases |tail -n1)
         sed "s/0.0.0.0/$IPADDR/" \
             /etc/sysconfig/network-devices/hosts.dhcp > /etc/hosts
         evaluate_retval
     else
         exit 1 > /dev/null
         evaluate_retval
     fi
fi

# End network-device/ifup-eth0
EOF
chmod 0755 /etc/sysconfig/network-devices/ifup-eth0
-------------------------------------------------------------------

Next we instruct the user to make a backup of /etc/hosts and make a copy 
to edit for use with the bootscripts.

-------------------------------------------------------------------
cp /etc/hosts /etc/hosts.bak &&
cp /etc/hosts /etc/sysconfig/network-devices/hosts.dhcp
-------------------------------------------------------------------

Now we have the user edit the ~/network-devices/hosts.dhcp.  Have the 
end-user remove his/her own IP from the FQDN entry and replace it with 
0.0.0.0" then run 'ifconfig eth0 down', and '/etc/rc.d/init.d/network 
start'.

The big sed in the dhclient testcase was provided by Timothy.  I really 
don't have a complete understanding of it.  I have one that is easier to 
understand (step by step grep|tail|sed|sed) if it'd be better for the 
book, but his looks much cleaner and kewler :)  See on blfs support 
'scripting help'.  Anyways, I think I've caught all the possible 
pitfalls, but needs testing if anyone would like to.

Thanks,

DJ

-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe blfs-dev' in the subject header of the message



More information about the blfs-dev mailing list