Configuring dhcp for a client
Config files
/etc/sysconfig/network,
/etc/sysconfig/network-devices/ifup-eth0,
/etc/sysconfig/network-devices/ifdown-eth0,
/etc/sysconfig/networkdevices/ifconfig.eth0
Configuration Information
Note that we use eth0 as the interface
throughout these instructions. If you want to configure a different (or
more than one) interface, simply replace eth0
with the interface you wish to use.
These instructions will convert the configuration files from LFS
(a static configuration) to a DHCP configuration. Note that static and
DHCP interfaces can co-exist on a LFS system, only make the
alterations to those interfaces which need to support DHCP.
The first step is to remove the GATEWAY and GATEWAY_IF variables
from /etc/sysconfig/network. This should only be done
if the default interface you intend to use will be using DHCP and only
needs to be done once; regardless of how many interfaces you are setting
up.
cd /etc/sysconfig &&
cp network network.bak &&
sed "s/GATEWAY/# GATEWAY/" network.bak > network
Now you can create the appropriate ifconfig.eth0
file with the following commands (note that this will overwrite any
existing file):
cd /etc/sysconfig/network-devices &&
cat > ifconfig.eth0 << "EOF"
ONBOOT=yes
DHCP_PROG=<path to dhcp>
DHCP_START=<start parameters>
DHCP_STOP=<stop parameter>
EOF
Review the appropriate manpages for parameters; for example, the
stop parameter for dhcpcd is '-k', while the stop parameter for dhclient
is '-r'.
You then need to create DHCP specific scripts. First, the
ifup-eth0 script:
cat > ifup-eth0 << "EOF"
#!/bin/sh
source /etc/sysconfig/rc || exit
source $rc_functions || exit
source $network_devices/ifconfig.eth0 || exit
echo "Bringing up the eth0 interface..."
modprobe eth0
loadproc $DHCP_PROG $DHCP_START
EOF
Then the ifdown-eth0 script:
cat > ifdown-eth0 << "EOF"
#!/bin/sh
source /etc/sysconfig/rc || exit
source $rc_functions || exit
source $network_devices/ifconfig.eth0 || exit
echo "Bringing down the eth0 interface..."
$DHCP_PROG $DHCP_STOP
evaluate_retval
EOF
Finally, we need to make these scripts executable:
chmod 755 ifup-eth0 &&
chmod 755 ifdown-eth0