source: chapter09/networkd.xml@ 1966b8d

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 1966b8d was 1966b8d, checked in by Xi Ruoyao <xry111@…>, 10 months ago

network cfg: mention that LFS and the host may name interfaces differently

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