1 | <sect1 id="dhcpclient" xreflabel="Configuring the LFS bootscripts to support DHCP clients">
|
---|
2 | <?dbhtml filename="configdhcp.html" dir="connect"?>
|
---|
3 | <title>Configuring the LFS bootscripts to support DHCP clients</title>
|
---|
4 |
|
---|
5 | <sect2><title>Config files</title>
|
---|
6 | <para><filename>/etc/sysconfig/network</filename>,
|
---|
7 | <filename>/etc/sysconfig/network-devices/ifup-eth0</filename>,
|
---|
8 | <filename>/etc/sysconfig/network-devices/ifdown-eth0</filename>,
|
---|
9 | <filename>/etc/sysconfig/network-devices/ifconfig.eth0</filename></para>
|
---|
10 | </sect2>
|
---|
11 |
|
---|
12 | <sect2><title>Configuration Information</title>
|
---|
13 |
|
---|
14 | <para>Note that on this and the following pages, we
|
---|
15 | use <userinput>eth0</userinput> as the example interface.
|
---|
16 | If you want to configure a different (or more than one) interface, simply
|
---|
17 | replace <userinput>eth0</userinput> with the interface you wish to use.</para>
|
---|
18 |
|
---|
19 | <para>These instructions will convert the configuration files from LFS
|
---|
20 | (a static configuration) to a configuration using the DHCP protocol.
|
---|
21 | Note that static and DHCP-based interfaces can co-exist on a LFS system. To
|
---|
22 | do this, you should only make the alterations to those interfaces which
|
---|
23 | need to support DHCP. All of the instructions on this page are applicable
|
---|
24 | no matter which DHCP client you intend to use.</para>
|
---|
25 |
|
---|
26 | <para>If the interface you intend to use as your default gateway is going to
|
---|
27 | use DHCP, the first step is to remove the <envar>GATEWAY</envar> and
|
---|
28 | <envar>GATEWAY_IF</envar> variables
|
---|
29 | from <filename>/etc/sysconfig/network</filename>. This will only need to be
|
---|
30 | done once.</para>
|
---|
31 |
|
---|
32 | <para><screen><userinput>cd /etc/sysconfig &&
|
---|
33 | cp network network.bak &&
|
---|
34 | sed "s/GATEWAY/# GATEWAY/" network.bak > network</userinput></screen></para>
|
---|
35 |
|
---|
36 | <para>You then need to create scripts which will override the default
|
---|
37 | network scripts and provide DHCP support. These two scripts are generic and
|
---|
38 | so for use with both DHCP clients. First, the
|
---|
39 | <filename>ifup-eth0</filename> script:</para>
|
---|
40 |
|
---|
41 | <para><screen><userinput>cat > /etc/sysconfig/network-devices/ifup-eth0 << "EOF" </userinput>
|
---|
42 | #!/bin/sh
|
---|
43 |
|
---|
44 | source /etc/sysconfig/rc || exit
|
---|
45 | source $rc_functions || exit
|
---|
46 | source $network_devices/ifconfig.eth0 || exit
|
---|
47 |
|
---|
48 | echo "Bringing up the eth0 interface..."
|
---|
49 | modprobe eth0
|
---|
50 | loadproc $DHCP_PROG $DHCP_START
|
---|
51 |
|
---|
52 | echo "Setting up the /etc/hosts file..."
|
---|
53 | if [ $(basename $DHCP_PROG) == "dhcpcd" ]
|
---|
54 | then
|
---|
55 | source /var/lib/dhcpc/dhcpcd-eth0.info
|
---|
56 |
|
---|
57 | else
|
---|
58 | if [ $(basename $DHCP_PROG) == "dhclient" ]
|
---|
59 | then
|
---|
60 | IPADDR=$(sed -n 's/;//;/fixed-address/s/.* //p' \
|
---|
61 | /var/state/dhcp/dhclient.leases |tail -n1)
|
---|
62 |
|
---|
63 | else
|
---|
64 | IPADDR=999.999.999.999
|
---|
65 | fi
|
---|
66 |
|
---|
67 | fi
|
---|
68 |
|
---|
69 | sed "s/0.0.0.0/$IPADDR/" \
|
---|
70 | /etc/sysconfig/network-devices/hosts.dhcp > /etc/hosts
|
---|
71 | evaluate_retval
|
---|
72 |
|
---|
73 | <userinput>EOF</userinput></screen></para>
|
---|
74 |
|
---|
75 | <para>Then the <filename>ifdown-eth0</filename> script:</para>
|
---|
76 |
|
---|
77 | <para><screen><userinput>cat > /etc/sysconfig/network-devices/ifdown-eth0 << "EOF" </userinput>
|
---|
78 | #!/bin/sh
|
---|
79 |
|
---|
80 | source /etc/sysconfig/rc || exit
|
---|
81 | source $rc_functions || exit
|
---|
82 | source $network_devices/ifconfig.eth0 || exit
|
---|
83 |
|
---|
84 | echo "Bringing down the eth0 interface..."
|
---|
85 | $DHCP_PROG $DHCP_STOP
|
---|
86 | evaluate_retval
|
---|
87 | <userinput>EOF</userinput></screen></para>
|
---|
88 |
|
---|
89 | <para>Next, we need to make these scripts executable:</para>
|
---|
90 |
|
---|
91 | <para><screen><userinput>chmod 755 /etc/sysconfig/network-devices/ifup-eth0 &&
|
---|
92 | chmod 755 /etc/sysconfig/network-devices/ifdown-eth0</userinput></screen></para>
|
---|
93 |
|
---|
94 | <para>Make a backup copy of your /etc/hosts file and one to source for the scripts:</para>
|
---|
95 |
|
---|
96 | <para><screen><userinput>cp /etc/hosts /etc/hosts.bak &&
|
---|
97 | cp /etc/hosts /etc/sysconfig/network-devices/hosts.dhcp</userinput></screen></para>
|
---|
98 |
|
---|
99 | <para>Finally, edit the <userinput>/etc/sysconfig/network-devices/hosts.dhcp</userinput>, and replace
|
---|
100 | the existing IP address associated with the FQDN with <userinput>0.0.0.0</userinput>.</para>
|
---|
101 |
|
---|
102 | </sect2>
|
---|
103 |
|
---|
104 | </sect1>
|
---|
105 |
|
---|