network.xml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.</para>
  20. <para>Configuration files for <command>systemd-networkd</command> can be
  21. placed in <filename class="directory">/usr/lib/systemd/network</filename>
  22. or <filename class="directory">/etc/systemd/network</filename>. Note that
  23. files in <filename class="directory">/etc/systemd/network</filename> have
  24. higher priority than the ones in
  25. <filename class="directory">/usr/lib/systemd/network</filename>.</para>
  26. <para>There are three types of configuration files:
  27. <filename class="extension">.link</filename>,
  28. <filename class="extension">.netdev</filename> and
  29. <filename class="extension">.network</filename> files. For detailed
  30. explanation about contents of the mentioned
  31. configuration files, consult <filename>systemd-link(5)</filename>,
  32. <filename>systemd-netdev(5)</filename> and
  33. <filename>systemd-network(5)</filename> manual pages.</para>
  34. <note><para>Udev may assign network card interface names based
  35. on system physical characteristics such as enp2s1. If you are
  36. not sure what your interface name is, you can always run
  37. <command>ip link</command> after you have booted your system.
  38. </para></note>
  39. <sect3 id="systemd-networkd-static">
  40. <title>Static IP Configuration</title>
  41. <para>The command below creates a basic configuration file for
  42. Static IP setup:</para>
  43. <screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-static-eth0.network &lt;&lt; "EOF"
  44. <literal>[Match]
  45. Name=eth0
  46. [Network]
  47. Address=192.168.0.2/24
  48. Gateway=192.168.0.1
  49. DNS=192.168.0.1</literal>
  50. EOF</userinput></screen>
  51. <para>More than one DNS entry can be specified in the configuration file.</para>
  52. </sect3>
  53. <sect3 id="systemd-networkd-dhcp">
  54. <title>DHCP Configuration</title>
  55. <para>The command below creates a basic configuration file for
  56. DHCP setup:</para>
  57. <screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-dhcp-eth0.network &lt;&lt; "EOF"
  58. <literal>[Match]
  59. Name=eth0
  60. [Network]
  61. DHCP=yes</literal>
  62. EOF</userinput></screen>
  63. <para>Note that <command>systemd-networkd</command> can only handle
  64. DHCPv4. DHCPv6 support is a work in progress.</para>
  65. </sect3>
  66. </sect2>
  67. <sect2 id="resolv.conf">
  68. <title>Creating the /etc/resolv.conf File</title>
  69. <indexterm zone="resolv.conf">
  70. <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
  71. </indexterm>
  72. <para>If the system is going to be connected to the Internet, it will
  73. need some means of Domain Name Service (DNS) name resolution to
  74. resolve Internet domain names to IP addresses, and vice versa. This is
  75. best achieved by placing the IP address of the DNS server, available
  76. from the ISP or network administrator, into
  77. <filename>/etc/resolv.conf</filename>.</para>
  78. <para>When using <command>systemd-networkd</command> for network
  79. configuration, another daemon, <command>systemd-resolved</command>,
  80. is responsible for creating the <filename>/etc/resolv.conf</filename>
  81. file. It is, however, placed in a non-standard location which is
  82. writable since early boot, so it is necessary to create a symlink
  83. to it by running the following command:</para>
  84. <screen><userinput>ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
  85. <para>If static <filename>/etc/resolv.conf</filename> is desired, create
  86. it by running the following command:</para>
  87. <screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
  88. <literal># Begin /etc/resolv.conf
  89. domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
  90. nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
  91. nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
  92. # End /etc/resolv.conf</literal>
  93. EOF</userinput></screen>
  94. <para>The <varname>domain</varname> statement can be omitted
  95. or replaced with a <varname>search</varname> statement. See the man page for
  96. resolv.conf for more details.</para>
  97. <para>Replace <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
  98. with the IP address of the DNS most appropriate for the setup. There will
  99. often be more than one entry (requirements demand secondary servers for
  100. fallback capability). If you only need or want one DNS server, remove the
  101. second <emphasis>nameserver</emphasis> line from the file. The IP address
  102. may also be a router on the local network.</para>
  103. <note><para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para></note>
  104. </sect2>
  105. <sect2 id="ch-scripts-hostname">
  106. <title>Configuring the system hostname</title>
  107. <indexterm zone="ch-scripts-hostname">
  108. <primary sortas="d-hostname">hostname</primary>
  109. <secondary>configuring</secondary>
  110. </indexterm>
  111. <para>During the boot process, the file <filename>/etc/hostname</filename>
  112. is used for establishing the system's hostname.</para>
  113. <para>Create the <filename>/etc/hostname</filename> file and enter a
  114. hostname by running:</para>
  115. <screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
  116. <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
  117. name given to the computer. Do not enter the Fully Qualified Domain Name
  118. (FQDN) here. That information is put in the
  119. <filename>/etc/hosts</filename> file.</para>
  120. </sect2>
  121. <sect2 id="ch-scripts-hosts">
  122. <title>Customizing the /etc/hosts File</title>
  123. <indexterm zone="ch-scripts-hosts">
  124. <primary sortas="e-/etc/hosts">/etc/hosts</primary>
  125. </indexterm>
  126. <indexterm zone="ch-scripts-hosts">
  127. <primary sortas="d-localnet">localnet</primary>
  128. <secondary>/etc/hosts</secondary>
  129. </indexterm>
  130. <indexterm zone="ch-scripts-hosts">
  131. <primary sortas="d-network">network</primary>
  132. <secondary>/etc/hosts</secondary>
  133. </indexterm>
  134. <para>Decide on the IP address, fully-qualified domain name (FQDN), and
  135. possible aliases for use in the <filename>/etc/hosts</filename> file. The
  136. syntax is:</para>
  137. <screen><literal>IP_address myhost.example.org aliases</literal></screen>
  138. <para>Unless the computer is to be visible to the Internet (i.e., there is
  139. a registered domain and a valid block of assigned IP addresses&mdash;most
  140. users do not have this), make sure that the IP address is in the private
  141. network IP address range. Valid ranges are:</para>
  142. <screen><literal>Private Network Address Range Normal Prefix
  143. 10.0.0.1 - 10.255.255.254 8
  144. 172.x.0.1 - 172.x.255.254 16
  145. 192.168.y.1 - 192.168.y.254 24</literal></screen>
  146. <para>x can be any number in the range 16-31. y can be any number in the
  147. range 0-255.</para>
  148. <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
  149. this IP could be lfs.example.org.</para>
  150. <para>Even if not using a network card, a valid FQDN is still required.
  151. This is necessary for certain programs to operate correctly.</para>
  152. <para>Create the <filename>/etc/hosts</filename> file by running:</para>
  153. <screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
  154. <literal># Begin /etc/hosts (network card version)
  155. 127.0.0.1 localhost
  156. ::1 localhost
  157. <replaceable>&lt;192.168.0.2&gt;</replaceable> <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
  158. # End /etc/hosts (network card version)</literal>
  159. EOF</userinput></screen>
  160. <para>The <replaceable>&lt;192.168.0.2&gt;</replaceable> and
  161. <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> values need to be
  162. changed for specific uses or requirements (if assigned an IP address by a
  163. network/system administrator and the machine will be connected to an
  164. existing network). The optional alias name(s) can be omitted.</para>
  165. <para>If a network card is not going to be configured, create the
  166. <filename>/etc/hosts</filename> file by running:</para>
  167. <screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
  168. <literal># Begin /etc/hosts (no network card version)
  169. 127.0.0.1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost
  170. ::1 localhost
  171. # End /etc/hosts (no network card version)</literal>
  172. EOF</userinput></screen>
  173. <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents the IPv6 loopback interface.</para>
  174. </sect2>
  175. </sect1>