source: chapter09/networkd.xml@ 0d80918a

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 0d80918a was 360fdfca, checked in by Pierre Labastie <pierre.labastie@…>, 8 months ago

Fix punctuation in quotes, and quote signs

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