source: chapter09/networkd.xml@ ea93c11

12.1 12.1-rc1 12.2 12.2-rc1 multilib trunk xry111/arm64 xry111/clfs-ng xry111/loongarch xry111/loongarch-12.1 xry111/loongarch-12.2 xry111/mips64el xry111/multilib xry111/update-glibc
Last change on this file since ea93c11 was ea93c11, checked in by Xi Ruoyao <xry111@…>, 8 months ago

treewide: Use <ulink> instead of <filename> for man pages

"gcc(1)" is really not a file name.

Use <ulink> and link to the online man page on
https://man.archlinux.org/ so the user can refer to the man pages more
easily.

The change is done via a sed command and long lines are wrapped
manually.

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