1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
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-scripts-network">
|
---|
9 | <?dbhtml filename="network.html"?>
|
---|
10 |
|
---|
11 | <title>General Network Configuration</title>
|
---|
12 |
|
---|
13 | <indexterm zone="ch-scripts-network">
|
---|
14 | <primary sortas="d-network">network</primary>
|
---|
15 | <secondary>configuring</secondary></indexterm>
|
---|
16 |
|
---|
17 | <para>This section only applies if a network card is to be
|
---|
18 | configured.</para>
|
---|
19 |
|
---|
20 | <para>If a network card will not be used, there is likely no need to create
|
---|
21 | any configuration files relating to network cards. If that is the case, you
|
---|
22 | will need to remove the <filename class="symlink">network</filename> symlinks
|
---|
23 | from all run-level directories (<filename
|
---|
24 | class="directory">/etc/rc.d/rc*.d</filename>) after the bootscripts are
|
---|
25 | installed in <xref linkend="ch-scripts-bootscripts"/>.</para>
|
---|
26 |
|
---|
27 | <sect2>
|
---|
28 | <title>Creating Network Interface Configuration Files</title>
|
---|
29 |
|
---|
30 | <para>Which interfaces are brought up and down by the network script
|
---|
31 | usually depends on the files in <filename
|
---|
32 | class="directory">/etc/sysconfig/</filename>. This directory should
|
---|
33 | contain a file for each interface to be configured, such as
|
---|
34 | <filename>ifconfig.xyz</filename>, where <quote>xyz</quote> is required to
|
---|
35 | be a Network Card Interface name (e.g. eth0). Inside this file are
|
---|
36 | attributes to this interface, such as its IP address(es), subnet masks, and
|
---|
37 | so forth. It is necessary that the stem of the filename be
|
---|
38 | <emphasis>ifconfig</emphasis>.</para>
|
---|
39 |
|
---|
40 | <note><para>If the procedure in the previous section was not used, Udev
|
---|
41 | will assign network card interface names based on system physical
|
---|
42 | characteristics such as enp2s1. If you are not sure what your interface
|
---|
43 | name is, you can always run <command>ip link</command> after you have
|
---|
44 | booted your system. Again, it is important that ifconfig.xyz is named
|
---|
45 | after correct network card interface name (e.g. ifconfig.enp2s1 or
|
---|
46 | ifconfig.eth0) or your network interface will not be initialized during
|
---|
47 | the boot process.</para></note>
|
---|
48 |
|
---|
49 | <para>The following command creates a sample file for the
|
---|
50 | <emphasis>eth0</emphasis> device with a static IP address:</para>
|
---|
51 |
|
---|
52 | <screen><userinput>cd /etc/sysconfig/
|
---|
53 | cat > ifconfig.eth0 << "EOF"
|
---|
54 | <literal>ONBOOT=yes
|
---|
55 | IFACE=eth0
|
---|
56 | SERVICE=ipv4-static
|
---|
57 | IP=192.168.1.2
|
---|
58 | GATEWAY=192.168.1.1
|
---|
59 | PREFIX=24
|
---|
60 | BROADCAST=192.168.1.255</literal>
|
---|
61 | EOF</userinput></screen>
|
---|
62 |
|
---|
63 | <para>The values of these variables must be changed in every file to match
|
---|
64 | the proper setup.</para>
|
---|
65 |
|
---|
66 | <para>If the <envar>ONBOOT</envar> variable is set to <quote>yes</quote> the
|
---|
67 | System V network script will bring up the Network Interface Card (NIC) during
|
---|
68 | booting of the system. If set to anything but <quote>yes</quote> the NIC
|
---|
69 | will be ignored by the network script and not be automatically brought up.
|
---|
70 | The interface can be manually started or stopped with the
|
---|
71 | <command>ifup</command> and <command>ifdown</command> commands.</para>
|
---|
72 |
|
---|
73 | <para>The <envar>IFACE</envar> variable defines the interface name,
|
---|
74 | for example, eth0. It is required for all network device configuration
|
---|
75 | files. </para>
|
---|
76 |
|
---|
77 | <para>The <envar>SERVICE</envar> variable defines the method used for
|
---|
78 | obtaining the IP address. The LFS-Bootscripts package has a modular IP
|
---|
79 | assignment format, and creating additional files in the <filename
|
---|
80 | class="directory">/lib/services/</filename> directory allows other IP
|
---|
81 | assignment methods. This is commonly used for Dynamic Host Configuration
|
---|
82 | Protocol (DHCP), which is addressed in the BLFS book.</para>
|
---|
83 |
|
---|
84 | <para>The <envar>GATEWAY</envar> variable should contain the default
|
---|
85 | gateway IP address, if one is present. If not, then comment out the
|
---|
86 | variable entirely.</para>
|
---|
87 |
|
---|
88 | <para>The <envar>PREFIX</envar> variable contains the number of
|
---|
89 | bits used in the subnet. Each octet in an IP address is 8 bits. If the
|
---|
90 | subnet's netmask is 255.255.255.0, then it is using the first three octets
|
---|
91 | (24 bits) to specify the network number. If the netmask is 255.255.255.240,
|
---|
92 | it would be using the first 28 bits. Prefixes longer than 24 bits are
|
---|
93 | commonly used by DSL and cable-based Internet Service Providers (ISPs).
|
---|
94 | In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
|
---|
95 | <envar>PREFIX</envar> variable according to your specific subnet.
|
---|
96 | If omitted, the PREFIX defaults to 24.</para>
|
---|
97 |
|
---|
98 | <para>For more information see the <command>ifup</command> man page.</para>
|
---|
99 |
|
---|
100 | </sect2>
|
---|
101 | <!--
|
---|
102 | <sect2 id="systemd-net-enable">
|
---|
103 | <title>Configuring the Network Interface Card at boot (systemd)</title>
|
---|
104 |
|
---|
105 | <para>Enabling of the network interface card configuration
|
---|
106 | in systemd is done per interface. To enable network interface card
|
---|
107 | configuration at boot, run:</para>
|
---|
108 |
|
---|
109 | <screen><userinput>systemctl enable ifupdown@eth0</userinput></screen>
|
---|
110 |
|
---|
111 | <para>To disable a previously enabled network interface
|
---|
112 | card configuration at boot, run:</para>
|
---|
113 |
|
---|
114 | <screen role="nodump"><userinput>systemctl disable ifupdown@eth0</userinput></screen>
|
---|
115 |
|
---|
116 | <para>To manually start the network interface card configuration,
|
---|
117 | run:</para>
|
---|
118 |
|
---|
119 | <screen role="nodump"><userinput>systemctl start ifupdown@eth0</userinput></screen>
|
---|
120 |
|
---|
121 | <para>Replace eth0 with the correct network interface card
|
---|
122 | name as described on the beginning of this page.</para>
|
---|
123 |
|
---|
124 | <note><para>These procedures require the configuration files as specified
|
---|
125 | in the previous section.</para></note>
|
---|
126 |
|
---|
127 | <note><para>The network card can also be started or stopped
|
---|
128 | with the traditional <command>ifup <device></command> or
|
---|
129 | <command>ifdown <device></command> commands.</para></note>
|
---|
130 |
|
---|
131 | </sect2>
|
---|
132 |
|
---|
133 | <sect2 id="systemd2-net-enable">
|
---|
134 | <title>Configuring the Network Interface Card for systemd-networkd</title>
|
---|
135 |
|
---|
136 | <para>An alternative way to configure a NIC when booting with with
|
---|
137 | systemd is to create a configuration file recognized by the
|
---|
138 | systemd-networkd daemon. To configure the device create a file similar
|
---|
139 | to this:</para>
|
---|
140 |
|
---|
141 | <screen role="nodump"><userinput>cat > /etc/systemd/network/10-static-eth0.network << "EOF"
|
---|
142 | [Match]
|
---|
143 | Name=eth0
|
---|
144 |
|
---|
145 | [Network]
|
---|
146 | Address=192.168.0.2/24
|
---|
147 | Gateway=192.168.0.1
|
---|
148 | EOF</userinput></screen>
|
---|
149 |
|
---|
150 | <para>You can use multiple .network files if desired. You can also specify
|
---|
151 | DHCP=yes instead of the Address and Gateway settings. See the man page for
|
---|
152 | systemd.network for more details,</para>
|
---|
153 |
|
---|
154 | <note><para>If this method is used, be sure to disable ifupdown@eth0 as
|
---|
155 | described in the previous section (if it was enabled).</para></note>
|
---|
156 |
|
---|
157 | </sect2>
|
---|
158 | -->
|
---|
159 | <sect2 id="resolv.conf">
|
---|
160 | <title>Creating the /etc/resolv.conf File</title>
|
---|
161 |
|
---|
162 | <indexterm zone="resolv.conf">
|
---|
163 | <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
|
---|
164 | </indexterm>
|
---|
165 |
|
---|
166 | <para>If the system is going to be connected to the Internet, it will
|
---|
167 | need some means of Domain Name Service (DNS) name resolution to
|
---|
168 | resolve Internet domain names to IP addresses, and vice versa. This is
|
---|
169 | best achieved by placing the IP address of the DNS server, available
|
---|
170 | from the ISP or network administrator, into
|
---|
171 | <filename>/etc/resolv.conf</filename>. Create the file by running the
|
---|
172 | following:</para>
|
---|
173 |
|
---|
174 | <screen><userinput>cat > /etc/resolv.conf << "EOF"
|
---|
175 | <literal># Begin /etc/resolv.conf
|
---|
176 |
|
---|
177 | domain <replaceable><Your Domain Name></replaceable>
|
---|
178 | nameserver <replaceable><IP address of your primary nameserver></replaceable>
|
---|
179 | nameserver <replaceable><IP address of your secondary nameserver></replaceable>
|
---|
180 |
|
---|
181 | # End /etc/resolv.conf</literal>
|
---|
182 | EOF</userinput></screen>
|
---|
183 |
|
---|
184 | <para>The <varname>domain</varname> statement can be omitted
|
---|
185 | or replaced with a <varname>search</varname> statement. See the man page for
|
---|
186 | resolv.conf for more details.</para>
|
---|
187 |
|
---|
188 | <para>Replace <replaceable><IP address of the nameserver></replaceable>
|
---|
189 | with the IP address of the DNS most appropriate for the setup. There will
|
---|
190 | often be more than one entry (requirements demand secondary servers for
|
---|
191 | fallback capability). If you only need or want one DNS server, remove the
|
---|
192 | second <emphasis>nameserver</emphasis> line from the file. The IP address
|
---|
193 | may also be a router on the local network.</para>
|
---|
194 |
|
---|
195 | <note><para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para></note>
|
---|
196 |
|
---|
197 | </sect2>
|
---|
198 |
|
---|
199 | <sect2 id="ch-scripts-hostname">
|
---|
200 | <title>Configuring the system hostname</title>
|
---|
201 |
|
---|
202 | <indexterm zone="ch-scripts-hostname">
|
---|
203 | <primary sortas="d-hostname">hostname</primary>
|
---|
204 | <secondary>configuring</secondary>
|
---|
205 | </indexterm>
|
---|
206 |
|
---|
207 | <para>During the boot process, the file <filename>/etc/hostname</filename>
|
---|
208 | is used for establishing the system's hostname.</para>
|
---|
209 |
|
---|
210 | <para>Create the <filename>/etc/hostname</filename> file and enter a
|
---|
211 | hostname by running:</para>
|
---|
212 |
|
---|
213 | <screen><userinput>echo "<replaceable><lfs></replaceable>" > /etc/hostname</userinput></screen>
|
---|
214 |
|
---|
215 | <para><replaceable><lfs></replaceable> needs to be replaced with the
|
---|
216 | name given to the computer. Do not enter the Fully Qualified Domain Name
|
---|
217 | (FQDN) here. That information is put in the
|
---|
218 | <filename>/etc/hosts</filename> file.</para>
|
---|
219 |
|
---|
220 | </sect2>
|
---|
221 |
|
---|
222 | <sect2 id="ch-scripts-hosts">
|
---|
223 | <title>Customizing the /etc/hosts File</title>
|
---|
224 |
|
---|
225 | <indexterm zone="ch-scripts-hosts">
|
---|
226 | <primary sortas="e-/etc/hosts">/etc/hosts</primary>
|
---|
227 | </indexterm>
|
---|
228 |
|
---|
229 | <indexterm zone="ch-scripts-hosts">
|
---|
230 | <primary sortas="d-localnet">localnet</primary>
|
---|
231 | <secondary>/etc/hosts</secondary>
|
---|
232 | </indexterm>
|
---|
233 |
|
---|
234 | <indexterm zone="ch-scripts-hosts">
|
---|
235 | <primary sortas="d-network">network</primary>
|
---|
236 | <secondary>/etc/hosts</secondary>
|
---|
237 | </indexterm>
|
---|
238 |
|
---|
239 | <para>Decide on the IP address, fully-qualified domain name (FQDN), and
|
---|
240 | possible aliases for use in the <filename>/etc/hosts</filename> file. The
|
---|
241 | syntax is:</para>
|
---|
242 |
|
---|
243 | <screen><literal>IP_address myhost.example.org aliases</literal></screen>
|
---|
244 |
|
---|
245 | <para>Unless the computer is to be visible to the Internet (i.e., there is
|
---|
246 | a registered domain and a valid block of assigned IP addresses—most
|
---|
247 | users do not have this), make sure that the IP address is in the private
|
---|
248 | network IP address range. Valid ranges are:</para>
|
---|
249 |
|
---|
250 | <screen><literal>Private Network Address Range Normal Prefix
|
---|
251 | 10.0.0.1 - 10.255.255.254 8
|
---|
252 | 172.x.0.1 - 172.x.255.254 16
|
---|
253 | 192.168.y.1 - 192.168.y.254 24</literal></screen>
|
---|
254 |
|
---|
255 | <para>x can be any number in the range 16-31. y can be any number in the
|
---|
256 | range 0-255.</para>
|
---|
257 |
|
---|
258 | <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
|
---|
259 | this IP could be lfs.example.org.</para>
|
---|
260 |
|
---|
261 | <para>Even if not using a network card, a valid FQDN is still required.
|
---|
262 | This is necessary for certain programs to operate correctly.</para>
|
---|
263 |
|
---|
264 | <para>Create the <filename>/etc/hosts</filename> file by running:</para>
|
---|
265 |
|
---|
266 | <screen><userinput>cat > /etc/hosts << "EOF"
|
---|
267 | <literal># Begin /etc/hosts (network card version)
|
---|
268 |
|
---|
269 | 127.0.0.1 localhost
|
---|
270 | <replaceable><192.168.1.1></replaceable> <replaceable><HOSTNAME.example.org></replaceable> <replaceable>[alias1] [alias2 ...]</replaceable>
|
---|
271 |
|
---|
272 | # End /etc/hosts (network card version)</literal>
|
---|
273 | EOF</userinput></screen>
|
---|
274 |
|
---|
275 | <para>The <replaceable><192.168.1.1></replaceable> and
|
---|
276 | <replaceable><HOSTNAME.example.org></replaceable> values need to be
|
---|
277 | changed for specific uses or requirements (if assigned an IP address by a
|
---|
278 | network/system administrator and the machine will be connected to an
|
---|
279 | existing network). The optional alias name(s) can be omitted.</para>
|
---|
280 |
|
---|
281 | <para>If a network card is not going to be configured, create the
|
---|
282 | <filename>/etc/hosts</filename> file by running:</para>
|
---|
283 |
|
---|
284 | <screen role="nodump"><userinput>cat > /etc/hosts << "EOF"
|
---|
285 | <literal># Begin /etc/hosts (no network card version)
|
---|
286 |
|
---|
287 | 127.0.0.1 <replaceable><HOSTNAME.example.org></replaceable> <replaceable><HOSTNAME></replaceable> localhost
|
---|
288 |
|
---|
289 | # End /etc/hosts (no network card version)</literal>
|
---|
290 | EOF</userinput></screen>
|
---|
291 |
|
---|
292 | </sect2>
|
---|
293 |
|
---|
294 | </sect1>
|
---|