source: chapter09/networkd.xml@ 5f3777a

11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 bdubbs/gcc13 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng 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 5f3777a was 5f3777a, checked in by Xi Ruoyao <xry111@…>, 2 years ago

disable systemd-networkd-wait-online if ...

systemd-networkd won't be used for network configuration

  • Property mode set to 100644
File size: 14.5 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-config-network" revision="systemd">
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 <para>This section only applies if a network card is to be
18 configured.</para>
19
20 <sect2>
21 <title>Network Interface Configuration Files</title>
22
23 <para>Starting with version 209, systemd ships a network configuration
24 daemon called <command>systemd-networkd</command> which can be used for
25 basic network configuration. Additionally, since version 213, DNS name
26 resolution can be handled by <command>systemd-resolved</command> in place
27 of a static <filename>/etc/resolv.conf</filename> file. Both services are
28 enabled by default.</para>
29
30 <note>
31 <para>
32 If you will not use <command>systemd-networkd</command> for network
33 configuration (for example, when the system is not connected to
34 network, or you want to use another utility like NetworkManager
35 for network configuration), disable a service to prevent an error
36 message during boot:
37 </para>
38 <screen role='nodump'><userinput>systemctl disable systemd-networkd-wait-online</userinput></screen>
39 </note>
40
41 <para>Configuration files for <command>systemd-networkd</command> (and
42 <command>systemd-resolved</command>) can be placed in
43 <filename class="directory">/usr/lib/systemd/network</filename>
44 or <filename class="directory">/etc/systemd/network</filename>. Files in
45 <filename class="directory">/etc/systemd/network</filename> have a
46 higher priority than the ones in
47 <filename class="directory">/usr/lib/systemd/network</filename>.
48 There are three types of configuration files:
49 <filename class="extension">.link</filename>,
50 <filename class="extension">.netdev</filename> and
51 <filename class="extension">.network</filename> files. For detailed
52 descriptions and example contents of these configuration files, consult
53 the <filename>systemd-link(5)</filename>,
54 <filename>systemd-netdev(5)</filename> and
55 <filename>systemd-network(5)</filename> manual pages.</para>
56
57 <sect3 id="systemd-network-devices">
58 <title>Network Device Naming</title>
59
60 <para>
61 Udev normally assigns network card interface names based
62 on physical system characteristics such as enp2s1. If you are
63 not sure what your interface name is, you can always run
64 <command>ip link</command> after you have booted your system.
65 </para>
66
67 <note>
68 <para>The interface names depend on the implementation and
69 configuration of the udev daemon running on the system. The udev
70 daemon for LFS (<command>systemd-udevd</command>, installed in
71 <xref linkend="ch-system-systemd"/>) will not run unless the LFS
72 system is booted. So it's unreliable to determine the interface
73 names being used in LFS system by running those commands on the host
74 distro,
75 <emphasis>even though you are in the chroot environment</emphasis>.</para>
76 </note>
77
78 <para>
79 For most systems, there is only one network interface for
80 each type of connection. For example, the classic interface
81 name for a wired connection is eth0. A wireless connection
82 will usually have the name wifi0 or wlan0.
83 </para>
84
85 <para>
86 If you prefer to use the classic or customized network interface names,
87 there are three alternative ways to do that:</para>
88
89 <itemizedlist>
90 <listitem>
91 <para>
92 Mask udev's .link file for the default policy:
93<screen role="nodump"><userinput>ln -s /dev/null /etc/systemd/network/99-default.link</userinput></screen>
94 </para>
95 </listitem>
96
97 <listitem>
98 <para>
99 Create a manual naming scheme, for example by naming the
100 interfaces something like "internet0", "dmz0", or "lan0".
101 To do that, create .link files in /etc/systemd/network/ that
102 select an explicit name or a better naming scheme for your
103 network interfaces. For example:
104 </para>
105
106<screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-ether0.link &lt;&lt; "EOF"
107<literal>[Match]
108# Change the MAC address as appropriate for your network device
109MACAddress=12:34:45:78:90:AB
110
111[Link]
112Name=ether0</literal>
113EOF</userinput></screen>
114
115 <para>
116 See the man page systemd.link(5) for more information.
117 </para>
118 </listitem>
119
120 <listitem>
121 <para>
122 In /boot/grub/grub.cfg, pass the option net.ifnames=0 on the
123 kernel command line.
124 </para>
125 </listitem>
126 </itemizedlist>
127 </sect3>
128
129 <sect3 id="systemd-networkd-static">
130 <title>Static IP Configuration</title>
131
132 <para>The command below creates a basic configuration file for a
133 Static IP setup (using both systemd-networkd and
134 systemd-resolved):</para>
135<!-- jhalfs relies on the values for Name, Address, etc. If you want to change
136 them, please inform the jhalfs maintainer(s). -->
137<screen><userinput>cat &gt; /etc/systemd/network/10-eth-static.network &lt;&lt; "EOF"
138<literal>[Match]
139Name=<replaceable>&lt;network-device-name&gt;</replaceable>
140
141[Network]
142Address=192.168.0.2/24
143Gateway=192.168.0.1
144DNS=192.168.0.1
145Domains=<replaceable>&lt;Your Domain Name&gt;</replaceable></literal>
146EOF</userinput></screen>
147
148 <para>Multiple DNS entries can be added if you have more than one DNS
149 server. Do not include DNS or Domains entries if you intend to use a
150 static <filename>/etc/resolv.conf</filename> file.</para>
151
152 </sect3>
153
154 <sect3 id="systemd-networkd-dhcp">
155 <title>DHCP Configuration</title>
156
157 <para>The command below creates a basic configuration file for an IPv4
158 DHCP setup:</para>
159
160<screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-eth-dhcp.network &lt;&lt; "EOF"
161<literal>[Match]
162Name=&lt;network-device-name&gt;
163
164[Network]
165DHCP=ipv4
166
167[DHCP]
168UseDomains=true</literal>
169EOF</userinput></screen>
170
171 </sect3>
172
173 </sect2>
174
175 <sect2 id="resolv.conf">
176 <title>Creating the /etc/resolv.conf File</title>
177
178 <indexterm zone="resolv.conf">
179 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
180 </indexterm>
181
182 <para>If the system is going to be connected to the Internet, it will
183 need some means of Domain Name Service (DNS) name resolution to
184 resolve Internet domain names to IP addresses, and vice versa. This is
185 best achieved by placing the IP address of the DNS server, available
186 from the ISP or network administrator, into
187 <filename>/etc/resolv.conf</filename>.</para>
188
189 <sect3 id="resolv-conf-systemd-resolved">
190 <title>systemd-resolved Configuration</title>
191
192 <note><para>If using methods incompatible with systemd-resolved to
193 configure your network interfaces (ex: ppp, etc.), or if using any
194 type of local resolver (ex: bind, dnsmasq, unbound, etc.),
195 or any other software that generates an <filename>/etc/resolv.conf</filename>
196 (ex: a <command>resolvconf</command> program other than the one
197 provided by systemd), the <command>systemd-resolved</command> service
198 should not be used.</para>
199
200 <para>To disable systemd-resolved, issue the following command:</para>
201
202<screen role="nodump"><userinput>systemctl disable systemd-resolved</userinput></screen></note>
203
204 <para>When using <command>systemd-resolved</command> for DNS
205 configuration, it creates the file
206 <filename>/run/systemd/resolve/stub-resolv.conf</filename>.
207 And, if <filename>/etc/resolv.conf</filename> does not exist, it
208 will be created by <command>systemd-resolved</command> as a symlink to
209 <filename>/run/systemd/resolve/stub-resolv.conf</filename>. So it's
210 unnecessary to create a <filename>/etc/resolv.conf</filename>
211 manually.</para>
212 <!--Create a
213 symlink in <filename>/etc</filename> to use the generated file:</para>
214
215<screen><userinput>ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
216 At least in systemd-250, this file gets created on first bootup.
217 -->
218 </sect3>
219
220 <sect3 id="resolv-conf-static">
221 <title>Static resolv.conf Configuration</title>
222
223 <para>If a static <filename>/etc/resolv.conf</filename> is desired,
224 create it by running the following command:</para>
225
226<screen role="nodump"><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
227<literal># Begin /etc/resolv.conf
228
229domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
230nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
231nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
232
233# End /etc/resolv.conf</literal>
234EOF</userinput></screen>
235
236 <para>The <varname>domain</varname> statement can be omitted
237 or replaced with a <varname>search</varname> statement. See the man page
238 for resolv.conf for more details.</para>
239
240 <para>Replace
241 <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
242 with the IP address of the DNS server most appropriate for your setup.
243 There will often be more than one entry (requirements demand secondary
244 servers for fallback capability). If you only need or want one DNS server,
245 remove the second <emphasis>nameserver</emphasis> line from the file.
246 The IP address may also be a router on the local network. Another option
247 is to use the Google Public DNS service using the IP addresses below as
248 nameservers.</para>
249
250 <note><para>The Google Public IPv4 DNS addresses are
251 <parameter>8.8.8.8</parameter> and <parameter>8.8.4.4</parameter>
252 for IPv4, and <parameter>2001:4860:4860::8888</parameter> and
253 <parameter>2001:4860:4860::8844</parameter> for IPv6.</para></note>
254
255 </sect3>
256
257 </sect2>
258
259 <sect2 id="ch-config-hostname">
260 <title>Configuring the system hostname</title>
261
262 <indexterm zone="ch-config-hostname">
263 <primary sortas="d-hostname">hostname</primary>
264 <secondary>configuring</secondary>
265 </indexterm>
266
267 <para>During the boot process, the file <filename>/etc/hostname</filename>
268 is used for establishing the system's hostname.</para>
269
270 <para>Create the <filename>/etc/hostname</filename> file and enter a
271 hostname by running:</para>
272
273<screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
274
275 <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
276 name given to the computer. Do not enter the Fully Qualified Domain Name
277 (FQDN) here. That information is put in the
278 <filename>/etc/hosts</filename> file.</para>
279
280 </sect2>
281
282 <sect2 id="ch-config-hosts">
283 <title>Customizing the /etc/hosts File</title>
284
285 <indexterm zone="ch-config-hosts">
286 <primary sortas="e-/etc/hosts">/etc/hosts</primary>
287 </indexterm>
288
289 <indexterm zone="ch-config-hosts">
290 <primary sortas="d-localnet">localnet</primary>
291 <secondary>/etc/hosts</secondary>
292 </indexterm>
293
294 <indexterm zone="ch-config-hosts">
295 <primary sortas="d-network">network</primary>
296 <secondary>/etc/hosts</secondary>
297 </indexterm>
298
299 <para>Decide on a fully-qualified domain name (FQDN), and possible aliases
300 for use in the <filename>/etc/hosts</filename> file. If using static IP
301 addresses, you'll also need to decide on an IP address. The syntax
302 for a hosts file entry is:</para>
303
304<screen><literal>IP_address myhost.example.org aliases</literal></screen>
305
306 <para>Unless the computer is to be visible to the Internet (i.e., there is
307 a registered domain and a valid block of assigned IP addresses&mdash;most
308 users do not have this), make sure that the IP address is in the private
309 network IP address range. Valid ranges are:</para>
310
311<screen><literal>Private Network Address Range Normal Prefix
31210.0.0.1 - 10.255.255.254 8
313172.x.0.1 - 172.x.255.254 16
314192.168.y.1 - 192.168.y.254 24</literal></screen>
315
316 <para>x can be any number in the range 16-31. y can be any number in the
317 range 0-255.</para>
318
319 <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
320 this IP could be lfs.example.org.</para>
321
322 <para>Even if not using a network card, a valid FQDN is still required.
323 This is necessary for certain programs, such as MTAs, to operate properly.</para>
324
325<!--
326 <para>Create the /etc/hosts file using the following command:</para>
327
328<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
329<literal># Begin /etc/hosts
330
331127.0.0.1 localhost.localdomain localhost
332127.0.1.1 <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable>
333::1 localhost ip6-localhost ip6-loopback
334ff02::1 ip6-allnodes
335ff02::2 ip6-allrouters
336
337# End /etc/hosts</literal>
338EOF</userinput></screen>
339-->
340
341 <para>Create the <filename>/etc/hosts</filename> file using the following
342 command:</para>
343
344<screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
345<literal># Begin /etc/hosts
346
347127.0.0.1 localhost.localdomain localhost
348127.0.1.1 <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable>
349<replaceable>&lt;192.168.0.2&gt;</replaceable> <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
350::1 localhost ip6-localhost ip6-loopback
351ff02::1 ip6-allnodes
352ff02::2 ip6-allrouters
353
354# End /etc/hosts</literal>
355EOF</userinput></screen>
356
357 <para>The <replaceable>&lt;192.168.0.2&gt;</replaceable>,
358 <replaceable>&lt;FQDN&gt;</replaceable>, and
359 <replaceable>&lt;HOSTNAME&gt;</replaceable> values need to be
360 changed for specific uses or requirements (if assigned an IP address by a
361 network/system administrator and the machine will be connected to an
362 existing network). The optional alias name(s) can be omitted, and the
363 <replaceable>&lt;192.168.0.2&gt;</replaceable> line can be omitted if you
364 are using a connection configured with DHCP or IPv6 Autoconfiguration.</para>
365
366 <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents
367 the IPv6 loopback interface. 127.0.1.1 is a loopback entry reserved
368 specifically for the FQDN.</para>
369
370 </sect2>
371
372</sect1>
Note: See TracBrowser for help on using the repository browser.