networkd.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. <sect1 id="ch-config-network" revision="systemd">
  8. <?dbhtml filename="network.html"?>
  9. <title>General Network Configuration</title>
  10. <indexterm zone="ch-config-network">
  11. <primary sortas="d-network">network</primary>
  12. <secondary>configuring</secondary></indexterm>
  13. <para>This section only applies if a network card is to be
  14. configured.</para>
  15. <sect2>
  16. <title>Network Interface Configuration Files</title>
  17. <para>Starting with version 209, systemd ships a network configuration
  18. daemon called <command>systemd-networkd</command> which can be used for
  19. basic network configuration. Additionally, since version 213, DNS name
  20. resolution can be handled by <command>systemd-resolved</command> in place
  21. of a static <filename>/etc/resolv.conf</filename> file. Both services are
  22. enabled by default.</para>
  23. <para>Configuration files for <command>systemd-networkd</command> (and
  24. <command>systemd-resolved</command>) can be placed in
  25. <filename class="directory">/usr/lib/systemd/network</filename>
  26. or <filename class="directory">/etc/systemd/network</filename>. Files in
  27. <filename class="directory">/etc/systemd/network</filename> have a
  28. higher priority than the ones in
  29. <filename class="directory">/usr/lib/systemd/network</filename>.
  30. There are three types of configuration files:
  31. <filename class="extension">.link</filename>,
  32. <filename class="extension">.netdev</filename> and
  33. <filename class="extension">.network</filename> files. For detailed
  34. descriptions and example contents of these configuration files, consult
  35. the <filename>systemd-link(5)</filename>,
  36. <filename>systemd-netdev(5)</filename> and
  37. <filename>systemd-network(5)</filename> manual pages.</para>
  38. <sect3 id="systemd-network-devices">
  39. <title>Network Device Naming</title>
  40. <para>
  41. Udev normally assigns network card interface names based
  42. on physical system characteristics such as enp2s1. If you are
  43. not sure what your interface name is, you can always run
  44. <command>ip link</command> after you have booted your system.
  45. </para>
  46. <para>
  47. For most systems, there is only one network interface for
  48. each type of connection. For example, the classic interface
  49. name for a wired connection is eth0. A wireless connection
  50. will usually have the name wifi0 or wlan0.
  51. </para>
  52. <para>
  53. If you prefer to use the classic or customized network interface names,
  54. there are three alternative ways to do that:</para>
  55. <itemizedlist>
  56. <listitem>
  57. <para>
  58. Mask udev's .link file for the default policy:
  59. <screen role="nodump"><userinput>ln -s /dev/null /etc/systemd/network/99-default.link</userinput></screen>
  60. </para>
  61. </listitem>
  62. <listitem>
  63. <para>
  64. Create a manual naming scheme, for example by naming the
  65. interfaces something like "internet0", "dmz0", or "lan0".
  66. To do that, create .link files in /etc/systemd/network/ that
  67. select an explicit name or a better naming scheme for your
  68. network interfaces. For example:
  69. </para>
  70. <screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-ether0.link &lt;&lt; "EOF"
  71. <literal>[Match]
  72. # Change the MAC address as appropriate for your network device
  73. MACAddress=12:34:45:78:90:AB
  74. [Link]
  75. Name=ether0</literal>
  76. EOF</userinput></screen>
  77. <para>
  78. See the man page systemd.link(5) for more information.
  79. </para>
  80. </listitem>
  81. <listitem>
  82. <para>
  83. In /boot/grub/grub.cfg, pass the option net.ifnames=0 on the
  84. kernel command line.
  85. </para>
  86. </listitem>
  87. </itemizedlist>
  88. </sect3>
  89. <sect3 id="systemd-networkd-static">
  90. <title>Static IP Configuration</title>
  91. <para>The command below creates a basic configuration file for a
  92. Static IP setup (using both systemd-networkd and
  93. systemd-resolved):</para>
  94. <!-- jhalfs relies on the values for Name, Address, etc. If you want to change
  95. them, please inform the jhalfs maintainer(s). -->
  96. <screen><userinput>cat &gt; /etc/systemd/network/10-eth-static.network &lt;&lt; "EOF"
  97. <literal>[Match]
  98. Name=<replaceable>&lt;network-device-name&gt;</replaceable>
  99. [Network]
  100. Address=192.168.0.2/24
  101. Gateway=192.168.0.1
  102. DNS=192.168.0.1
  103. Domains=<replaceable>&lt;Your Domain Name&gt;</replaceable></literal>
  104. EOF</userinput></screen>
  105. <para>Multiple DNS entries can be added if you have more than one DNS
  106. server. Do not include DNS or Domains entries if you intend to use a
  107. static <filename>/etc/resolv.conf</filename> file.</para>
  108. </sect3>
  109. <sect3 id="systemd-networkd-dhcp">
  110. <title>DHCP Configuration</title>
  111. <para>The command below creates a basic configuration file for an IPv4
  112. DHCP setup:</para>
  113. <screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-eth-dhcp.network &lt;&lt; "EOF"
  114. <literal>[Match]
  115. Name=&lt;network-device-name&gt;
  116. [Network]
  117. DHCP=ipv4
  118. [DHCP]
  119. UseDomains=true</literal>
  120. EOF</userinput></screen>
  121. </sect3>
  122. </sect2>
  123. <sect2 id="resolv.conf">
  124. <title>Creating the /etc/resolv.conf File</title>
  125. <indexterm zone="resolv.conf">
  126. <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
  127. </indexterm>
  128. <para>If the system is going to be connected to the Internet, it will
  129. need some means of Domain Name Service (DNS) name resolution to
  130. resolve Internet domain names to IP addresses, and vice versa. This is
  131. best achieved by placing the IP address of the DNS server, available
  132. from the ISP or network administrator, into
  133. <filename>/etc/resolv.conf</filename>.</para>
  134. <sect3 id="resolv-conf-systemd-resolved">
  135. <title>systemd-resolved Configuration</title>
  136. <note><para>If using methods incompatible with systemd-resolved to
  137. configure your network interfaces (ex: ppp, etc.), or if using any
  138. type of local resolver (ex: bind, dnsmasq, unbound, etc.),
  139. or any other software that generates an <filename>/etc/resolv.conf</filename>
  140. (ex: a <command>resolvconf</command> program other than the one
  141. provided by systemd), the <command>systemd-resolved</command> service
  142. should not be used.</para></note>
  143. <para>When using <command>systemd-resolved</command> for DNS
  144. configuration, it creates the file
  145. <filename>/run/systemd/resolve/resolv.conf</filename>. Create a
  146. symlink in <filename>/etc</filename> to use the generated file:</para>
  147. <screen><userinput>ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
  148. </sect3>
  149. <sect3 id="resolv-conf-static">
  150. <title>Static resolv.conf Configuration</title>
  151. <para>If a static <filename>/etc/resolv.conf</filename> is desired,
  152. create it by running the following command:</para>
  153. <screen role="nodump"><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
  154. <literal># Begin /etc/resolv.conf
  155. domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
  156. nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
  157. nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
  158. # End /etc/resolv.conf</literal>
  159. EOF</userinput></screen>
  160. <para>The <varname>domain</varname> statement can be omitted
  161. or replaced with a <varname>search</varname> statement. See the man page
  162. for resolv.conf for more details.</para>
  163. <para>Replace
  164. <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
  165. with the IP address of the DNS server most appropriate for your setup.
  166. There will often be more than one entry (requirements demand secondary
  167. servers for fallback capability). If you only need or want one DNS server,
  168. remove the second <emphasis>nameserver</emphasis> line from the file.
  169. The IP address may also be a router on the local network. Another option
  170. is to use the Google Public DNS service using the IP addresses below as
  171. nameservers.</para>
  172. <note><para>The Google Public IPv4 DNS addresses are
  173. <parameter>8.8.8.8</parameter> and <parameter>8.8.4.4</parameter>
  174. for IPv4, and <parameter>2001:4860:4860::8888</parameter> and
  175. <parameter>2001:4860:4860::8844</parameter> for IPv6.</para></note>
  176. </sect3>
  177. </sect2>
  178. <sect2 id="ch-config-hostname">
  179. <title>Configuring the system hostname</title>
  180. <indexterm zone="ch-config-hostname">
  181. <primary sortas="d-hostname">hostname</primary>
  182. <secondary>configuring</secondary>
  183. </indexterm>
  184. <para>During the boot process, the file <filename>/etc/hostname</filename>
  185. is used for establishing the system's hostname.</para>
  186. <para>Create the <filename>/etc/hostname</filename> file and enter a
  187. hostname by running:</para>
  188. <screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
  189. <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
  190. name given to the computer. Do not enter the Fully Qualified Domain Name
  191. (FQDN) here. That information is put in the
  192. <filename>/etc/hosts</filename> file.</para>
  193. </sect2>
  194. <sect2 id="ch-config-hosts">
  195. <title>Customizing the /etc/hosts File</title>
  196. <indexterm zone="ch-config-hosts">
  197. <primary sortas="e-/etc/hosts">/etc/hosts</primary>
  198. </indexterm>
  199. <indexterm zone="ch-config-hosts">
  200. <primary sortas="d-localnet">localnet</primary>
  201. <secondary>/etc/hosts</secondary>
  202. </indexterm>
  203. <indexterm zone="ch-config-hosts">
  204. <primary sortas="d-network">network</primary>
  205. <secondary>/etc/hosts</secondary>
  206. </indexterm>
  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 IP
  209. addresses, you'll also need to decide on an IP address. The syntax
  210. for a hosts file entry is:</para>
  211. <screen><literal>IP_address myhost.example.org aliases</literal></screen>
  212. <para>Unless the computer is to be visible to the Internet (i.e., there is
  213. a registered domain and a valid block of assigned IP addresses&mdash;most
  214. users do not have this), make sure that the IP address is in the private
  215. network IP address range. Valid ranges are:</para>
  216. <screen><literal>Private Network Address Range Normal Prefix
  217. 10.0.0.1 - 10.255.255.254 8
  218. 172.x.0.1 - 172.x.255.254 16
  219. 192.168.y.1 - 192.168.y.254 24</literal></screen>
  220. <para>x can be any number in the range 16-31. y can be any number in the
  221. range 0-255.</para>
  222. <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
  223. this IP could be lfs.example.org.</para>
  224. <para>Even if not using a network card, a valid FQDN is still required.
  225. This is necessary for certain programs, such as MTAs, to operate properly.</para>
  226. <!--
  227. <para>Create the /etc/hosts file using the following command:</para>
  228. <screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
  229. <literal># Begin /etc/hosts
  230. 127.0.0.1 localhost.localdomain localhost
  231. 127.0.1.1 <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable>
  232. ::1 localhost ip6-localhost ip6-loopback
  233. ff02::1 ip6-allnodes
  234. ff02::2 ip6-allrouters
  235. # End /etc/hosts</literal>
  236. EOF</userinput></screen>
  237. -->
  238. <para>Create the <filename>/etc/hosts</filename> file using the following
  239. command:</para>
  240. <screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
  241. <literal># Begin /etc/hosts
  242. 127.0.0.1 localhost.localdomain localhost
  243. 127.0.1.1 <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable>
  244. <replaceable>&lt;192.168.0.2&gt;</replaceable> <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
  245. ::1 localhost ip6-localhost ip6-loopback
  246. ff02::1 ip6-allnodes
  247. ff02::2 ip6-allrouters
  248. # End /etc/hosts</literal>
  249. EOF</userinput></screen>
  250. <para>The <replaceable>&lt;192.168.0.2&gt;</replaceable>,
  251. <replaceable>&lt;FQDN&gt;</replaceable>, and
  252. <replaceable>&lt;HOSTNAME&gt;</replaceable> values need to be
  253. changed for specific uses or requirements (if assigned an IP address by a
  254. network/system administrator and the machine will be connected to an
  255. existing network). The optional alias name(s) can be omitted, and the
  256. <replaceable>&lt;192.168.0.2</replaceable> line can be omitted if you
  257. are using a connection configured with DHCP or IPv6 Autoconfiguration.</para>
  258. <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents
  259. the IPv6 loopback interface. 127.0.1.1 is a loopback entry reserved
  260. specifically for the FQDN.</para>
  261. </sect2>
  262. </sect1>