source: chapter09/networkd.xml@ 4234aea6

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 ml-11.0 multilib trunk xry111/git-transition xry111/glibc-2.34 xry111/tester-nohack xry111/usr-move
Last change on this file since 4234aea6 was 4234aea6, checked in by Douglas R. Reno <renodr@…>, 18 months ago

Fix the /etc/hosts file on systemd

git-svn-id: http://svn.linuxfromscratch.org/LFS/branches/cross2@11930 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

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