source: chapter07/network.xml@ 131c907

7.9-systemd
Last change on this file since 131c907 was 131c907, checked in by DJ Lucas <dj@…>, 8 years ago

Sync with trunk r10891, update to udev-1.10.6, update to systemd-228.

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

  • Property mode set to 100644
File size: 10.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-scripts-network">
9 <?dbhtml filename="network.html"?>
10
11 <title>General Network Configuration</title>
12
13 <indexterm zone="ch-scripts-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 defualt, and absolutely should not be disabled.</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 <note><para>Udev may assign network card interface names based
47 on system physical characteristics such as enp2s1. If you are
48 not sure what your interface name is, you can always run
49 <command>ip link</command> after you have booted your system.
50 </para></note>
51
52 <sect3 id="systemd-networkd-static">
53 <title>Static IP Configuration</title>
54
55 <para>The command below creates a basic configuration file for a
56 Static IP setup (using both systemd-networkd and
57 systemd-resolved):</para>
58
59<screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-eth0-static.network &lt;&lt; "EOF"
60<literal>[Match]
61Name=eth0
62
63[Network]
64Address=192.168.0.2/24
65Gateway=192.168.0.1
66DNS=192.168.0.1</literal>
67EOF</userinput></screen>
68
69 <para>Multiple DNS entries can be added if you have more than one DNS
70 server.</para>
71
72 </sect3>
73
74 <sect3 id="systemd-networkd-dhcp">
75 <title>DHCP Configuration</title>
76
77 <para>The command below creates a basic configuration file for an IPv4
78 DHCP setup:</para>
79
80<screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-eth0-dhcp.network &lt;&lt; "EOF"
81<literal>[Match]
82Name=eth0
83
84[Network]
85DHCP=ipv4</literal>
86EOF</userinput></screen>
87
88 </sect3>
89
90 </sect2>
91
92 <sect2 id="resolv.conf">
93 <title>Creating the /etc/resolv.conf File</title>
94
95 <indexterm zone="resolv.conf">
96 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
97 </indexterm>
98
99 <para>If the system is going to be connected to the Internet, it will
100 need some means of Domain Name Service (DNS) name resolution to
101 resolve Internet domain names to IP addresses, and vice versa. This is
102 best achieved by placing the IP address of the DNS server, available
103 from the ISP or network administrator, into
104 <filename>/etc/resolv.conf</filename>.</para>
105
106 <sect3 id="resolv-conf-systemd-resoloved">
107 <title>systemd-resolved Configuration</title>
108
109 <note><para>If using another means to configure your network
110 interfaces (ex: ppp, network-manager, etc.), or if using any type of
111 local resolver (ex: bind, dnsmasq, etc.), or any other software that
112 generates an <filename>/etc/resolv.conf</filename> (ex: resolvconf), the
113 <command>systemd-resolved</command> service should not be
114 used.</para></note>
115
116 <para>When using <command>systemd-resolved</command> for DNS
117 configuration, it is responsible for creating the
118 <filename>/etc/resolv.conf</filename> file, which is placed in a
119 non-standard location that is writable during early boot. In order to be
120 used by other components of the system, it is necessary to create a
121 symlink with the following command:</para>
122
123<screen><userinput>ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
124
125 <para>This is required if you are specifying DNS entries in <filename
126 class="extension">.network</filename> files or using the built in
127 DHCP client to obtain DNS addresses.</para>
128
129 </sect3>
130
131 <sect3 id="resolv-conf-static">
132 <title>Static resolv.conf Configuration</title>
133
134 <para>If a static <filename>/etc/resolv.conf</filename> is desired,
135 create it by running the following command:</para>
136
137<screen role="nodump"><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
138<literal># Begin /etc/resolv.conf
139
140domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
141nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
142nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
143
144# End /etc/resolv.conf</literal>
145EOF</userinput></screen>
146
147 <para>The <varname>domain</varname> statement can be omitted
148 or replaced with a <varname>search</varname> statement. See the man page
149 for resolv.conf for more details.</para>
150
151 <para>Replace
152 <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
153 with the IP address of the DNS most appropriate for the setup. There will
154 often be more than one entry (requirements demand secondary servers for
155 fallback capability). If you only need or want one DNS server, remove the
156 second <emphasis>nameserver</emphasis> line from the file. The IP address
157 may also be a router on the local network.</para>
158
159 <note><para>The Google Public IPv4 DNS addresses are
160 <parameter>8.8.8.8</parameter> and <parameter>8.8.4.4</parameter>
161 for IPv4, and <parameter>2001:4860:4860::8888</parameter> and
162 <parameter>2001:4860:4860::8844</parameter> for IPv6.</para></note>
163
164 </sect3>
165
166 </sect2>
167
168 <sect2 id="ch-scripts-hostname">
169 <title>Configuring the system hostname</title>
170
171 <indexterm zone="ch-scripts-hostname">
172 <primary sortas="d-hostname">hostname</primary>
173 <secondary>configuring</secondary>
174 </indexterm>
175
176 <para>During the boot process, the file <filename>/etc/hostname</filename>
177 is used for establishing the system's hostname.</para>
178
179 <para>Create the <filename>/etc/hostname</filename> file and enter a
180 hostname by running:</para>
181
182<screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
183
184 <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
185 name given to the computer. Do not enter the Fully Qualified Domain Name
186 (FQDN) here. That information is put in the
187 <filename>/etc/hosts</filename> file.</para>
188
189 </sect2>
190
191 <sect2 id="ch-scripts-hosts">
192 <title>Customizing the /etc/hosts File</title>
193
194 <indexterm zone="ch-scripts-hosts">
195 <primary sortas="e-/etc/hosts">/etc/hosts</primary>
196 </indexterm>
197
198 <indexterm zone="ch-scripts-hosts">
199 <primary sortas="d-localnet">localnet</primary>
200 <secondary>/etc/hosts</secondary>
201 </indexterm>
202
203 <indexterm zone="ch-scripts-hosts">
204 <primary sortas="d-network">network</primary>
205 <secondary>/etc/hosts</secondary>
206 </indexterm>
207
208 <para>Decide on the IP address, fully-qualified domain name (FQDN), and
209 possible aliases for use in the <filename>/etc/hosts</filename> file. The
210 syntax is:</para>
211
212<screen><literal>IP_address myhost.example.org aliases</literal></screen>
213
214 <para>Unless the computer is to be visible to the Internet (i.e., there is
215 a registered domain and a valid block of assigned IP addresses&mdash;most
216 users do not have this), make sure that the IP address is in the private
217 network IP address range. Valid ranges are:</para>
218
219<screen><literal>Private Network Address Range Normal Prefix
22010.0.0.1 - 10.255.255.254 8
221172.x.0.1 - 172.x.255.254 16
222192.168.y.1 - 192.168.y.254 24</literal></screen>
223
224 <para>x can be any number in the range 16-31. y can be any number in the
225 range 0-255.</para>
226
227 <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
228 this IP could be lfs.example.org.</para>
229
230 <para>Even if not using a network card, a valid FQDN is still required.
231 This is necessary for certain programs to operate correctly.</para>
232
233 <para>Create the <filename>/etc/hosts</filename> file by running:</para>
234
235<screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
236<literal># Begin /etc/hosts (network card version)
237
238127.0.0.1 localhost
239::1 localhost
240<replaceable>&lt;192.168.0.2&gt;</replaceable> <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
241
242# End /etc/hosts (network card version)</literal>
243EOF</userinput></screen>
244
245 <para>The <replaceable>&lt;192.168.0.2&gt;</replaceable> and
246 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> values need to be
247 changed for specific uses or requirements (if assigned an IP address by a
248 network/system administrator and the machine will be connected to an
249 existing network). The optional alias name(s) can be omitted.</para>
250
251 <para>If a network card is not going to be configured, create the
252 <filename>/etc/hosts</filename> file by running:</para>
253
254<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
255<literal># Begin /etc/hosts (no network card version)
256
257127.0.0.1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost
258::1 localhost
259
260# End /etc/hosts (no network card version)</literal>
261EOF</userinput></screen>
262
263 <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents the IPv6 loopback interface.</para>
264
265 </sect2>
266
267</sect1>
Note: See TracBrowser for help on using the repository browser.