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