Changeset d92670c in clfs-embedded for BOOK


Ignore:
Timestamp:
Oct 18, 2013, 1:03:04 PM (11 years ago)
Author:
Andrew Bradford <andrew@…>
Branches:
master
Children:
66e014b
Parents:
d262fc0
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BOOK/bootscripts/common/network.xml

    rd262fc0 rd92670c  
    1818    <title>Creating Network Interface Configuration Files</title>
    1919
    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>
    2827
    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>
    3131
    32 <screen><userinput>cat &gt; ${CLFS}/targetfs/etc/network.conf &lt;&lt; "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
     33mkdir -pv ${CLFS}/targetfs/usr/share/udhcpc
    3634
    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>
     35cat &gt; ${CLFS}/targetfs/etc/network/interfaces &lt;&lt; "EOF"
     36<literal>auto eth0
     37iface eth0 inet dhcp</literal>
    5538EOF</userinput></screen>
    5639
    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>
     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>
    6043
    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 &amp;&amp;
    65 cat &gt; ${CLFS}/targetfs/etc/network.d/interface.eth0 &lt;&lt; "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 &gt; ${CLFS}/targetfs/etc/udhcpc.conf &lt;&lt; "EOF"
     44<screen><userinput>cat &gt; ${CLFS}/targetfs/usr/share/udhcpc/default.script &lt;&lt; "EOF"
    11345<literal>#!/bin/sh
    11446# udhcpc Interface Configuration
     
    11951
    12052RESOLV_CONF="/etc/resolv.conf"
    121 RESOLV_BAK="/etc/resolv.bak"
    122 
    12353[ -n "$broadcast" ] &amp;&amp; BROADCAST="broadcast $broadcast"
    12454[ -n "$subnet" ] &amp;&amp; NETMASK="netmask $subnet"
     
    12656case "$1" in
    12757        deconfig)
    128                 if [ -f "$RESOLV_BAK" ]; then
    129                         mv "$RESOLV_BAK" "$RESOLV_CONF"
    130                 fi
    13158                /sbin/ifconfig $interface 0.0.0.0
    13259                ;;
     
    14572                fi
    14673
    147                 if [ ! -f "$RESOLV_BAK" ] &amp;&amp; [ -f "$RESOLV_CONF" ]; then
    148                         mv "$RESOLV_CONF" "$RESOLV_BAK"
    149                 fi
    150 
    15174                echo -n &gt; $RESOLV_CONF
    15275                [ -n "$domain" ] &amp;&amp; echo search $domain &gt;&gt; $RESOLV_CONF
     
    16083</literal>EOF
    16184
    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 &gt; ${CLFS}/targetfs/etc/resolv.conf &lt;&lt; "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>
     85chmod +x ${CLFS}/targetfs/usr/share/udhcpc/default.script</userinput></screen>
    19786
    19887  </sect2>
Note: See TracChangeset for help on using the changeset viewer.