[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 |
|
---|
[35a5259] | 8 | <sect1 id="ch-scripts-network" revision="systemd">
|
---|
[1118b17] | 9 | <?dbhtml filename="network.html"?>
|
---|
| 10 |
|
---|
| 11 | <title>General Network Configuration</title>
|
---|
| 12 |
|
---|
| 13 | <indexterm zone="ch-scripts-network">
|
---|
| 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 |
|
---|
| 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.
|
---|
| 50 | </para></note>
|
---|
| 51 |
|
---|
| 52 | <sect3 id="systemd-networkd-static">
|
---|
| 53 | <title>Static IP Configuration</title>
|
---|
| 54 |
|
---|
| 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>
|
---|
| 58 |
|
---|
| 59 | <screen role="nodump"><userinput>cat > /etc/systemd/network/10-eth0-static.network << "EOF"
|
---|
| 60 | <literal>[Match]
|
---|
| 61 | Name=eth0
|
---|
| 62 |
|
---|
| 63 | [Network]
|
---|
| 64 | Address=192.168.0.2/24
|
---|
| 65 | Gateway=192.168.0.1
|
---|
| 66 | DNS=192.168.0.1
|
---|
| 67 | Domains=<replaceable><Your Domain Name></replaceable></literal>
|
---|
| 68 | EOF</userinput></screen>
|
---|
| 69 |
|
---|
| 70 | <para>Multiple DNS entries can be added if you have more than one DNS
|
---|
| 71 | server. Do not include DNS or Domains entries if you intend to use a
|
---|
[7eac1a5e] | 72 | static <filename>/etc/resolv.conf</filename> file.</para>
|
---|
[1118b17] | 73 |
|
---|
| 74 | </sect3>
|
---|
| 75 |
|
---|
| 76 | <sect3 id="systemd-networkd-dhcp">
|
---|
| 77 | <title>DHCP Configuration</title>
|
---|
| 78 |
|
---|
| 79 | <para>The command below creates a basic configuration file for an IPv4
|
---|
| 80 | DHCP setup:</para>
|
---|
| 81 |
|
---|
| 82 | <screen role="nodump"><userinput>cat > /etc/systemd/network/10-eth0-dhcp.network << "EOF"
|
---|
| 83 | <literal>[Match]
|
---|
| 84 | Name=eth0
|
---|
| 85 |
|
---|
| 86 | [Network]
|
---|
| 87 | DHCP=ipv4
|
---|
| 88 |
|
---|
| 89 | [DHCP]
|
---|
| 90 | UseDomains=true</literal>
|
---|
| 91 | EOF</userinput></screen>
|
---|
| 92 |
|
---|
| 93 | </sect3>
|
---|
| 94 |
|
---|
| 95 | </sect2>
|
---|
| 96 |
|
---|
| 97 | <sect2 id="resolv.conf">
|
---|
| 98 | <title>Creating the /etc/resolv.conf File</title>
|
---|
| 99 |
|
---|
| 100 | <indexterm zone="resolv.conf">
|
---|
| 101 | <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
|
---|
| 102 | </indexterm>
|
---|
| 103 |
|
---|
| 104 | <para>If the system is going to be connected to the Internet, it will
|
---|
| 105 | need some means of Domain Name Service (DNS) name resolution to
|
---|
| 106 | resolve Internet domain names to IP addresses, and vice versa. This is
|
---|
| 107 | best achieved by placing the IP address of the DNS server, available
|
---|
| 108 | from the ISP or network administrator, into
|
---|
| 109 | <filename>/etc/resolv.conf</filename>.</para>
|
---|
| 110 |
|
---|
| 111 | <sect3 id="resolv-conf-systemd-resoloved">
|
---|
| 112 | <title>systemd-resolved Configuration</title>
|
---|
| 113 |
|
---|
| 114 | <note><para>If using another means to configure your network
|
---|
| 115 | interfaces (ex: ppp, network-manager, etc.), or if using any type of
|
---|
| 116 | local resolver (ex: bind, dnsmasq, etc.), or any other software that
|
---|
| 117 | generates an <filename>/etc/resolv.conf</filename> (ex: resolvconf), the
|
---|
| 118 | <command>systemd-resolved</command> service should not be
|
---|
| 119 | used.</para></note>
|
---|
| 120 |
|
---|
| 121 | <para>When using <command>systemd-resolved</command> for DNS
|
---|
[e053117] | 122 | configuration, it creates the file
|
---|
| 123 | <filename>/run/systemd/resolve/resolv.conf</filename>. Create a
|
---|
| 124 | symlink in <filename>/etc</filename> to use the generatd file:</para>
|
---|
| 125 |
|
---|
| 126 | <screen><userinput remap="install">ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
|
---|
[1118b17] | 127 |
|
---|
| 128 | </sect3>
|
---|
| 129 |
|
---|
| 130 | <sect3 id="resolv-conf-static">
|
---|
| 131 | <title>Static resolv.conf Configuration</title>
|
---|
| 132 |
|
---|
| 133 | <para>If a static <filename>/etc/resolv.conf</filename> is desired,
|
---|
| 134 | create it by running the following command:</para>
|
---|
| 135 |
|
---|
| 136 | <screen role="nodump"><userinput>cat > /etc/resolv.conf << "EOF"
|
---|
| 137 | <literal># Begin /etc/resolv.conf
|
---|
| 138 |
|
---|
| 139 | domain <replaceable><Your Domain Name></replaceable>
|
---|
| 140 | nameserver <replaceable><IP address of your primary nameserver></replaceable>
|
---|
| 141 | nameserver <replaceable><IP address of your secondary nameserver></replaceable>
|
---|
| 142 |
|
---|
| 143 | # End /etc/resolv.conf</literal>
|
---|
| 144 | EOF</userinput></screen>
|
---|
| 145 |
|
---|
| 146 | <para>The <varname>domain</varname> statement can be omitted
|
---|
| 147 | or replaced with a <varname>search</varname> statement. See the man page
|
---|
| 148 | for resolv.conf for more details.</para>
|
---|
| 149 |
|
---|
| 150 | <para>Replace
|
---|
| 151 | <replaceable><IP address of the nameserver></replaceable>
|
---|
| 152 | with the IP address of the DNS most appropriate for the setup. There will
|
---|
| 153 | often be more than one entry (requirements demand secondary servers for
|
---|
| 154 | fallback capability). If you only need or want one DNS server, remove the
|
---|
| 155 | second <emphasis>nameserver</emphasis> line from the file. The IP address
|
---|
| 156 | may also be a router on the local network.</para>
|
---|
| 157 |
|
---|
| 158 | <note><para>The Google Public IPv4 DNS addresses are
|
---|
| 159 | <parameter>8.8.8.8</parameter> and <parameter>8.8.4.4</parameter>
|
---|
| 160 | for IPv4, and <parameter>2001:4860:4860::8888</parameter> and
|
---|
| 161 | <parameter>2001:4860:4860::8844</parameter> for IPv6.</para></note>
|
---|
| 162 |
|
---|
| 163 | </sect3>
|
---|
| 164 |
|
---|
| 165 | </sect2>
|
---|
| 166 |
|
---|
| 167 | <sect2 id="ch-scripts-hostname">
|
---|
| 168 | <title>Configuring the system hostname</title>
|
---|
| 169 |
|
---|
| 170 | <indexterm zone="ch-scripts-hostname">
|
---|
| 171 | <primary sortas="d-hostname">hostname</primary>
|
---|
| 172 | <secondary>configuring</secondary>
|
---|
| 173 | </indexterm>
|
---|
| 174 |
|
---|
| 175 | <para>During the boot process, the file <filename>/etc/hostname</filename>
|
---|
| 176 | is used for establishing the system's hostname.</para>
|
---|
| 177 |
|
---|
| 178 | <para>Create the <filename>/etc/hostname</filename> file and enter a
|
---|
| 179 | hostname by running:</para>
|
---|
| 180 |
|
---|
| 181 | <screen><userinput>echo "<replaceable><lfs></replaceable>" > /etc/hostname</userinput></screen>
|
---|
| 182 |
|
---|
| 183 | <para><replaceable><lfs></replaceable> needs to be replaced with the
|
---|
| 184 | name given to the computer. Do not enter the Fully Qualified Domain Name
|
---|
| 185 | (FQDN) here. That information is put in the
|
---|
| 186 | <filename>/etc/hosts</filename> file.</para>
|
---|
| 187 |
|
---|
| 188 | </sect2>
|
---|
| 189 |
|
---|
| 190 | <sect2 id="ch-scripts-hosts">
|
---|
| 191 | <title>Customizing the /etc/hosts File</title>
|
---|
| 192 |
|
---|
| 193 | <indexterm zone="ch-scripts-hosts">
|
---|
| 194 | <primary sortas="e-/etc/hosts">/etc/hosts</primary>
|
---|
| 195 | </indexterm>
|
---|
| 196 |
|
---|
| 197 | <indexterm zone="ch-scripts-hosts">
|
---|
| 198 | <primary sortas="d-localnet">localnet</primary>
|
---|
| 199 | <secondary>/etc/hosts</secondary>
|
---|
| 200 | </indexterm>
|
---|
| 201 |
|
---|
| 202 | <indexterm zone="ch-scripts-hosts">
|
---|
| 203 | <primary sortas="d-network">network</primary>
|
---|
| 204 | <secondary>/etc/hosts</secondary>
|
---|
| 205 | </indexterm>
|
---|
| 206 |
|
---|
| 207 | <para>Decide on a fully-qualified domain name (FQDN), and possible aliases
|
---|
| 208 | for use in the <filename>/etc/hosts</filename> file. If using static
|
---|
| 209 | addresses, you'll also need to decide on an IP address. The syntax
|
---|
| 210 | for a hosts file entry is:</para>
|
---|
| 211 |
|
---|
| 212 | <screen><literal>IP_address myhost.example.org aliases</literal></screen>
|
---|
| 213 |
|
---|
| 214 | <para>Unless the computer is to be visible to the Internet (i.e., there is
|
---|
| 215 | a registered domain and a valid block of assigned IP addresses—most
|
---|
| 216 | users do not have this), make sure that the IP address is in the private
|
---|
| 217 | network IP address range. Valid ranges are:</para>
|
---|
| 218 |
|
---|
| 219 | <screen><literal>Private Network Address Range Normal Prefix
|
---|
| 220 | 10.0.0.1 - 10.255.255.254 8
|
---|
| 221 | 172.x.0.1 - 172.x.255.254 16
|
---|
| 222 | 192.168.y.1 - 192.168.y.254 24</literal></screen>
|
---|
| 223 |
|
---|
| 224 | <para>x can be any number in the range 16-31. y can be any number in the
|
---|
| 225 | range 0-255.</para>
|
---|
| 226 |
|
---|
| 227 | <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
|
---|
| 228 | this IP could be lfs.example.org.</para>
|
---|
| 229 |
|
---|
| 230 | <para>Even if not using a network card, a valid FQDN is still required.
|
---|
| 231 | This is necessary for certain programs to operate correctly.</para>
|
---|
| 232 |
|
---|
| 233 | <para>If using DHCP, DHCPv6, IPv6 Autoconfiguration, or if a network card
|
---|
| 234 | is not going to be configured, create the <filename>/etc/hosts</filename>
|
---|
| 235 | file by running the following command:</para>
|
---|
| 236 |
|
---|
| 237 | <screen><userinput>cat > /etc/hosts << "EOF"
|
---|
| 238 | <literal># Begin /etc/hosts
|
---|
| 239 |
|
---|
| 240 | 127.0.0.1 <replaceable><HOSTNAME.example.org></replaceable> <replaceable><HOSTNAME></replaceable> localhost <replaceable>[alias1] [alias2] ...</replaceable>
|
---|
| 241 | ::1 <replaceable><HOSTNAME.example.org></replaceable> <replaceable><HOSTNAME></replaceable> localhost <replaceable>[alias1] [alias2] ...</replaceable>
|
---|
| 242 |
|
---|
| 243 | # End /etc/hosts</literal>
|
---|
| 244 | EOF</userinput></screen>
|
---|
| 245 |
|
---|
| 246 | <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents
|
---|
| 247 | the IPv6 loopback interface.</para>
|
---|
| 248 |
|
---|
[e54605e] | 249 | <para>If using a static address, create the <filename>/etc/hosts</filename>
|
---|
[1118b17] | 250 | file by running this command instead:</para>
|
---|
| 251 |
|
---|
| 252 | <screen role="nodump"><userinput>cat > /etc/hosts << "EOF"
|
---|
| 253 | <literal># Begin /etc/hosts
|
---|
| 254 |
|
---|
| 255 | 127.0.0.1 localhost
|
---|
| 256 | ::1 localhost
|
---|
| 257 | <replaceable><192.168.0.2></replaceable> <replaceable><HOSTNAME.example.org></replaceable> <replaceable><HOSTNAME></replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
|
---|
| 258 |
|
---|
| 259 | # End /etc/hosts</literal>
|
---|
| 260 | EOF</userinput></screen>
|
---|
| 261 |
|
---|
| 262 | <para>The <replaceable><192.168.0.2></replaceable>,
|
---|
| 263 | <replaceable><HOSTNAME.example.org></replaceable>, and
|
---|
| 264 | <replaceable><HOSTNAME></replaceable> values need to be
|
---|
| 265 | changed for specific uses or requirements (if assigned an IP address by a
|
---|
| 266 | network/system administrator and the machine will be connected to an
|
---|
| 267 | existing network). The optional alias name(s) can be omitted.</para>
|
---|
| 268 |
|
---|
| 269 | </sect2>
|
---|
| 270 |
|
---|
| 271 | </sect1>
|
---|