source: chapter09/networkd.xml@ 0a75d62

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 0a75d62 was 0a75d62, checked in by Douglas R. Reno <renodr@…>, 10 months ago

Minor tweaks to systemd

  • Property mode set to 100644
File size: 13.7 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/resolv.conf</filename>.</para>
196 <!--Create a
197 symlink in <filename>/etc</filename> to use the generated file:</para>
198
199<screen><userinput>ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
200 At least in systemd-250, this file gets created on first bootup.
201 -->
202 </sect3>
203
204 <sect3 id="resolv-conf-static">
205 <title>Static resolv.conf Configuration</title>
206
207 <para>If a static <filename>/etc/resolv.conf</filename> is desired,
208 create it by running the following command:</para>
209
210<screen role="nodump"><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
211<literal># Begin /etc/resolv.conf
212
213domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
214nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
215nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
216
217# End /etc/resolv.conf</literal>
218EOF</userinput></screen>
219
220 <para>The <varname>domain</varname> statement can be omitted
221 or replaced with a <varname>search</varname> statement. See the man page
222 for resolv.conf for more details.</para>
223
224 <para>Replace
225 <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
226 with the IP address of the DNS server most appropriate for your setup.
227 There will often be more than one entry (requirements demand secondary
228 servers for fallback capability). If you only need or want one DNS server,
229 remove the second <emphasis>nameserver</emphasis> line from the file.
230 The IP address may also be a router on the local network. Another option
231 is to use the Google Public DNS service using the IP addresses below as
232 nameservers.</para>
233
234 <note><para>The Google Public IPv4 DNS addresses are
235 <parameter>8.8.8.8</parameter> and <parameter>8.8.4.4</parameter>
236 for IPv4, and <parameter>2001:4860:4860::8888</parameter> and
237 <parameter>2001:4860:4860::8844</parameter> for IPv6.</para></note>
238
239 </sect3>
240
241 </sect2>
242
243 <sect2 id="ch-config-hostname">
244 <title>Configuring the system hostname</title>
245
246 <indexterm zone="ch-config-hostname">
247 <primary sortas="d-hostname">hostname</primary>
248 <secondary>configuring</secondary>
249 </indexterm>
250
251 <para>During the boot process, the file <filename>/etc/hostname</filename>
252 is used for establishing the system's hostname.</para>
253
254 <para>Create the <filename>/etc/hostname</filename> file and enter a
255 hostname by running:</para>
256
257<screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
258
259 <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
260 name given to the computer. Do not enter the Fully Qualified Domain Name
261 (FQDN) here. That information is put in the
262 <filename>/etc/hosts</filename> file.</para>
263
264 </sect2>
265
266 <sect2 id="ch-config-hosts">
267 <title>Customizing the /etc/hosts File</title>
268
269 <indexterm zone="ch-config-hosts">
270 <primary sortas="e-/etc/hosts">/etc/hosts</primary>
271 </indexterm>
272
273 <indexterm zone="ch-config-hosts">
274 <primary sortas="d-localnet">localnet</primary>
275 <secondary>/etc/hosts</secondary>
276 </indexterm>
277
278 <indexterm zone="ch-config-hosts">
279 <primary sortas="d-network">network</primary>
280 <secondary>/etc/hosts</secondary>
281 </indexterm>
282
283 <para>Decide on a fully-qualified domain name (FQDN), and possible aliases
284 for use in the <filename>/etc/hosts</filename> file. If using static IP
285 addresses, you'll also need to decide on an IP address. The syntax
286 for a hosts file entry is:</para>
287
288<screen><literal>IP_address myhost.example.org aliases</literal></screen>
289
290 <para>Unless the computer is to be visible to the Internet (i.e., there is
291 a registered domain and a valid block of assigned IP addresses&mdash;most
292 users do not have this), make sure that the IP address is in the private
293 network IP address range. Valid ranges are:</para>
294
295<screen><literal>Private Network Address Range Normal Prefix
29610.0.0.1 - 10.255.255.254 8
297172.x.0.1 - 172.x.255.254 16
298192.168.y.1 - 192.168.y.254 24</literal></screen>
299
300 <para>x can be any number in the range 16-31. y can be any number in the
301 range 0-255.</para>
302
303 <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
304 this IP could be lfs.example.org.</para>
305
306 <para>Even if not using a network card, a valid FQDN is still required.
307 This is necessary for certain programs, such as MTAs, to operate properly.</para>
308
309<!--
310 <para>Create the /etc/hosts file using the following command:</para>
311
312<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
313<literal># Begin /etc/hosts
314
315127.0.0.1 localhost.localdomain localhost
316127.0.1.1 <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable>
317::1 localhost ip6-localhost ip6-loopback
318ff02::1 ip6-allnodes
319ff02::2 ip6-allrouters
320
321# End /etc/hosts</literal>
322EOF</userinput></screen>
323-->
324
325 <para>Create the <filename>/etc/hosts</filename> file using the following
326 command:</para>
327
328<screen><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<replaceable>&lt;192.168.0.2&gt;</replaceable> <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
334::1 localhost ip6-localhost ip6-loopback
335ff02::1 ip6-allnodes
336ff02::2 ip6-allrouters
337
338# End /etc/hosts</literal>
339EOF</userinput></screen>
340
341 <para>The <replaceable>&lt;192.168.0.2&gt;</replaceable>,
342 <replaceable>&lt;FQDN&gt;</replaceable>, and
343 <replaceable>&lt;HOSTNAME&gt;</replaceable> values need to be
344 changed for specific uses or requirements (if assigned an IP address by a
345 network/system administrator and the machine will be connected to an
346 existing network). The optional alias name(s) can be omitted, and the
347 <replaceable>&lt;192.168.0.2</replaceable> line can be omitted if you
348 are using a connection configured with DHCP or IPv6 Autoconfiguration.</para>
349
350 <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents
351 the IPv6 loopback interface. 127.0.1.1 is a loopback entry reserved
352 specifically for the FQDN.</para>
353
354 </sect2>
355
356</sect1>
Note: See TracBrowser for help on using the repository browser.