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