network.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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-scripts-network">
  8. <?dbhtml filename="network.html"?>
  9. <title>General Network Configuration</title>
  10. <indexterm zone="ch-scripts-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 defualt, and absolutely should not be disabled.</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. <note><para>Udev may assign network card interface names based
  39. on system physical characteristics such as enp2s1. If you are
  40. not sure what your interface name is, you can always run
  41. <command>ip link</command> after you have booted your system.
  42. </para></note>
  43. <sect3 id="systemd-networkd-static">
  44. <title>Static IP Configuration</title>
  45. <para>The command below creates a basic configuration file for a
  46. Static IP setup (using both systemd-networkd and
  47. systemd-resolved):</para>
  48. <screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-eth0-static.network &lt;&lt; "EOF"
  49. <literal>[Match]
  50. Name=eth0
  51. [Network]
  52. Address=192.168.0.2/24
  53. Gateway=192.168.0.1
  54. DNS=192.168.0.1</literal>
  55. EOF</userinput></screen>
  56. <para>Multiple DNS entries can be added if you have more than one DNS
  57. server.</para>
  58. </sect3>
  59. <sect3 id="systemd-networkd-dhcp">
  60. <title>DHCP Configuration</title>
  61. <para>The command below creates a basic configuration file for an IPv4
  62. DHCP setup:</para>
  63. <screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-eth0-dhcp.network &lt;&lt; "EOF"
  64. <literal>[Match]
  65. Name=eth0
  66. [Network]
  67. DHCP=ipv4</literal>
  68. EOF</userinput></screen>
  69. </sect3>
  70. </sect2>
  71. <sect2 id="resolv.conf">
  72. <title>Creating the /etc/resolv.conf File</title>
  73. <indexterm zone="resolv.conf">
  74. <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
  75. </indexterm>
  76. <para>If the system is going to be connected to the Internet, it will
  77. need some means of Domain Name Service (DNS) name resolution to
  78. resolve Internet domain names to IP addresses, and vice versa. This is
  79. best achieved by placing the IP address of the DNS server, available
  80. from the ISP or network administrator, into
  81. <filename>/etc/resolv.conf</filename>.</para>
  82. <sect3 id="resolv-conf-systemd-resoloved">
  83. <title>systemd-resolved Configuration</title>
  84. <note><para>If using another means to configure your network
  85. interfaces (ex: ppp, network-manager, etc.), or if using any type of
  86. local resolver (ex: bind, dnsmasq, etc.), or any other software that
  87. generates an <filename>/etc/resolv.conf</filename> (ex: resolvconf), the
  88. <command>systemd-resolved</command> service should not be
  89. used.</para></note>
  90. <para>When using <command>systemd-resolved</command> for DNS
  91. configuration, it is responsible for creating the
  92. <filename>/etc/resolv.conf</filename> file. Since version 226, the
  93. symlink for <filename>/etc/resolv.conf</filename> is created by systemd
  94. when needed, so no further configuration is necessary.</para>
  95. </sect3>
  96. <sect3 id="resolv-conf-static">
  97. <title>Static resolv.conf Configuration</title>
  98. <para>If a static <filename>/etc/resolv.conf</filename> is desired,
  99. create it by running the following command:</para>
  100. <screen role="nodump"><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
  101. <literal># Begin /etc/resolv.conf
  102. domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
  103. nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
  104. nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
  105. # End /etc/resolv.conf</literal>
  106. EOF</userinput></screen>
  107. <para>The <varname>domain</varname> statement can be omitted
  108. or replaced with a <varname>search</varname> statement. See the man page
  109. for resolv.conf for more details.</para>
  110. <para>Replace
  111. <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
  112. with the IP address of the DNS most appropriate for the setup. There will
  113. often be more than one entry (requirements demand secondary servers for
  114. fallback capability). If you only need or want one DNS server, remove the
  115. second <emphasis>nameserver</emphasis> line from the file. The IP address
  116. may also be a router on the local network.</para>
  117. <note><para>The Google Public IPv4 DNS addresses are
  118. <parameter>8.8.8.8</parameter> and <parameter>8.8.4.4</parameter>
  119. for IPv4, and <parameter>2001:4860:4860::8888</parameter> and
  120. <parameter>2001:4860:4860::8844</parameter> for IPv6.</para></note>
  121. </sect3>
  122. </sect2>
  123. <sect2 id="ch-scripts-hostname">
  124. <title>Configuring the system hostname</title>
  125. <indexterm zone="ch-scripts-hostname">
  126. <primary sortas="d-hostname">hostname</primary>
  127. <secondary>configuring</secondary>
  128. </indexterm>
  129. <para>During the boot process, the file <filename>/etc/hostname</filename>
  130. is used for establishing the system's hostname.</para>
  131. <para>Create the <filename>/etc/hostname</filename> file and enter a
  132. hostname by running:</para>
  133. <screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
  134. <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
  135. name given to the computer. Do not enter the Fully Qualified Domain Name
  136. (FQDN) here. That information is put in the
  137. <filename>/etc/hosts</filename> file.</para>
  138. </sect2>
  139. <sect2 id="ch-scripts-hosts">
  140. <title>Customizing the /etc/hosts File</title>
  141. <indexterm zone="ch-scripts-hosts">
  142. <primary sortas="e-/etc/hosts">/etc/hosts</primary>
  143. </indexterm>
  144. <indexterm zone="ch-scripts-hosts">
  145. <primary sortas="d-localnet">localnet</primary>
  146. <secondary>/etc/hosts</secondary>
  147. </indexterm>
  148. <indexterm zone="ch-scripts-hosts">
  149. <primary sortas="d-network">network</primary>
  150. <secondary>/etc/hosts</secondary>
  151. </indexterm>
  152. <para>Decide on a fully-qualified domain name (FQDN), and possible aliases
  153. for use in the <filename>/etc/hosts</filename> file. If using static
  154. addresses, you'll also need to decide on an IP address. The syntax
  155. for a hosts file entry is:</para>
  156. <screen><literal>IP_address myhost.example.org aliases</literal></screen>
  157. <para>Unless the computer is to be visible to the Internet (i.e., there is
  158. a registered domain and a valid block of assigned IP addresses&mdash;most
  159. users do not have this), make sure that the IP address is in the private
  160. network IP address range. Valid ranges are:</para>
  161. <screen><literal>Private Network Address Range Normal Prefix
  162. 10.0.0.1 - 10.255.255.254 8
  163. 172.x.0.1 - 172.x.255.254 16
  164. 192.168.y.1 - 192.168.y.254 24</literal></screen>
  165. <para>x can be any number in the range 16-31. y can be any number in the
  166. range 0-255.</para>
  167. <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
  168. this IP could be lfs.example.org.</para>
  169. <para>Even if not using a network card, a valid FQDN is still required.
  170. This is necessary for certain programs to operate correctly.</para>
  171. <para>If using DHCP, DHCPv6, IPv6 Autoconfiguration, or if a network card
  172. is not going to be configured, create the <filename>/etc/hosts</filename>
  173. file by running the following command:</para>
  174. <screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
  175. <literal># Begin /etc/hosts
  176. 127.0.0.1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost <replaceable>[alias1] [alias2] ...</replaceable>
  177. ::1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost <replaceable>[alias1] [alias2] ...</replaceable>
  178. # End /etc/hosts</literal>
  179. EOF</userinput></screen>
  180. <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents
  181. the IPv6 loopback interface.</para>
  182. <para>If ussing a staic address, create the <filename>/etc/hosts</filename>
  183. file by running this command instead:</para>
  184. <screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
  185. <literal># Begin /etc/hosts
  186. 127.0.0.1 localhost
  187. ::1 localhost
  188. <replaceable>&lt;192.168.0.2&gt;</replaceable> <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
  189. # End /etc/hosts</literal>
  190. EOF</userinput></screen>
  191. <para>The <replaceable>&lt;192.168.0.2&gt;</replaceable>,
  192. <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable>, and
  193. <replaceable>&lt;HOSTNAME&gt;</replaceable> values need to be
  194. changed for specific uses or requirements (if assigned an IP address by a
  195. network/system administrator and the machine will be connected to an
  196. existing network). The optional alias name(s) can be omitted.</para>
  197. </sect2>
  198. </sect1>