[1118b17] | 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 |
|
---|
[afcfd74] | 8 | <sect1 id="ch-config-network" revision="systemd">
|
---|
[1118b17] | 9 | <?dbhtml filename="network.html"?>
|
---|
| 10 |
|
---|
| 11 | <title>General Network Configuration</title>
|
---|
| 12 |
|
---|
[afcfd74] | 13 | <indexterm zone="ch-config-network">
|
---|
[1118b17] | 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
|
---|
[e053117] | 28 | enabled by default.</para>
|
---|
[1118b17] | 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 |
|
---|
[94e3e7bd] | 46 | <sect3 id="systemd-network-devices">
|
---|
| 47 | <title>Network Device Naming</title>
|
---|
| 48 |
|
---|
| 49 | <para>
|
---|
| 50 | Udev normally assigns network card interface names based
|
---|
[9e7475a] | 51 | on physical system characteristics such as enp2s1. If you are
|
---|
[94e3e7bd] | 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".
|
---|
[9e7475a] | 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:
|
---|
[94e3e7bd] | 82 | </para>
|
---|
| 83 |
|
---|
| 84 | <screen role="nodump"><userinput>cat > /etc/systemd/network/10-ether0.link << "EOF"
|
---|
| 85 | <literal>[Match]
|
---|
| 86 | # Change the MAC address as appropriate for your network device
|
---|
| 87 | MACAddress=12:34:45:78:90:AB
|
---|
| 88 |
|
---|
| 89 | [Link]
|
---|
| 90 | Name=ether0</literal>
|
---|
| 91 | EOF</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>
|
---|
[1118b17] | 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>
|
---|
[8154126] | 113 | <!-- jhalfs relies on the values for Name, Address, etc. If you want to change
|
---|
[93058448] | 114 | them, please inform the jhalfs maintainer(s). -->
|
---|
[94e3e7bd] | 115 | <screen><userinput>cat > /etc/systemd/network/10-eth-static.network << "EOF"
|
---|
[1118b17] | 116 | <literal>[Match]
|
---|
[8154126] | 117 | Name=<replaceable><network-device-name></replaceable>
|
---|
[1118b17] | 118 |
|
---|
| 119 | [Network]
|
---|
| 120 | Address=192.168.0.2/24
|
---|
| 121 | Gateway=192.168.0.1
|
---|
| 122 | DNS=192.168.0.1
|
---|
| 123 | Domains=<replaceable><Your Domain Name></replaceable></literal>
|
---|
| 124 | EOF</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
|
---|
[7eac1a5e] | 128 | static <filename>/etc/resolv.conf</filename> file.</para>
|
---|
[1118b17] | 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 |
|
---|
[94e3e7bd] | 138 | <screen role="nodump"><userinput>cat > /etc/systemd/network/10-eth-dhcp.network << "EOF"
|
---|
[1118b17] | 139 | <literal>[Match]
|
---|
[94e3e7bd] | 140 | Name=<network-device-name>
|
---|
[1118b17] | 141 |
|
---|
| 142 | [Network]
|
---|
| 143 | DHCP=ipv4
|
---|
| 144 |
|
---|
| 145 | [DHCP]
|
---|
| 146 | UseDomains=true</literal>
|
---|
| 147 | EOF</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 |
|
---|
[4139f87] | 167 | <sect3 id="resolv-conf-systemd-resolved">
|
---|
[1118b17] | 168 | <title>systemd-resolved Configuration</title>
|
---|
| 169 |
|
---|
[c53ff08] | 170 | <note><para>If using methods incompatible with systemd-resolved to
|
---|
| 171 | configure your network interfaces (ex: ppp, etc.), or if using any
|
---|
| 172 | type of local resolver (ex: bind, dnsmasq, unbound, etc.),
|
---|
| 173 | or any other software that generates an <filename>/etc/resolv.conf</filename>
|
---|
| 174 | (ex: a <command>resolvconf</command> program other than the one
|
---|
| 175 | provided by systemd), the <command>systemd-resolved</command> service
|
---|
| 176 | should not be used.</para></note>
|
---|
[1118b17] | 177 |
|
---|
| 178 | <para>When using <command>systemd-resolved</command> for DNS
|
---|
[e053117] | 179 | configuration, it creates the file
|
---|
| 180 | <filename>/run/systemd/resolve/resolv.conf</filename>. Create a
|
---|
[4139f87] | 181 | symlink in <filename>/etc</filename> to use the generated file:</para>
|
---|
[e053117] | 182 |
|
---|
[4139f87] | 183 | <screen><userinput>ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
|
---|
[1118b17] | 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 > /etc/resolv.conf << "EOF"
|
---|
| 194 | <literal># Begin /etc/resolv.conf
|
---|
| 195 |
|
---|
| 196 | domain <replaceable><Your Domain Name></replaceable>
|
---|
| 197 | nameserver <replaceable><IP address of your primary nameserver></replaceable>
|
---|
| 198 | nameserver <replaceable><IP address of your secondary nameserver></replaceable>
|
---|
| 199 |
|
---|
| 200 | # End /etc/resolv.conf</literal>
|
---|
| 201 | EOF</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><IP address of the nameserver></replaceable>
|
---|
[9e7475a] | 209 | with the IP address of the DNS server most appropriate for your setup.
|
---|
| 210 | There will often be more than one entry (requirements demand secondary
|
---|
| 211 | servers for fallback capability). If you only need or want one DNS server,
|
---|
| 212 | remove the second <emphasis>nameserver</emphasis> line from the file.
|
---|
| 213 | The IP address may also be a router on the local network. Another option
|
---|
| 214 | is to use the Google Public DNS service using the IP addresses below as
|
---|
| 215 | nameservers.</para>
|
---|
[1118b17] | 216 |
|
---|
| 217 | <note><para>The Google Public IPv4 DNS addresses are
|
---|
| 218 | <parameter>8.8.8.8</parameter> and <parameter>8.8.4.4</parameter>
|
---|
| 219 | for IPv4, and <parameter>2001:4860:4860::8888</parameter> and
|
---|
| 220 | <parameter>2001:4860:4860::8844</parameter> for IPv6.</para></note>
|
---|
| 221 |
|
---|
| 222 | </sect3>
|
---|
| 223 |
|
---|
| 224 | </sect2>
|
---|
| 225 |
|
---|
[afcfd74] | 226 | <sect2 id="ch-config-hostname">
|
---|
[1118b17] | 227 | <title>Configuring the system hostname</title>
|
---|
| 228 |
|
---|
[afcfd74] | 229 | <indexterm zone="ch-config-hostname">
|
---|
[1118b17] | 230 | <primary sortas="d-hostname">hostname</primary>
|
---|
| 231 | <secondary>configuring</secondary>
|
---|
| 232 | </indexterm>
|
---|
| 233 |
|
---|
| 234 | <para>During the boot process, the file <filename>/etc/hostname</filename>
|
---|
| 235 | is used for establishing the system's hostname.</para>
|
---|
| 236 |
|
---|
| 237 | <para>Create the <filename>/etc/hostname</filename> file and enter a
|
---|
| 238 | hostname by running:</para>
|
---|
| 239 |
|
---|
| 240 | <screen><userinput>echo "<replaceable><lfs></replaceable>" > /etc/hostname</userinput></screen>
|
---|
| 241 |
|
---|
| 242 | <para><replaceable><lfs></replaceable> needs to be replaced with the
|
---|
| 243 | name given to the computer. Do not enter the Fully Qualified Domain Name
|
---|
| 244 | (FQDN) here. That information is put in the
|
---|
| 245 | <filename>/etc/hosts</filename> file.</para>
|
---|
| 246 |
|
---|
| 247 | </sect2>
|
---|
| 248 |
|
---|
[afcfd74] | 249 | <sect2 id="ch-config-hosts">
|
---|
[1118b17] | 250 | <title>Customizing the /etc/hosts File</title>
|
---|
| 251 |
|
---|
[afcfd74] | 252 | <indexterm zone="ch-config-hosts">
|
---|
[1118b17] | 253 | <primary sortas="e-/etc/hosts">/etc/hosts</primary>
|
---|
| 254 | </indexterm>
|
---|
| 255 |
|
---|
[afcfd74] | 256 | <indexterm zone="ch-config-hosts">
|
---|
[1118b17] | 257 | <primary sortas="d-localnet">localnet</primary>
|
---|
| 258 | <secondary>/etc/hosts</secondary>
|
---|
| 259 | </indexterm>
|
---|
| 260 |
|
---|
[afcfd74] | 261 | <indexterm zone="ch-config-hosts">
|
---|
[1118b17] | 262 | <primary sortas="d-network">network</primary>
|
---|
| 263 | <secondary>/etc/hosts</secondary>
|
---|
| 264 | </indexterm>
|
---|
| 265 |
|
---|
| 266 | <para>Decide on a fully-qualified domain name (FQDN), and possible aliases
|
---|
[9e7475a] | 267 | for use in the <filename>/etc/hosts</filename> file. If using static IP
|
---|
[1118b17] | 268 | addresses, you'll also need to decide on an IP address. The syntax
|
---|
| 269 | for a hosts file entry is:</para>
|
---|
| 270 |
|
---|
| 271 | <screen><literal>IP_address myhost.example.org aliases</literal></screen>
|
---|
| 272 |
|
---|
| 273 | <para>Unless the computer is to be visible to the Internet (i.e., there is
|
---|
| 274 | a registered domain and a valid block of assigned IP addresses—most
|
---|
| 275 | users do not have this), make sure that the IP address is in the private
|
---|
| 276 | network IP address range. Valid ranges are:</para>
|
---|
| 277 |
|
---|
| 278 | <screen><literal>Private Network Address Range Normal Prefix
|
---|
| 279 | 10.0.0.1 - 10.255.255.254 8
|
---|
| 280 | 172.x.0.1 - 172.x.255.254 16
|
---|
| 281 | 192.168.y.1 - 192.168.y.254 24</literal></screen>
|
---|
| 282 |
|
---|
| 283 | <para>x can be any number in the range 16-31. y can be any number in the
|
---|
| 284 | range 0-255.</para>
|
---|
| 285 |
|
---|
| 286 | <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
|
---|
| 287 | this IP could be lfs.example.org.</para>
|
---|
| 288 |
|
---|
| 289 | <para>Even if not using a network card, a valid FQDN is still required.
|
---|
[9e7475a] | 290 | This is necessary for certain programs, such as MTAs, to operate properly.</para>
|
---|
[1118b17] | 291 |
|
---|
[4234aea6] | 292 | <!--
|
---|
[9e7475a] | 293 | <para>Create the /etc/hosts file using the following command:</para>
|
---|
[1118b17] | 294 |
|
---|
[4139f87] | 295 | <screen role="nodump"><userinput>cat > /etc/hosts << "EOF"
|
---|
[1118b17] | 296 | <literal># Begin /etc/hosts
|
---|
| 297 |
|
---|
[c300794] | 298 | 127.0.0.1 localhost.localdomain localhost
|
---|
[bd4a1d9] | 299 | 127.0.1.1 <replaceable><FQDN></replaceable> <replaceable><HOSTNAME></replaceable>
|
---|
| 300 | ::1 localhost ip6-localhost ip6-loopback
|
---|
| 301 | ff02::1 ip6-allnodes
|
---|
| 302 | ff02::2 ip6-allrouters
|
---|
[1118b17] | 303 |
|
---|
| 304 | # End /etc/hosts</literal>
|
---|
| 305 | EOF</userinput></screen>
|
---|
[4234aea6] | 306 | -->
|
---|
[1118b17] | 307 |
|
---|
[4234aea6] | 308 | <para>Create the <filename>/etc/hosts</filename> file using the following
|
---|
| 309 | command:</para>
|
---|
[1118b17] | 310 |
|
---|
[a542116] | 311 | <screen><userinput>cat > /etc/hosts << "EOF"
|
---|
[1118b17] | 312 | <literal># Begin /etc/hosts
|
---|
| 313 |
|
---|
[9e7475a] | 314 | 127.0.0.1 localhost.localdomain localhost
|
---|
[bd4a1d9] | 315 | 127.0.1.1 <replaceable><FQDN></replaceable> <replaceable><HOSTNAME></replaceable>
|
---|
| 316 | <replaceable><192.168.0.2></replaceable> <replaceable><FQDN></replaceable> <replaceable><HOSTNAME></replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
|
---|
| 317 | ::1 localhost ip6-localhost ip6-loopback
|
---|
| 318 | ff02::1 ip6-allnodes
|
---|
| 319 | ff02::2 ip6-allrouters
|
---|
[1118b17] | 320 |
|
---|
| 321 | # End /etc/hosts</literal>
|
---|
| 322 | EOF</userinput></screen>
|
---|
| 323 |
|
---|
| 324 | <para>The <replaceable><192.168.0.2></replaceable>,
|
---|
[bd4a1d9] | 325 | <replaceable><FQDN></replaceable>, and
|
---|
[1118b17] | 326 | <replaceable><HOSTNAME></replaceable> values need to be
|
---|
| 327 | changed for specific uses or requirements (if assigned an IP address by a
|
---|
| 328 | network/system administrator and the machine will be connected to an
|
---|
[4234aea6] | 329 | existing network). The optional alias name(s) can be omitted, and the
|
---|
| 330 | <replaceable><192.168.0.2</replaceable> line can be omitted if you
|
---|
| 331 | are using a connection configured with DHCP or IPv6 Autoconfiguration.</para>
|
---|
| 332 |
|
---|
| 333 | <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents
|
---|
| 334 | the IPv6 loopback interface. 127.0.1.1 is a loopback entry reserved
|
---|
| 335 | specifically for the FQDN.</para>
|
---|
| 336 |
|
---|
[1118b17] | 337 | </sect2>
|
---|
| 338 |
|
---|
| 339 | </sect1>
|
---|