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">
8 <sect1 id="ch-scripts-network">
9 <?dbhtml filename="network.html"?>
11 <title>General Network Configuration</title>
13 <indexterm zone="ch-scripts-network">
14 <primary sortas="d-network">network</primary>
15 <secondary>configuring</secondary></indexterm>
17 <para>This section only applies if a network card is to be
21 <title>Network Interface Configuration Files</title>
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>
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>
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.
52 <sect3 id="systemd-networkd-static">
53 <title>Static IP Configuration</title>
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>
59 <screen role="nodump"><userinput>cat > /etc/systemd/network/10-eth0-static.network << "EOF"
64 Address=192.168.0.2/24
66 DNS=192.168.0.1</literal>
67 EOF</userinput></screen>
69 <para>Multiple DNS entries can be added if you have more than one DNS
74 <sect3 id="systemd-networkd-dhcp">
75 <title>DHCP Configuration</title>
77 <para>The command below creates a basic configuration file for an IPv4
80 <screen role="nodump"><userinput>cat > /etc/systemd/network/10-eth0-dhcp.network << "EOF"
86 EOF</userinput></screen>
92 <sect2 id="resolv.conf">
93 <title>Creating the /etc/resolv.conf File</title>
95 <indexterm zone="resolv.conf">
96 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
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>
106 <sect3 id="resolv-conf-systemd-resoloved">
107 <title>systemd-resolved Configuration</title>
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
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. Since version 226, the
119 symlink for <filename>/etc/resolv.conf</filename> is created by systemd
120 when needed, so no further configuration is necessary.</para>
124 <sect3 id="resolv-conf-static">
125 <title>Static resolv.conf Configuration</title>
127 <para>If a static <filename>/etc/resolv.conf</filename> is desired,
128 create it by running the following command:</para>
130 <screen role="nodump"><userinput>cat > /etc/resolv.conf << "EOF"
131 <literal># Begin /etc/resolv.conf
133 domain <replaceable><Your Domain Name></replaceable>
134 nameserver <replaceable><IP address of your primary nameserver></replaceable>
135 nameserver <replaceable><IP address of your secondary nameserver></replaceable>
137 # End /etc/resolv.conf</literal>
138 EOF</userinput></screen>
140 <para>The <varname>domain</varname> statement can be omitted
141 or replaced with a <varname>search</varname> statement. See the man page
142 for resolv.conf for more details.</para>
145 <replaceable><IP address of the nameserver></replaceable>
146 with the IP address of the DNS most appropriate for the setup. There will
147 often be more than one entry (requirements demand secondary servers for
148 fallback capability). If you only need or want one DNS server, remove the
149 second <emphasis>nameserver</emphasis> line from the file. The IP address
150 may also be a router on the local network.</para>
152 <note><para>The Google Public IPv4 DNS addresses are
153 <parameter>8.8.8.8</parameter> and <parameter>8.8.4.4</parameter>
154 for IPv4, and <parameter>2001:4860:4860::8888</parameter> and
155 <parameter>2001:4860:4860::8844</parameter> for IPv6.</para></note>
161 <sect2 id="ch-scripts-hostname">
162 <title>Configuring the system hostname</title>
164 <indexterm zone="ch-scripts-hostname">
165 <primary sortas="d-hostname">hostname</primary>
166 <secondary>configuring</secondary>
169 <para>During the boot process, the file <filename>/etc/hostname</filename>
170 is used for establishing the system's hostname.</para>
172 <para>Create the <filename>/etc/hostname</filename> file and enter a
173 hostname by running:</para>
175 <screen><userinput>echo "<replaceable><lfs></replaceable>" > /etc/hostname</userinput></screen>
177 <para><replaceable><lfs></replaceable> needs to be replaced with the
178 name given to the computer. Do not enter the Fully Qualified Domain Name
179 (FQDN) here. That information is put in the
180 <filename>/etc/hosts</filename> file.</para>
184 <sect2 id="ch-scripts-hosts">
185 <title>Customizing the /etc/hosts File</title>
187 <indexterm zone="ch-scripts-hosts">
188 <primary sortas="e-/etc/hosts">/etc/hosts</primary>
191 <indexterm zone="ch-scripts-hosts">
192 <primary sortas="d-localnet">localnet</primary>
193 <secondary>/etc/hosts</secondary>
196 <indexterm zone="ch-scripts-hosts">
197 <primary sortas="d-network">network</primary>
198 <secondary>/etc/hosts</secondary>
201 <para>Decide on the IP address, fully-qualified domain name (FQDN), and
202 possible aliases for use in the <filename>/etc/hosts</filename> file. The
205 <screen><literal>IP_address myhost.example.org aliases</literal></screen>
207 <para>Unless the computer is to be visible to the Internet (i.e., there is
208 a registered domain and a valid block of assigned IP addresses—most
209 users do not have this), make sure that the IP address is in the private
210 network IP address range. Valid ranges are:</para>
212 <screen><literal>Private Network Address Range Normal Prefix
213 10.0.0.1 - 10.255.255.254 8
214 172.x.0.1 - 172.x.255.254 16
215 192.168.y.1 - 192.168.y.254 24</literal></screen>
217 <para>x can be any number in the range 16-31. y can be any number in the
220 <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
221 this IP could be lfs.example.org.</para>
223 <para>Even if not using a network card, a valid FQDN is still required.
224 This is necessary for certain programs to operate correctly.</para>
226 <para>Create the <filename>/etc/hosts</filename> file by running:</para>
228 <screen><userinput>cat > /etc/hosts << "EOF"
229 <literal># Begin /etc/hosts (network card version)
233 <replaceable><192.168.0.2></replaceable> <replaceable><HOSTNAME.example.org></replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
235 # End /etc/hosts (network card version)</literal>
236 EOF</userinput></screen>
238 <para>The <replaceable><192.168.0.2></replaceable> and
239 <replaceable><HOSTNAME.example.org></replaceable> values need to be
240 changed for specific uses or requirements (if assigned an IP address by a
241 network/system administrator and the machine will be connected to an
242 existing network). The optional alias name(s) can be omitted.</para>
244 <para>If a network card is not going to be configured, create the
245 <filename>/etc/hosts</filename> file by running:</para>
247 <screen role="nodump"><userinput>cat > /etc/hosts << "EOF"
248 <literal># Begin /etc/hosts (no network card version)
250 127.0.0.1 <replaceable><HOSTNAME.example.org></replaceable> <replaceable><HOSTNAME></replaceable> localhost
253 # End /etc/hosts (no network card version)</literal>
254 EOF</userinput></screen>
256 <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents the IPv6 loopback interface.</para>