source: chapter09/networkd.xml

trunk
Last change on this file was 9575382, checked in by Bruce Dubbs <bdubbs@…>, 2 months ago

Minor text changes

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