source: chapter07/networkd.xml@ d53fefa

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since d53fefa was c300794, checked in by Pierre Labastie <pieere@…>, 4 years ago

Update to upstream r11892

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

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