1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
4 | <!ENTITY % general-entities SYSTEM "../general.ent">
|
---|
5 | %general-entities;
|
---|
6 | ]>
|
---|
7 |
|
---|
8 | <sect1 id="ch-config-network" revision="sysv">
|
---|
9 | <?dbhtml filename="network.html"?>
|
---|
10 |
|
---|
11 | <title>General Network Configuration</title>
|
---|
12 |
|
---|
13 | <indexterm zone="ch-config-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>The files in <filename class="directory">/etc/sysconfig/</filename>
|
---|
21 | usually determine which interfaces are brought up and down by the network
|
---|
22 | script. This directory should
|
---|
23 | contain a file for each interface to be configured, such as
|
---|
24 | <filename>ifconfig.xyz</filename>, where <quote>xyz</quote> describes
|
---|
25 | the network card. The interface name (e.g. eth0) is usually appropriate.
|
---|
26 | Each file contains the attributes of one interface, such as its IP
|
---|
27 | address(es), subnet masks, and so forth. The stem of
|
---|
28 | the filename must be <emphasis>ifconfig</emphasis>.</para>
|
---|
29 |
|
---|
30 | <note>
|
---|
31 | <para>If the procedure in the previous section was not used, udev
|
---|
32 | will assign network card interface names based on system physical
|
---|
33 | characteristics such as enp2s1. If you are not sure what your interface
|
---|
34 | name is, you can always run <command>ip link</command> or <command>ls
|
---|
35 | /sys/class/net</command> after you have booted your system.
|
---|
36 | </para>
|
---|
37 |
|
---|
38 | <para>The interface names depend on the implementation and
|
---|
39 | configuration of the udev daemon running on the system. The udev
|
---|
40 | daemon for LFS (installed in <xref linkend="ch-system-udev"/>) will
|
---|
41 | not run until the LFS system is booted. So the interface names
|
---|
42 | in the LFS system cannot always be determined by running
|
---|
43 | those commands on the host distro,
|
---|
44 | <emphasis>even in the chroot environment</emphasis>.</para>
|
---|
45 | </note>
|
---|
46 |
|
---|
47 | <para>The following command creates a sample file for the
|
---|
48 | <emphasis>eth0</emphasis> device with a static IP address:</para>
|
---|
49 | <!-- jhalfs relies on the values for IFACE, IP, etc. If you want to change
|
---|
50 | them, please inform the jhalfs maintainer(s). -->
|
---|
51 | <screen><userinput>cd /etc/sysconfig/
|
---|
52 | cat > ifconfig.<replaceable>eth0</replaceable> << "EOF"
|
---|
53 | <literal>ONBOOT=<replaceable>yes</replaceable>
|
---|
54 | IFACE=<replaceable>eth0</replaceable>
|
---|
55 | SERVICE=<replaceable>ipv4-static</replaceable>
|
---|
56 | IP=<replaceable>192.168.1.2</replaceable>
|
---|
57 | GATEWAY=<replaceable>192.168.1.1</replaceable>
|
---|
58 | PREFIX=<replaceable>24</replaceable>
|
---|
59 | BROADCAST=<replaceable>192.168.1.255</replaceable></literal>
|
---|
60 | EOF</userinput></screen>
|
---|
61 |
|
---|
62 | <para>The values in italics must be changed in each file, to set
|
---|
63 | the interfaces up correctly.</para>
|
---|
64 |
|
---|
65 | <para>If the <envar>ONBOOT</envar> variable is set to <literal>yes</literal> the
|
---|
66 | System V network script will bring up the Network Interface Card (NIC) during
|
---|
67 | the system boot process. If set to anything besides <literal>yes</literal>, the NIC
|
---|
68 | will be ignored by the network script and will not be started automatically.
|
---|
69 | Interfaces can be manually started or stopped with the
|
---|
70 | <command>ifup</command> and <command>ifdown</command> commands.</para>
|
---|
71 |
|
---|
72 | <para>The <envar>IFACE</envar> variable defines the interface name,
|
---|
73 | for example, eth0. It is required for all network device configuration
|
---|
74 | files. The filename extension must match this value.</para>
|
---|
75 |
|
---|
76 | <para>The <envar>SERVICE</envar> variable defines the method used for
|
---|
77 | obtaining the IP address. The LFS-Bootscripts package has a modular IP
|
---|
78 | assignment format, and creating additional files in the <filename
|
---|
79 | class="directory">/lib/services/</filename> directory allows other IP
|
---|
80 | assignment methods. This is commonly used for Dynamic Host Configuration
|
---|
81 | Protocol (DHCP), which is addressed in the BLFS book.</para>
|
---|
82 |
|
---|
83 | <para>The <envar>GATEWAY</envar> variable should contain the default
|
---|
84 | gateway IP address, if one is present. If not, then comment out the
|
---|
85 | variable entirely.</para>
|
---|
86 |
|
---|
87 | <para>The <envar>PREFIX</envar> variable specifies the number of
|
---|
88 | bits used in the subnet. Each segment of an IP address is 8 bits. If the
|
---|
89 | subnet's netmask is 255.255.255.0, then it is using the first three segments
|
---|
90 | (24 bits) to specify the network number. If the netmask is 255.255.255.240,
|
---|
91 | the subnet is using the first 28 bits. Prefixes longer than 24 bits are
|
---|
92 | commonly used by DSL and cable-based Internet Service Providers (ISPs).
|
---|
93 | In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
|
---|
94 | <envar>PREFIX</envar> variable according to your specific subnet.
|
---|
95 | If omitted, the PREFIX defaults to 24.</para>
|
---|
96 |
|
---|
97 | <para>For more information see the <command>ifup</command> man page.</para>
|
---|
98 |
|
---|
99 | </sect2>
|
---|
100 | <sect2 id="resolv.conf">
|
---|
101 | <title>Creating the /etc/resolv.conf File</title>
|
---|
102 |
|
---|
103 | <indexterm zone="resolv.conf">
|
---|
104 | <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
|
---|
105 | </indexterm>
|
---|
106 |
|
---|
107 | <para>The system will need some means of obtaining Domain Name Service
|
---|
108 | (DNS) name resolution to resolve Internet domain names to IP addresses, and
|
---|
109 | vice versa. This is best achieved by placing the IP address of the DNS
|
---|
110 | server, available from the ISP or network administrator, into
|
---|
111 | <filename>/etc/resolv.conf</filename>. Create the file by running the
|
---|
112 | following:</para>
|
---|
113 |
|
---|
114 | <screen><userinput>cat > /etc/resolv.conf << "EOF"
|
---|
115 | <literal># Begin /etc/resolv.conf
|
---|
116 |
|
---|
117 | domain <replaceable><Your Domain Name></replaceable>
|
---|
118 | nameserver <replaceable><IP address of your primary nameserver></replaceable>
|
---|
119 | nameserver <replaceable><IP address of your secondary nameserver></replaceable>
|
---|
120 |
|
---|
121 | # End /etc/resolv.conf</literal>
|
---|
122 | EOF</userinput></screen>
|
---|
123 |
|
---|
124 | <para>The <varname>domain</varname> statement can be omitted
|
---|
125 | or replaced with a <varname>search</varname> statement. See the man page for
|
---|
126 | resolv.conf for more details.</para>
|
---|
127 |
|
---|
128 | <para>Replace <replaceable><IP address of the nameserver></replaceable>
|
---|
129 | with the IP address of the DNS most appropriate for the setup. There will
|
---|
130 | often be more than one entry (requirements demand secondary servers for
|
---|
131 | fallback capability). If you only need or want one DNS server, remove the
|
---|
132 | second <emphasis>nameserver</emphasis> line from the file. The IP address
|
---|
133 | may also be a router on the local network.</para>
|
---|
134 |
|
---|
135 | <note>
|
---|
136 | <para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para>
|
---|
137 | </note>
|
---|
138 |
|
---|
139 | </sect2>
|
---|
140 |
|
---|
141 | <sect2 id="ch-config-hostname">
|
---|
142 | <title>Configuring the System Hostname</title>
|
---|
143 |
|
---|
144 | <indexterm zone="ch-config-hostname">
|
---|
145 | <primary sortas="d-hostname">hostname</primary>
|
---|
146 | <secondary>configuring</secondary>
|
---|
147 | </indexterm>
|
---|
148 |
|
---|
149 | <para>During the boot process, the file <filename>/etc/hostname</filename>
|
---|
150 | is used for establishing the system's hostname.</para>
|
---|
151 |
|
---|
152 | <para>Create the <filename>/etc/hostname</filename> file and enter a
|
---|
153 | hostname by running:</para>
|
---|
154 |
|
---|
155 | <screen><userinput>echo "<replaceable><lfs></replaceable>" > /etc/hostname</userinput></screen>
|
---|
156 |
|
---|
157 | <para><replaceable><lfs></replaceable> needs to be replaced with the
|
---|
158 | name given to the computer. Do not enter the Fully Qualified Domain Name
|
---|
159 | (FQDN) here. That information goes in the
|
---|
160 | <filename>/etc/hosts</filename> file.</para>
|
---|
161 |
|
---|
162 | </sect2>
|
---|
163 |
|
---|
164 | <sect2 id="ch-config-hosts">
|
---|
165 | <title>Customizing the /etc/hosts File</title>
|
---|
166 |
|
---|
167 | <indexterm zone="ch-config-hosts">
|
---|
168 | <primary sortas="e-/etc/hosts">/etc/hosts</primary>
|
---|
169 | </indexterm>
|
---|
170 |
|
---|
171 | <indexterm zone="ch-config-hosts">
|
---|
172 | <primary sortas="d-localnet">localnet</primary>
|
---|
173 | <secondary>/etc/hosts</secondary>
|
---|
174 | </indexterm>
|
---|
175 |
|
---|
176 | <indexterm zone="ch-config-hosts">
|
---|
177 | <primary sortas="d-network">network</primary>
|
---|
178 | <secondary>/etc/hosts</secondary>
|
---|
179 | </indexterm>
|
---|
180 |
|
---|
181 | <para>Decide on a fully-qualified domain name (FQDN), and possible aliases
|
---|
182 | for use in the <filename>/etc/hosts</filename> file. If using static IP
|
---|
183 | addresses, you'll also need to decide on an IP address. The syntax
|
---|
184 | for a hosts file entry is:</para>
|
---|
185 |
|
---|
186 | <screen><literal>IP_address myhost.example.org aliases</literal></screen>
|
---|
187 |
|
---|
188 | <para>Unless the computer is to be visible to the Internet (i.e., there is
|
---|
189 | a registered domain and a valid block of assigned IP addresses—most
|
---|
190 | users do not have this), make sure that the IP address is in the private
|
---|
191 | network IP address range. Valid ranges are:</para>
|
---|
192 |
|
---|
193 | <screen><literal>Private Network Address Range Normal Prefix
|
---|
194 | 10.0.0.1 - 10.255.255.254 8
|
---|
195 | 172.x.0.1 - 172.x.255.254 16
|
---|
196 | 192.168.y.1 - 192.168.y.254 24</literal></screen>
|
---|
197 |
|
---|
198 | <para>x can be any number in the range 16-31. y can be any number in the
|
---|
199 | range 0-255.</para>
|
---|
200 |
|
---|
201 | <para>A valid private IP address could be 192.168.1.1.</para>
|
---|
202 |
|
---|
203 | <para>If the computer is to be visible to the Internet, a valid FQDN
|
---|
204 | can be the domain name itself, or a string resulted by concatenating a
|
---|
205 | prefix (often the hostname) and the domain name with a <quote>.</quote>
|
---|
206 | character. And, you need to contact the domain provider to resolve the
|
---|
207 | FQDN to your public IP address.</para>
|
---|
208 |
|
---|
209 | <para>Even if the computer is not visible to the Internet, a FQDN is
|
---|
210 | still needed for certain programs, such as MTAs, to operate properly.
|
---|
211 | A special FQDN, <literal>localhost.localdomain</literal>, can be used
|
---|
212 | for this purpose.</para>
|
---|
213 |
|
---|
214 | <para>Create the <filename>/etc/hosts</filename> file by running:</para>
|
---|
215 |
|
---|
216 | <screen><userinput>cat > /etc/hosts << "EOF"
|
---|
217 | <literal># Begin /etc/hosts
|
---|
218 |
|
---|
219 | 127.0.0.1 localhost.localdomain localhost
|
---|
220 | 127.0.1.1 <replaceable><FQDN></replaceable> <replaceable><HOSTNAME></replaceable>
|
---|
221 | <replaceable><192.168.1.1></replaceable> <replaceable><FQDN></replaceable> <replaceable><HOSTNAME></replaceable> <replaceable>[alias1] [alias2 ...]</replaceable>
|
---|
222 | ::1 localhost ip6-localhost ip6-loopback
|
---|
223 | ff02::1 ip6-allnodes
|
---|
224 | ff02::2 ip6-allrouters
|
---|
225 |
|
---|
226 | # End /etc/hosts</literal>
|
---|
227 | EOF</userinput></screen>
|
---|
228 |
|
---|
229 | <para>The <replaceable><192.168.1.1></replaceable>,
|
---|
230 | <replaceable><FQDN></replaceable>, and
|
---|
231 | <replaceable><HOSTNAME></replaceable> values need to be
|
---|
232 | changed for specific uses or requirements (if assigned an IP address by a
|
---|
233 | network/system administrator and the machine will be connected to an
|
---|
234 | existing network). The optional alias name(s) can be omitted.</para>
|
---|
235 |
|
---|
236 | <!-- This is not very useful
|
---|
237 |
|
---|
238 | <para>If a network card is not going to be configured, create the
|
---|
239 | <filename>/etc/hosts</filename> file by running:</para>
|
---|
240 |
|
---|
241 | <screen role="nodump"><userinput>cat > /etc/hosts << "EOF"
|
---|
242 | <literal># Begin /etc/hosts (no network card version)
|
---|
243 |
|
---|
244 | 127.0.0.1 localhost
|
---|
245 | 127.0.1.1 <replaceable><FQDN></replaceable> <replaceable><HOSTNAME></replaceable>
|
---|
246 | ::1 localhost ip6-localhost ip6-loopback
|
---|
247 | ff02::1 ip6-allnodes
|
---|
248 | ff02::2 ip6-allrouters
|
---|
249 |
|
---|
250 | # End /etc/hosts (no network card version)</literal>
|
---|
251 | EOF</userinput></screen> -->
|
---|
252 |
|
---|
253 | </sect2>
|
---|
254 |
|
---|
255 | </sect1>
|
---|