Files
Andrew Bradford d92670cff5 network: Create simple DHCP client config
Using udhcpc and eth0, on 'ifup eth0' obtain an IP address via DHCP and
assign it properly to eth0.
2013-10-18 16:03:04 -04:00

90 lines
2.8 KiB
XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % general-entities SYSTEM "../../general.ent">
%general-entities;
]>
<sect1 id="ch-scripts-network">
<?dbhtml filename="network.html"?>
<title>Configuring the network Script</title>
<indexterm zone="ch-scripts-network">
<primary sortas="d-network">network</primary>
<secondary>configuring</secondary></indexterm>
<sect2>
<title>Creating Network Interface Configuration Files</title>
<para>Which interfaces are brought up and down by the network utilities
depends on the files and directories in the
<filename class="directory">/etc/network</filename> directory. The
<filename>interfaces</filename> file should contain a
description of the interfaces, as done by Debian, and each of the
directories contain scripts for actions to perform on each type of network
event.</para>
<para>The following command creates the required directories and the
<filename>interfaces</filename> file, assuming DHCP will be used for
eth0:</para>
<screen><userinput>mkdir -pv ${CLFS}/targetfs/etc/network/if-{post-{up,down},pre-{up,down},up,down}.d
mkdir -pv ${CLFS}/targetfs/usr/share/udhcpc
cat &gt; ${CLFS}/targetfs/etc/network/interfaces &lt;&lt; "EOF"
<literal>auto eth0
iface eth0 inet dhcp</literal>
EOF</userinput></screen>
<para>For DHCP to work properly with udhcpc, the BusyBox dhcp client, a
configuration script is needed. Create a simple script to assign the
provided DHCP address and update <filename>/etc/resolv.conf</filename>:</para>
<screen><userinput>cat &gt; ${CLFS}/targetfs/usr/share/udhcpc/default.script &lt;&lt; "EOF"
<literal>#!/bin/sh
# udhcpc Interface Configuration
# Based on http://lists.debian.org/debian-boot/2002/11/msg00500.html
# udhcpc script edited by Tim Riker &lt;Tim@Rikers.org&gt;
[ -z "$1" ] &amp;&amp; echo "Error: should be called from udhcpc" &amp;&amp; exit 1
RESOLV_CONF="/etc/resolv.conf"
[ -n "$broadcast" ] &amp;&amp; BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] &amp;&amp; NETMASK="netmask $subnet"
case "$1" in
deconfig)
/sbin/ifconfig $interface 0.0.0.0
;;
renew|bound)
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ] ; then
while route del default gw 0.0.0.0 dev $interface ; do
true
done
for i in $router ; do
route add default gw $i dev $interface
done
fi
echo -n &gt; $RESOLV_CONF
[ -n "$domain" ] &amp;&amp; echo search $domain &gt;&gt; $RESOLV_CONF
for i in $dns ; do
echo nameserver $i &gt;&gt; $RESOLV_CONF
done
;;
esac
exit 0
</literal>EOF
chmod +x ${CLFS}/targetfs/usr/share/udhcpc/default.script</userinput></screen>
</sect2>
</sect1>