source: clfs-embedded/BOOK/bootscripts/common/network.xml@ 99bb0b8

Last change on this file since 99bb0b8 was d92670c, checked in by Andrew Bradford <andrew@…>, 11 years ago

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.

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[a9e389d]1<?xml version="1.0" encoding="ISO-8859-1"?>
[bd48e48]2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
[a9e389d]4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="ch-scripts-network">
9 <?dbhtml filename="network.html"?>
10
11 <title>Configuring the network Script</title>
12
13 <indexterm zone="ch-scripts-network">
14 <primary sortas="d-network">network</primary>
15 <secondary>configuring</secondary></indexterm>
16
17 <sect2>
18 <title>Creating Network Interface Configuration Files</title>
19
[d92670c]20 <para>Which interfaces are brought up and down by the network utilities
21 depends on the files and directories in the
22 <filename class="directory">/etc/network</filename> directory. The
23 <filename>interfaces</filename> file should contain a
24 description of the interfaces, as done by Debian, and each of the
25 directories contain scripts for actions to perform on each type of network
26 event.</para>
27
28 <para>The following command creates the required directories and the
29 <filename>interfaces</filename> file, assuming DHCP will be used for
30 eth0:</para>
31
32<screen><userinput>mkdir -pv ${CLFS}/targetfs/etc/network/if-{post-{up,down},pre-{up,down},up,down}.d
33mkdir -pv ${CLFS}/targetfs/usr/share/udhcpc
34
35cat &gt; ${CLFS}/targetfs/etc/network/interfaces &lt;&lt; "EOF"
36<literal>auto eth0
37iface eth0 inet dhcp</literal>
[1d67150]38EOF</userinput></screen>
[a9e389d]39
[d92670c]40 <para>For DHCP to work properly with udhcpc, the BusyBox dhcp client, a
41 configuration script is needed. Create a simple script to assign the
42 provided DHCP address and update <filename>/etc/resolv.conf</filename>:</para>
[a9e389d]43
[d92670c]44<screen><userinput>cat &gt; ${CLFS}/targetfs/usr/share/udhcpc/default.script &lt;&lt; "EOF"
[423fe6b]45<literal>#!/bin/sh
46# udhcpc Interface Configuration
47# Based on http://lists.debian.org/debian-boot/2002/11/msg00500.html
48# udhcpc script edited by Tim Riker &lt;Tim@Rikers.org&gt;
49
50[ -z "$1" ] &amp;&amp; echo "Error: should be called from udhcpc" &amp;&amp; exit 1
51
52RESOLV_CONF="/etc/resolv.conf"
53[ -n "$broadcast" ] &amp;&amp; BROADCAST="broadcast $broadcast"
54[ -n "$subnet" ] &amp;&amp; NETMASK="netmask $subnet"
55
56case "$1" in
57 deconfig)
58 /sbin/ifconfig $interface 0.0.0.0
59 ;;
60
61 renew|bound)
62 /sbin/ifconfig $interface $ip $BROADCAST $NETMASK
63
64 if [ -n "$router" ] ; then
65 while route del default gw 0.0.0.0 dev $interface ; do
66 true
67 done
68
69 for i in $router ; do
70 route add default gw $i dev $interface
71 done
72 fi
73
74 echo -n &gt; $RESOLV_CONF
75 [ -n "$domain" ] &amp;&amp; echo search $domain &gt;&gt; $RESOLV_CONF
76 for i in $dns ; do
77 echo nameserver $i &gt;&gt; $RESOLV_CONF
78 done
79 ;;
80esac
81
82exit 0
83</literal>EOF
84
[d92670c]85chmod +x ${CLFS}/targetfs/usr/share/udhcpc/default.script</userinput></screen>
[a9e389d]86
87 </sect2>
88
89</sect1>
Note: See TracBrowser for help on using the repository browser.