source: chapter07/network.xml@ bf58c1e

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since bf58c1e was bf58c1e, checked in by Bruce Dubbs <bdubbs@…>, 10 years ago

Rewrite and reorganize Chapter 7.
Update systemd customization.

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@10542 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 12.0 KB
Line 
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/
53cat &gt; ifconfig.eth0 &lt;&lt; "EOF"
54<literal>ONBOOT=yes
55IFACE=eth0
56SERVICE=ipv4-static
57IP=192.168.1.2
58GATEWAY=192.168.1.1
59PREFIX=24
60BROADCAST=192.168.1.255</literal>
61EOF</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 configuartion 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 &lt;device&gt;</command> or
129 <command>ifdown &lt;device&gt;</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 &gt; /etc/systemd/network/10-static-eth0.network &lt;&lt; "EOF"
142[Match]
143Name=eth0
144
145[Network]
146Address=192.168.0.2/24
147Gateway=192.168.0.1
148EOF</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 </sect2>
155
156 <sect2 id="resolv.conf">
157 <title>Creating the /etc/resolv.conf File</title>
158
159 <indexterm zone="resolv.conf">
160 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
161 </indexterm>
162
163 <para>If the system is going to be connected to the Internet, it will
164 need some means of Domain Name Service (DNS) name resolution to
165 resolve Internet domain names to IP addresses, and vice versa. This is
166 best achieved by placing the IP address of the DNS server, available
167 from the ISP or network administrator, into
168 <filename>/etc/resolv.conf</filename>. Create the file by running the
169 following:</para>
170
171<screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
172<literal># Begin /etc/resolv.conf
173
174domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
175nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
176nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
177
178# End /etc/resolv.conf</literal>
179EOF</userinput></screen>
180
181 <para>The <varname>domain</varname> statement can be omitted
182 or replaced with a <varname>search</varname> statement. See the man page for
183 resolv.conf for more details.</para>
184
185 <para>Replace <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
186 with the IP address of the DNS most appropriate for the setup. There will
187 often be more than one entry (requirements demand secondary servers for
188 fallback capability). If you only need or want one DNS server, remove the
189 second <emphasis>nameserver</emphasis> line from the file. The IP address
190 may also be a router on the local network.</para>
191
192 <note><para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para></note>
193
194 </sect2>
195
196 <sect2 id="ch-scripts-hostname">
197 <title>Configuring the system hostname</title>
198
199 <indexterm zone="ch-scripts-hostname">
200 <primary sortas="d-hostname">hostname</primary>
201 <secondary>configuring</secondary>
202 </indexterm>
203
204 <para>During the boot process, both Systemd and System V use the same file
205 for establishing the system's hostname. This needs to be configured by
206 creating <filename>/etc/hostname</filename>.</para>
207
208 <para>Create the <filename>/etc/hostname</filename> file and enter a
209 hostname by running:</para>
210
211<screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
212
213 <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
214 name given to the computer. Do not enter the Fully Qualified Domain Name
215 (FQDN) here. That information is put in the
216 <filename>/etc/hosts</filename> file.</para>
217
218 </sect2>
219
220 <sect2 id="ch-scripts-hosts">
221 <title>Customizing the /etc/hosts File</title>
222
223 <indexterm zone="ch-scripts-hosts">
224 <primary sortas="e-/etc/hosts">/etc/hosts</primary>
225 </indexterm>
226
227 <indexterm zone="ch-scripts-hosts">
228 <primary sortas="d-localnet">localnet</primary>
229 <secondary>/etc/hosts</secondary>
230 </indexterm>
231
232 <indexterm zone="ch-scripts-hosts">
233 <primary sortas="d-network">network</primary>
234 <secondary>/etc/hosts</secondary>
235 </indexterm>
236
237 <para>Decide on the IP address, fully-qualified domain name (FQDN), and
238 possible aliases for use in the <filename>/etc/hosts</filename> file. The
239 syntax is:</para>
240
241<screen><literal>IP_address myhost.example.org aliases</literal></screen>
242
243 <para>Unless the computer is to be visible to the Internet (i.e., there is
244 a registered domain and a valid block of assigned IP addresses&mdash;most
245 users do not have this), make sure that the IP address is in the private
246 network IP address range. Valid ranges are:</para>
247
248<screen><literal>Private Network Address Range Normal Prefix
24910.0.0.1 - 10.255.255.254 8
250172.x.0.1 - 172.x.255.254 16
251192.168.y.1 - 192.168.y.254 24</literal></screen>
252
253 <para>x can be any number in the range 16-31. y can be any number in the
254 range 0-255.</para>
255
256 <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
257 this IP could be lfs.example.org.</para>
258
259 <para>Even if not using a network card, a valid FQDN is still required.
260 This is necessary for certain programs to operate correctly.</para>
261
262 <para>Create the <filename>/etc/hosts</filename> file by running:</para>
263
264<screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
265<literal># Begin /etc/hosts (network card version)
266
267127.0.0.1 localhost
268<replaceable>&lt;192.168.1.1&gt;</replaceable> <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>[alias1] [alias2 ...]</replaceable>
269
270# End /etc/hosts (network card version)</literal>
271EOF</userinput></screen>
272
273 <para>The <replaceable>&lt;192.168.1.1&gt;</replaceable> and
274 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> values need to be
275 changed for specific uses or requirements (if assigned an IP address by a
276 network/system administrator and the machine will be connected to an
277 existing network). The optional alias name(s) can be omitted.</para>
278
279 <para>If a network card is not going to be configured, create the
280 <filename>/etc/hosts</filename> file by running:</para>
281
282<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
283<literal># Begin /etc/hosts (no network card version)
284
285127.0.0.1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost
286
287# End /etc/hosts (no network card version)</literal>
288EOF</userinput></screen>
289
290 </sect2>
291
292</sect1>
Note: See TracBrowser for help on using the repository browser.