source: chapter09/networkd.xml@ d79ba5b

11.1 11.1-rc1 11.2 11.2-rc1 arm multilib s6-init trunk xry111/arm64 xry111/clfs-ng xry111/lfs-next xry111/pip3 xry111/queue-11.3 xry111/rust-wip-20221008
Last change on this file since d79ba5b was d79ba5b, checked in by Xi Ruoyao <xry111@…>, 10 months ago

systemd network config: slightly reword about resolv.conf

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