source: clfs-embedded/BOOK/bootscripts/common/network.xml@ 485885e

Last change on this file since 485885e was 423fe6b, checked in by Maarten Lankhorst <mlankhorst@…>, 15 years ago

add a udhcpc.conf script to make udhcpc actually useful

  • Property mode set to 100644
File size: 6.4 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
20 <para>Which interfaces are brought up and down by the network script
21 depends on the files and directories in the <filename
[1d67150]22 class="directory">/etc/network.d</filename> hierarchy.
23 This directory should contain a file for each interface to be
24 configured, such as <filename>interface.xyz</filename>, where
25 <quote>xyz</quote> is a network interface name. Inside this file we
26 would be defining the attributes to this interface, such as its IP
[a9e389d]27 address(es), subnet masks, and so forth.</para>
28
[1d67150]29 <para>The following command creates the <filename>network.conf</filename>
30 file for use by the entire system:</para>
[a9e389d]31
[de9651e]32<screen><userinput>cat &gt; ${CLFS}/etc/network.conf &lt;&lt; "EOF"
[1d67150]33<literal># /etc/network.conf
34# Global Networking Configuration
35# interface configuration is in /etc/network.d/
36
37# set to yes to enable networking
38NETWORKING=yes
[a9e389d]39
[1d67150]40# set to yes to set default route to gateway
41USE_GATEWAY=no
42
43# set to gateway IP address
[423fe6b]44GATEWAY=192.168.0.1
45
46# Interfaces to add to br0 bridge
47# Leave commented to not setup a network bridge
48# Substitute br0 for eth0 in the interface.eth0 sample below to bring up br0
49# instead
50# bcm47xx with vlans:
51#BRIDGE_INTERFACES="eth0.0 eth0.1 wlan0"
52# Other access point with a wired eth0 and a wireless wlan0 interface:
53#BRIDGE_INTERFACES="eth0 wlan0"
54</literal>
[1d67150]55EOF</userinput></screen>
[a9e389d]56
57 <para>The <envar>GATEWAY</envar> variable should contain the default
58 gateway IP address, if one is present. If not, then comment out the
59 variable entirely.</para>
60
[1d67150]61 <para>The following command creates a sample <filename>interface.eth0</filename>
62 file for the <emphasis>eth0</emphasis> device:</para>
63
[de9651e]64<screen><userinput>mkdir ${CLFS}/etc/network.d &amp;&amp;
65cat &gt; ${CLFS}/etc/network.d/interface.eth0 &lt;&lt; "EOF"
[1d67150]66<literal># Network Interface Configuration
67
68# network device name
69INTERFACE=eth0
70
71# set to yes to use DHCP instead of the settings below
72DHCP=no
73
74# IP address
75IPADDRESS=192.168.1.2
76
77# netmask
78NETMASK=255.255.255.0
79
80# broadcast address
81BROADCAST=192.168.1.255</literal>
82EOF</userinput></screen>
83
84 <para>The <envar>INTERFACE</envar> variable should contain the name of
85 the interface interface.</para>
86
87 <para>The <envar>DHCP</envar> variable if set to yes will allow you to
88 use dhcp. If set to no, you will need to configure the rest of the options.</para>
89
90 <para>The <envar>IPADDRESS</envar> variable should contain the default
91 IP address for this interface.</para>
92
93 <para>The <envar>NETMASK</envar> variable should contain the default
94 Subnet Mask for the IP address for this interface.</para>
95
96 <para>The <envar>BROADCAST</envar> variable should contain the default
97 Broadcast Address for the Subnet Mask of the IP Range being used on
98 this interface.</para>
[a9e389d]99
100 </sect2>
101
[423fe6b]102 <sect2 id="udhcpc.conf">
103 <title>Creating the ${CLFS}/etc/udhcpc.conf File</title>
104
105 <indexterm zone="udhcpc.conf">
106 <primary sortas="e-/etc/udhcpc.conf">/etc/udhcpc.conf</primary>
107 </indexterm>
108
109 <para>For DHCP to work properly a configuration script is needed.
110 Create a sample udhcpc.conf:</para>
111
112<screen><userinput>mkdir ${CLFS}/etc/network.d &amp;&amp;
113cat &gt; ${CLFS}/etc/network.d/interface.eth0 &lt;&lt; "EOF"
114<literal>#!/bin/sh
115# udhcpc Interface Configuration
116# Based on http://lists.debian.org/debian-boot/2002/11/msg00500.html
117# udhcpc script edited by Tim Riker &lt;Tim@Rikers.org&gt;
118
119[ -z "$1" ] &amp;&amp; echo "Error: should be called from udhcpc" &amp;&amp; exit 1
120
121RESOLV_CONF="/etc/resolv.conf"
122RESOLV_BAK="/etc/resolv.bak"
123
124[ -n "$broadcast" ] &amp;&amp; BROADCAST="broadcast $broadcast"
125[ -n "$subnet" ] &amp;&amp; NETMASK="netmask $subnet"
126
127case "$1" in
128 deconfig)
129 if [ -f "$RESOLV_BAK" ]; then
130 mv "$RESOLV_BAK" "$RESOLV_CONF"
131 fi
132 /sbin/ifconfig $interface 0.0.0.0
133 ;;
134
135 renew|bound)
136 /sbin/ifconfig $interface $ip $BROADCAST $NETMASK
137
138 if [ -n "$router" ] ; then
139 while route del default gw 0.0.0.0 dev $interface ; do
140 true
141 done
142
143 for i in $router ; do
144 route add default gw $i dev $interface
145 done
146 fi
147
148 if [ ! -f "$RESOLV_BAK" ] &amp;&amp; [ -f "$RESOLV_CONF" ]; then
149 mv "$RESOLV_CONF" "$RESOLV_BAK"
150 fi
151
152 echo -n &gt; $RESOLV_CONF
153 [ -n "$domain" ] &amp;&amp; echo search $domain &gt;&gt; $RESOLV_CONF
154 for i in $dns ; do
155 echo nameserver $i &gt;&gt; $RESOLV_CONF
156 done
157 ;;
158esac
159
160exit 0
161</literal>EOF
162
163chmod +x ${CLFS}/etc/udhcpc.conf</userinput></screen>
164
165 </sect2>
166
[a9e389d]167 <sect2 id="resolv.conf">
[de9651e]168 <title>Creating the ${CLFS}/etc/resolv.conf File</title>
[a9e389d]169
170 <indexterm zone="resolv.conf">
171 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
172 </indexterm>
173
174 <para>If the system is going to be connected to the Internet, it will
175 need some means of Domain Name Service (DNS) name resolution to
176 resolve Internet domain names to IP addresses, and vice versa. This is
177 best achieved by placing the IP address of the DNS server, available
178 from the ISP or network administrator, into
179 <filename>/etc/resolv.conf</filename>. Create the file by running the
180 following:</para>
181
[de9651e]182<screen><userinput>cat &gt; ${CLFS}/etc/resolv.conf &lt;&lt; "EOF"
[a9e389d]183<literal># Begin /etc/resolv.conf
184
185domain <replaceable>[Your Domain Name]</replaceable>
186nameserver <replaceable>[IP address of your primary nameserver]</replaceable>
187nameserver <replaceable>[IP address of your secondary nameserver]</replaceable>
188
189# End /etc/resolv.conf</literal>
190EOF</userinput></screen>
191
192 <para>Replace <replaceable>[IP address of the nameserver]</replaceable>
193 with the IP address of the DNS most appropriate for the setup. There will
194 often be more than one entry (requirements demand secondary servers for
195 fallback capability). If you only need or want one DNS server, remove the
196 second <emphasis>nameserver</emphasis> line from the file. The IP address
197 may also be a router on the local network.</para>
198
199 </sect2>
200
201</sect1>
Note: See TracBrowser for help on using the repository browser.