[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 |
|
---|
[5f3777a] | 30 | <note>
|
---|
| 31 | <para>
|
---|
| 32 | If you will not use <command>systemd-networkd</command> for network
|
---|
| 33 | configuration (for example, when the system is not connected to
|
---|
| 34 | network, or you want to use another utility like NetworkManager
|
---|
| 35 | for network configuration), disable a service to prevent an error
|
---|
| 36 | message during boot:
|
---|
| 37 | </para>
|
---|
| 38 | <screen role='nodump'><userinput>systemctl disable systemd-networkd-wait-online</userinput></screen>
|
---|
| 39 | </note>
|
---|
| 40 |
|
---|
[1118b17] | 41 | <para>Configuration files for <command>systemd-networkd</command> (and
|
---|
| 42 | <command>systemd-resolved</command>) can be placed in
|
---|
| 43 | <filename class="directory">/usr/lib/systemd/network</filename>
|
---|
| 44 | or <filename class="directory">/etc/systemd/network</filename>. Files in
|
---|
| 45 | <filename class="directory">/etc/systemd/network</filename> have a
|
---|
| 46 | higher priority than the ones in
|
---|
| 47 | <filename class="directory">/usr/lib/systemd/network</filename>.
|
---|
| 48 | There are three types of configuration files:
|
---|
| 49 | <filename class="extension">.link</filename>,
|
---|
| 50 | <filename class="extension">.netdev</filename> and
|
---|
| 51 | <filename class="extension">.network</filename> files. For detailed
|
---|
[c34b4fb] | 52 | descriptions and example contents of these configuration files, consult
|
---|
[1118b17] | 53 | the <filename>systemd-link(5)</filename>,
|
---|
| 54 | <filename>systemd-netdev(5)</filename> and
|
---|
| 55 | <filename>systemd-network(5)</filename> manual pages.</para>
|
---|
| 56 |
|
---|
[94e3e7bd] | 57 | <sect3 id="systemd-network-devices">
|
---|
| 58 | <title>Network Device Naming</title>
|
---|
| 59 |
|
---|
| 60 | <para>
|
---|
| 61 | Udev normally assigns network card interface names based
|
---|
[9e7475a] | 62 | on physical system characteristics such as enp2s1. If you are
|
---|
[94e3e7bd] | 63 | not sure what your interface name is, you can always run
|
---|
| 64 | <command>ip link</command> after you have booted your system.
|
---|
| 65 | </para>
|
---|
| 66 |
|
---|
[1966b8d] | 67 | <note>
|
---|
| 68 | <para>The interface names depend on the implementation and
|
---|
| 69 | configuration of the udev daemon running on the system. The udev
|
---|
| 70 | daemon for LFS (<command>systemd-udevd</command>, installed in
|
---|
| 71 | <xref linkend="ch-system-systemd"/>) will not run unless the LFS
|
---|
| 72 | system is booted. So it's unreliable to determine the interface
|
---|
| 73 | names being used in LFS system by running those commands on the host
|
---|
| 74 | distro,
|
---|
[18d4d6d] | 75 | <emphasis>even though you are in the chroot environment</emphasis>.</para>
|
---|
[1966b8d] | 76 | </note>
|
---|
| 77 |
|
---|
[94e3e7bd] | 78 | <para>
|
---|
| 79 | For most systems, there is only one network interface for
|
---|
| 80 | each type of connection. For example, the classic interface
|
---|
| 81 | name for a wired connection is eth0. A wireless connection
|
---|
[c34b4fb] | 82 | will usually have the name wifi0 or wlan0.
|
---|
[94e3e7bd] | 83 | </para>
|
---|
| 84 |
|
---|
| 85 | <para>
|
---|
| 86 | If you prefer to use the classic or customized network interface names,
|
---|
| 87 | there are three alternative ways to do that:</para>
|
---|
| 88 |
|
---|
| 89 | <itemizedlist>
|
---|
| 90 | <listitem>
|
---|
| 91 | <para>
|
---|
| 92 | Mask udev's .link file for the default policy:
|
---|
| 93 | <screen role="nodump"><userinput>ln -s /dev/null /etc/systemd/network/99-default.link</userinput></screen>
|
---|
| 94 | </para>
|
---|
| 95 | </listitem>
|
---|
| 96 |
|
---|
| 97 | <listitem>
|
---|
| 98 | <para>
|
---|
| 99 | Create a manual naming scheme, for example by naming the
|
---|
[c34b4fb] | 100 | interfaces something like "internet0", "dmz0", or "lan0".
|
---|
| 101 | To do that, create .link files in /etc/systemd/network/ that
|
---|
[9e7475a] | 102 | select an explicit name or a better naming scheme for your
|
---|
| 103 | network interfaces. For example:
|
---|
[94e3e7bd] | 104 | </para>
|
---|
| 105 |
|
---|
| 106 | <screen role="nodump"><userinput>cat > /etc/systemd/network/10-ether0.link << "EOF"
|
---|
| 107 | <literal>[Match]
|
---|
| 108 | # Change the MAC address as appropriate for your network device
|
---|
| 109 | MACAddress=12:34:45:78:90:AB
|
---|
| 110 |
|
---|
| 111 | [Link]
|
---|
| 112 | Name=ether0</literal>
|
---|
| 113 | EOF</userinput></screen>
|
---|
| 114 |
|
---|
| 115 | <para>
|
---|
[c34b4fb] | 116 | See the man page systemd.link(5) for more information.
|
---|
[94e3e7bd] | 117 | </para>
|
---|
| 118 | </listitem>
|
---|
| 119 |
|
---|
| 120 | <listitem>
|
---|
| 121 | <para>
|
---|
[c34b4fb] | 122 | In /boot/grub/grub.cfg, pass the option net.ifnames=0 on the
|
---|
[94e3e7bd] | 123 | kernel command line.
|
---|
| 124 | </para>
|
---|
| 125 | </listitem>
|
---|
| 126 | </itemizedlist>
|
---|
| 127 | </sect3>
|
---|
[1118b17] | 128 |
|
---|
| 129 | <sect3 id="systemd-networkd-static">
|
---|
| 130 | <title>Static IP Configuration</title>
|
---|
| 131 |
|
---|
| 132 | <para>The command below creates a basic configuration file for a
|
---|
| 133 | Static IP setup (using both systemd-networkd and
|
---|
| 134 | systemd-resolved):</para>
|
---|
[8154126] | 135 | <!-- jhalfs relies on the values for Name, Address, etc. If you want to change
|
---|
[93058448] | 136 | them, please inform the jhalfs maintainer(s). -->
|
---|
[94e3e7bd] | 137 | <screen><userinput>cat > /etc/systemd/network/10-eth-static.network << "EOF"
|
---|
[1118b17] | 138 | <literal>[Match]
|
---|
[8154126] | 139 | Name=<replaceable><network-device-name></replaceable>
|
---|
[1118b17] | 140 |
|
---|
| 141 | [Network]
|
---|
| 142 | Address=192.168.0.2/24
|
---|
| 143 | Gateway=192.168.0.1
|
---|
| 144 | DNS=192.168.0.1
|
---|
| 145 | Domains=<replaceable><Your Domain Name></replaceable></literal>
|
---|
| 146 | EOF</userinput></screen>
|
---|
| 147 |
|
---|
| 148 | <para>Multiple DNS entries can be added if you have more than one DNS
|
---|
| 149 | server. Do not include DNS or Domains entries if you intend to use a
|
---|
[7eac1a5e] | 150 | static <filename>/etc/resolv.conf</filename> file.</para>
|
---|
[1118b17] | 151 |
|
---|
| 152 | </sect3>
|
---|
| 153 |
|
---|
| 154 | <sect3 id="systemd-networkd-dhcp">
|
---|
| 155 | <title>DHCP Configuration</title>
|
---|
| 156 |
|
---|
| 157 | <para>The command below creates a basic configuration file for an IPv4
|
---|
| 158 | DHCP setup:</para>
|
---|
| 159 |
|
---|
[94e3e7bd] | 160 | <screen role="nodump"><userinput>cat > /etc/systemd/network/10-eth-dhcp.network << "EOF"
|
---|
[1118b17] | 161 | <literal>[Match]
|
---|
[94e3e7bd] | 162 | Name=<network-device-name>
|
---|
[1118b17] | 163 |
|
---|
| 164 | [Network]
|
---|
| 165 | DHCP=ipv4
|
---|
| 166 |
|
---|
[ce779ec] | 167 | [DHCPv4]
|
---|
[1118b17] | 168 | UseDomains=true</literal>
|
---|
| 169 | EOF</userinput></screen>
|
---|
| 170 |
|
---|
| 171 | </sect3>
|
---|
| 172 |
|
---|
| 173 | </sect2>
|
---|
| 174 |
|
---|
| 175 | <sect2 id="resolv.conf">
|
---|
| 176 | <title>Creating the /etc/resolv.conf File</title>
|
---|
| 177 |
|
---|
| 178 | <indexterm zone="resolv.conf">
|
---|
| 179 | <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
|
---|
| 180 | </indexterm>
|
---|
| 181 |
|
---|
| 182 | <para>If the system is going to be connected to the Internet, it will
|
---|
| 183 | need some means of Domain Name Service (DNS) name resolution to
|
---|
| 184 | resolve Internet domain names to IP addresses, and vice versa. This is
|
---|
| 185 | best achieved by placing the IP address of the DNS server, available
|
---|
| 186 | from the ISP or network administrator, into
|
---|
| 187 | <filename>/etc/resolv.conf</filename>.</para>
|
---|
| 188 |
|
---|
[4139f87] | 189 | <sect3 id="resolv-conf-systemd-resolved">
|
---|
[1118b17] | 190 | <title>systemd-resolved Configuration</title>
|
---|
| 191 |
|
---|
[c53ff08] | 192 | <note><para>If using methods incompatible with systemd-resolved to
|
---|
| 193 | configure your network interfaces (ex: ppp, etc.), or if using any
|
---|
| 194 | type of local resolver (ex: bind, dnsmasq, unbound, etc.),
|
---|
| 195 | or any other software that generates an <filename>/etc/resolv.conf</filename>
|
---|
| 196 | (ex: a <command>resolvconf</command> program other than the one
|
---|
| 197 | provided by systemd), the <command>systemd-resolved</command> service
|
---|
[0a75d62] | 198 | should not be used.</para>
|
---|
| 199 |
|
---|
| 200 | <para>To disable systemd-resolved, issue the following command:</para>
|
---|
| 201 |
|
---|
| 202 | <screen role="nodump"><userinput>systemctl disable systemd-resolved</userinput></screen></note>
|
---|
[1118b17] | 203 |
|
---|
| 204 | <para>When using <command>systemd-resolved</command> for DNS
|
---|
[e053117] | 205 | configuration, it creates the file
|
---|
[d79ba5b] | 206 | <filename>/run/systemd/resolve/stub-resolv.conf</filename>.
|
---|
| 207 | And, if <filename>/etc/resolv.conf</filename> does not exist, it
|
---|
[c633b87] | 208 | will be created by <command>systemd-resolved</command> as a symlink to
|
---|
| 209 | <filename>/run/systemd/resolve/stub-resolv.conf</filename>. So it's
|
---|
[d79ba5b] | 210 | unnecessary to create a <filename>/etc/resolv.conf</filename>
|
---|
| 211 | manually.</para>
|
---|
[0a75d62] | 212 | <!--Create a
|
---|
[4139f87] | 213 | symlink in <filename>/etc</filename> to use the generated file:</para>
|
---|
[e053117] | 214 |
|
---|
[4139f87] | 215 | <screen><userinput>ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
|
---|
[0a75d62] | 216 | At least in systemd-250, this file gets created on first bootup.
|
---|
| 217 | -->
|
---|
[1118b17] | 218 | </sect3>
|
---|
| 219 |
|
---|
| 220 | <sect3 id="resolv-conf-static">
|
---|
| 221 | <title>Static resolv.conf Configuration</title>
|
---|
| 222 |
|
---|
| 223 | <para>If a static <filename>/etc/resolv.conf</filename> is desired,
|
---|
| 224 | create it by running the following command:</para>
|
---|
| 225 |
|
---|
| 226 | <screen role="nodump"><userinput>cat > /etc/resolv.conf << "EOF"
|
---|
| 227 | <literal># Begin /etc/resolv.conf
|
---|
| 228 |
|
---|
| 229 | domain <replaceable><Your Domain Name></replaceable>
|
---|
| 230 | nameserver <replaceable><IP address of your primary nameserver></replaceable>
|
---|
| 231 | nameserver <replaceable><IP address of your secondary nameserver></replaceable>
|
---|
| 232 |
|
---|
| 233 | # End /etc/resolv.conf</literal>
|
---|
| 234 | EOF</userinput></screen>
|
---|
| 235 |
|
---|
| 236 | <para>The <varname>domain</varname> statement can be omitted
|
---|
| 237 | or replaced with a <varname>search</varname> statement. See the man page
|
---|
| 238 | for resolv.conf for more details.</para>
|
---|
| 239 |
|
---|
| 240 | <para>Replace
|
---|
| 241 | <replaceable><IP address of the nameserver></replaceable>
|
---|
[9e7475a] | 242 | with the IP address of the DNS server most appropriate for your setup.
|
---|
| 243 | There will often be more than one entry (requirements demand secondary
|
---|
| 244 | servers for fallback capability). If you only need or want one DNS server,
|
---|
[c34b4fb] | 245 | remove the second <emphasis>nameserver</emphasis> line from the file.
|
---|
[9e7475a] | 246 | The IP address may also be a router on the local network. Another option
|
---|
| 247 | is to use the Google Public DNS service using the IP addresses below as
|
---|
| 248 | nameservers.</para>
|
---|
[1118b17] | 249 |
|
---|
| 250 | <note><para>The Google Public IPv4 DNS addresses are
|
---|
| 251 | <parameter>8.8.8.8</parameter> and <parameter>8.8.4.4</parameter>
|
---|
| 252 | for IPv4, and <parameter>2001:4860:4860::8888</parameter> and
|
---|
| 253 | <parameter>2001:4860:4860::8844</parameter> for IPv6.</para></note>
|
---|
| 254 |
|
---|
| 255 | </sect3>
|
---|
| 256 |
|
---|
| 257 | </sect2>
|
---|
| 258 |
|
---|
[afcfd74] | 259 | <sect2 id="ch-config-hostname">
|
---|
[1118b17] | 260 | <title>Configuring the system hostname</title>
|
---|
| 261 |
|
---|
[afcfd74] | 262 | <indexterm zone="ch-config-hostname">
|
---|
[1118b17] | 263 | <primary sortas="d-hostname">hostname</primary>
|
---|
| 264 | <secondary>configuring</secondary>
|
---|
| 265 | </indexterm>
|
---|
| 266 |
|
---|
| 267 | <para>During the boot process, the file <filename>/etc/hostname</filename>
|
---|
| 268 | is used for establishing the system's hostname.</para>
|
---|
| 269 |
|
---|
| 270 | <para>Create the <filename>/etc/hostname</filename> file and enter a
|
---|
| 271 | hostname by running:</para>
|
---|
| 272 |
|
---|
| 273 | <screen><userinput>echo "<replaceable><lfs></replaceable>" > /etc/hostname</userinput></screen>
|
---|
| 274 |
|
---|
| 275 | <para><replaceable><lfs></replaceable> needs to be replaced with the
|
---|
| 276 | name given to the computer. Do not enter the Fully Qualified Domain Name
|
---|
| 277 | (FQDN) here. That information is put in the
|
---|
| 278 | <filename>/etc/hosts</filename> file.</para>
|
---|
| 279 |
|
---|
| 280 | </sect2>
|
---|
| 281 |
|
---|
[afcfd74] | 282 | <sect2 id="ch-config-hosts">
|
---|
[1118b17] | 283 | <title>Customizing the /etc/hosts File</title>
|
---|
| 284 |
|
---|
[afcfd74] | 285 | <indexterm zone="ch-config-hosts">
|
---|
[1118b17] | 286 | <primary sortas="e-/etc/hosts">/etc/hosts</primary>
|
---|
| 287 | </indexterm>
|
---|
[c34b4fb] | 288 |
|
---|
[afcfd74] | 289 | <indexterm zone="ch-config-hosts">
|
---|
[1118b17] | 290 | <primary sortas="d-localnet">localnet</primary>
|
---|
| 291 | <secondary>/etc/hosts</secondary>
|
---|
| 292 | </indexterm>
|
---|
[c34b4fb] | 293 |
|
---|
[afcfd74] | 294 | <indexterm zone="ch-config-hosts">
|
---|
[1118b17] | 295 | <primary sortas="d-network">network</primary>
|
---|
| 296 | <secondary>/etc/hosts</secondary>
|
---|
| 297 | </indexterm>
|
---|
| 298 |
|
---|
| 299 | <para>Decide on a fully-qualified domain name (FQDN), and possible aliases
|
---|
[9e7475a] | 300 | for use in the <filename>/etc/hosts</filename> file. If using static IP
|
---|
[1118b17] | 301 | addresses, you'll also need to decide on an IP address. The syntax
|
---|
| 302 | for a hosts file entry is:</para>
|
---|
| 303 |
|
---|
| 304 | <screen><literal>IP_address myhost.example.org aliases</literal></screen>
|
---|
| 305 |
|
---|
| 306 | <para>Unless the computer is to be visible to the Internet (i.e., there is
|
---|
| 307 | a registered domain and a valid block of assigned IP addresses—most
|
---|
| 308 | users do not have this), make sure that the IP address is in the private
|
---|
| 309 | network IP address range. Valid ranges are:</para>
|
---|
| 310 |
|
---|
| 311 | <screen><literal>Private Network Address Range Normal Prefix
|
---|
| 312 | 10.0.0.1 - 10.255.255.254 8
|
---|
| 313 | 172.x.0.1 - 172.x.255.254 16
|
---|
| 314 | 192.168.y.1 - 192.168.y.254 24</literal></screen>
|
---|
| 315 |
|
---|
| 316 | <para>x can be any number in the range 16-31. y can be any number in the
|
---|
| 317 | range 0-255.</para>
|
---|
| 318 |
|
---|
| 319 | <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
|
---|
| 320 | this IP could be lfs.example.org.</para>
|
---|
| 321 |
|
---|
| 322 | <para>Even if not using a network card, a valid FQDN is still required.
|
---|
[9e7475a] | 323 | This is necessary for certain programs, such as MTAs, to operate properly.</para>
|
---|
[1118b17] | 324 |
|
---|
[4234aea6] | 325 | <!--
|
---|
[9e7475a] | 326 | <para>Create the /etc/hosts file using the following command:</para>
|
---|
[1118b17] | 327 |
|
---|
[4139f87] | 328 | <screen role="nodump"><userinput>cat > /etc/hosts << "EOF"
|
---|
[1118b17] | 329 | <literal># Begin /etc/hosts
|
---|
| 330 |
|
---|
[c300794] | 331 | 127.0.0.1 localhost.localdomain localhost
|
---|
[bd4a1d9] | 332 | 127.0.1.1 <replaceable><FQDN></replaceable> <replaceable><HOSTNAME></replaceable>
|
---|
| 333 | ::1 localhost ip6-localhost ip6-loopback
|
---|
| 334 | ff02::1 ip6-allnodes
|
---|
| 335 | ff02::2 ip6-allrouters
|
---|
[1118b17] | 336 |
|
---|
| 337 | # End /etc/hosts</literal>
|
---|
| 338 | EOF</userinput></screen>
|
---|
[4234aea6] | 339 | -->
|
---|
[1118b17] | 340 |
|
---|
[4234aea6] | 341 | <para>Create the <filename>/etc/hosts</filename> file using the following
|
---|
| 342 | command:</para>
|
---|
[1118b17] | 343 |
|
---|
[a542116] | 344 | <screen><userinput>cat > /etc/hosts << "EOF"
|
---|
[1118b17] | 345 | <literal># Begin /etc/hosts
|
---|
| 346 |
|
---|
[9e7475a] | 347 | 127.0.0.1 localhost.localdomain localhost
|
---|
[bd4a1d9] | 348 | 127.0.1.1 <replaceable><FQDN></replaceable> <replaceable><HOSTNAME></replaceable>
|
---|
| 349 | <replaceable><192.168.0.2></replaceable> <replaceable><FQDN></replaceable> <replaceable><HOSTNAME></replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
|
---|
| 350 | ::1 localhost ip6-localhost ip6-loopback
|
---|
| 351 | ff02::1 ip6-allnodes
|
---|
| 352 | ff02::2 ip6-allrouters
|
---|
[1118b17] | 353 |
|
---|
| 354 | # End /etc/hosts</literal>
|
---|
| 355 | EOF</userinput></screen>
|
---|
| 356 |
|
---|
| 357 | <para>The <replaceable><192.168.0.2></replaceable>,
|
---|
[bd4a1d9] | 358 | <replaceable><FQDN></replaceable>, and
|
---|
[1118b17] | 359 | <replaceable><HOSTNAME></replaceable> values need to be
|
---|
| 360 | changed for specific uses or requirements (if assigned an IP address by a
|
---|
| 361 | network/system administrator and the machine will be connected to an
|
---|
[4234aea6] | 362 | existing network). The optional alias name(s) can be omitted, and the
|
---|
[d759d8b] | 363 | <replaceable><192.168.0.2></replaceable> line can be omitted if you
|
---|
[4234aea6] | 364 | are using a connection configured with DHCP or IPv6 Autoconfiguration.</para>
|
---|
| 365 |
|
---|
| 366 | <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents
|
---|
| 367 | the IPv6 loopback interface. 127.0.1.1 is a loopback entry reserved
|
---|
| 368 | specifically for the FQDN.</para>
|
---|
| 369 |
|
---|
[1118b17] | 370 | </sect2>
|
---|
| 371 |
|
---|
| 372 | </sect1>
|
---|