- Timestamp:
- Oct 18, 2013, 1:03:04 PM (11 years ago)
- Branches:
- master
- Children:
- 66e014b
- Parents:
- d262fc0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BOOK/bootscripts/common/network.xml
rd262fc0 rd92670c 18 18 <title>Creating Network Interface Configuration Files</title> 19 19 20 <para>Which interfaces are brought up and down by the network script 21 depends on the files and directories in the <filename 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 27 address(es), subnet masks, and so forth.</para> 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> 28 27 29 <para>The following command creates the <filename>network.conf</filename> 30 file for use by the entire system:</para> 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 31 32 <screen><userinput>cat > ${CLFS}/targetfs/etc/network.conf << "EOF" 33 <literal># /etc/network.conf 34 # Global Networking Configuration 35 # interface configuration is in /etc/network.d/ 32 <screen><userinput>mkdir -pv ${CLFS}/targetfs/etc/network/if-{post-{up,down},pre-{up,down},up,down}.d 33 mkdir -pv ${CLFS}/targetfs/usr/share/udhcpc 36 34 37 # set to yes to enable networking 38 NETWORKING=yes 39 40 # set to yes to set default route to gateway 41 USE_GATEWAY=no 42 43 # set to gateway IP address 44 GATEWAY=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> 35 cat > ${CLFS}/targetfs/etc/network/interfaces << "EOF" 36 <literal>auto eth0 37 iface eth0 inet dhcp</literal> 55 38 EOF</userinput></screen> 56 39 57 <para> The <envar>GATEWAY</envar> variable should contain the default58 gateway IP address, if one is present. If not, then comment outthe59 variable entirely.</para>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> 60 43 61 <para>The following command creates a sample <filename>interface.eth0</filename> 62 file for the <emphasis>eth0</emphasis> device:</para> 63 64 <screen><userinput>mkdir ${CLFS}/targetfs/etc/network.d && 65 cat > ${CLFS}/targetfs/etc/network.d/interface.eth0 << "EOF" 66 <literal># Network Interface Configuration 67 68 # network device name 69 INTERFACE=eth0 70 71 # set to yes to use DHCP instead of the settings below 72 DHCP=no 73 74 # IP address 75 IPADDRESS=192.168.1.2 76 77 # netmask 78 NETMASK=255.255.255.0 79 80 # broadcast address 81 BROADCAST=192.168.1.255</literal> 82 EOF</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> 99 100 </sect2> 101 102 <sect2 id="udhcpc.conf"> 103 <title>Creating the ${CLFS}/targetfs/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>cat > ${CLFS}/targetfs/etc/udhcpc.conf << "EOF" 44 <screen><userinput>cat > ${CLFS}/targetfs/usr/share/udhcpc/default.script << "EOF" 113 45 <literal>#!/bin/sh 114 46 # udhcpc Interface Configuration … … 119 51 120 52 RESOLV_CONF="/etc/resolv.conf" 121 RESOLV_BAK="/etc/resolv.bak"122 123 53 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" 124 54 [ -n "$subnet" ] && NETMASK="netmask $subnet" … … 126 56 case "$1" in 127 57 deconfig) 128 if [ -f "$RESOLV_BAK" ]; then129 mv "$RESOLV_BAK" "$RESOLV_CONF"130 fi131 58 /sbin/ifconfig $interface 0.0.0.0 132 59 ;; … … 145 72 fi 146 73 147 if [ ! -f "$RESOLV_BAK" ] && [ -f "$RESOLV_CONF" ]; then148 mv "$RESOLV_CONF" "$RESOLV_BAK"149 fi150 151 74 echo -n > $RESOLV_CONF 152 75 [ -n "$domain" ] && echo search $domain >> $RESOLV_CONF … … 160 83 </literal>EOF 161 84 162 chmod +x ${CLFS}/targetfs/etc/udhcpc.conf</userinput></screen> 163 164 </sect2> 165 166 <sect2 id="resolv.conf"> 167 <title>Creating the ${CLFS}/targetfs/etc/resolv.conf File</title> 168 169 <indexterm zone="resolv.conf"> 170 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary> 171 </indexterm> 172 173 <para>If the system is going to be connected to the Internet, it will 174 need some means of Domain Name Service (DNS) name resolution to 175 resolve Internet domain names to IP addresses, and vice versa. This is 176 best achieved by placing the IP address of the DNS server, available 177 from the ISP or network administrator, into 178 <filename>/etc/resolv.conf</filename>. Create the file by running the 179 following:</para> 180 181 <screen><userinput>cat > ${CLFS}/targetfs/etc/resolv.conf << "EOF" 182 <literal># Begin /etc/resolv.conf 183 184 domain <replaceable>[Your Domain Name]</replaceable> 185 nameserver <replaceable>[IP address of your primary nameserver]</replaceable> 186 nameserver <replaceable>[IP address of your secondary nameserver]</replaceable> 187 188 # End /etc/resolv.conf</literal> 189 EOF</userinput></screen> 190 191 <para>Replace <replaceable>[IP address of the nameserver]</replaceable> 192 with the IP address of the DNS most appropriate for the setup. There will 193 often be more than one entry (requirements demand secondary servers for 194 fallback capability). If you only need or want one DNS server, remove the 195 second <emphasis>nameserver</emphasis> line from the file. The IP address 196 may also be a router on the local network.</para> 85 chmod +x ${CLFS}/targetfs/usr/share/udhcpc/default.script</userinput></screen> 197 86 198 87 </sect2>
Note:
See TracChangeset
for help on using the changeset viewer.