network.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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="sysv">
  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. <sect2>
  14. <title>Creating Network Interface Configuration Files</title>
  15. <para>Which interfaces are brought up and down by the network script
  16. usually depends on the files in <filename
  17. class="directory">/etc/sysconfig/</filename>. This directory should
  18. contain a file for each interface to be configured, such as
  19. <filename>ifconfig.xyz</filename>, where <quote>xyz</quote> should describe
  20. the network card. The interface name (e.g. eth0) is usually appropriate.
  21. Inside this file are attributes to this interface, such as its IP
  22. address(es), subnet masks, and so forth. It is necessary that the stem of
  23. the filename be <emphasis>ifconfig</emphasis>.</para>
  24. <note><para>If the procedure in the previous section was not used, udev
  25. will assign network card interface names based on system physical
  26. characteristics such as enp2s1. If you are not sure what your interface
  27. name is, you can always run <command>ip link</command> or <command>ls
  28. /sys/class/net</command> after you have booted your system.
  29. </para></note>
  30. <para>The following command creates a sample file for the
  31. <emphasis>eth0</emphasis> device with a static IP address:</para>
  32. <!-- jhalfs relies on the values for IFACE, IP, etc. If you want to change
  33. them, please inform the jhalfs maintainer(s). -->
  34. <screen><userinput>cd /etc/sysconfig/
  35. cat &gt; ifconfig.<replaceable>eth0</replaceable> &lt;&lt; "EOF"
  36. <literal>ONBOOT=<replaceable>yes</replaceable>
  37. IFACE=<replaceable>eth0</replaceable>
  38. SERVICE=<replaceable>ipv4-static</replaceable>
  39. IP=<replaceable>192.168.1.2</replaceable>
  40. GATEWAY=<replaceable>192.168.1.1</replaceable>
  41. PREFIX=<replaceable>24</replaceable>
  42. BROADCAST=<replaceable>192.168.1.255</replaceable></literal>
  43. EOF</userinput></screen>
  44. <para>The values in italics must be changed in every file to match
  45. the proper setup.</para>
  46. <para>If the <envar>ONBOOT</envar> variable is set to <quote>yes</quote> the
  47. System V network script will bring up the Network Interface Card (NIC) during
  48. the system boot process. If set to anything but <quote>yes</quote> the NIC
  49. will be ignored by the network script and not be automatically brought up.
  50. The interface can be manually started or stopped with the
  51. <command>ifup</command> and <command>ifdown</command> commands.</para>
  52. <para>The <envar>IFACE</envar> variable defines the interface name,
  53. for example, eth0. It is required for all network device configuration
  54. files. The filename extension must match this value.</para>
  55. <para>The <envar>SERVICE</envar> variable defines the method used for
  56. obtaining the IP address. The LFS-Bootscripts package has a modular IP
  57. assignment format, and creating additional files in the <filename
  58. class="directory">/lib/services/</filename> directory allows other IP
  59. assignment methods. This is commonly used for Dynamic Host Configuration
  60. Protocol (DHCP), which is addressed in the BLFS book.</para>
  61. <para>The <envar>GATEWAY</envar> variable should contain the default
  62. gateway IP address, if one is present. If not, then comment out the
  63. variable entirely.</para>
  64. <para>The <envar>PREFIX</envar> variable contains the number of
  65. bits used in the subnet. Each octet in an IP address is 8 bits. If the
  66. subnet's netmask is 255.255.255.0, then it is using the first three octets
  67. (24 bits) to specify the network number. If the netmask is 255.255.255.240,
  68. it would be using the first 28 bits. Prefixes longer than 24 bits are
  69. commonly used by DSL and cable-based Internet Service Providers (ISPs).
  70. In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
  71. <envar>PREFIX</envar> variable according to your specific subnet.
  72. If omitted, the PREFIX defaults to 24.</para>
  73. <para>For more information see the <command>ifup</command> man page.</para>
  74. </sect2>
  75. <sect2 id="resolv.conf">
  76. <title>Creating the /etc/resolv.conf File</title>
  77. <indexterm zone="resolv.conf">
  78. <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
  79. </indexterm>
  80. <para>The system will need some means of obtaining Domain Name Service
  81. (DNS) name resolution to resolve Internet domain names to IP addresses, and
  82. vice versa. This is best achieved by placing the IP address of the DNS
  83. server, available from the ISP or network administrator, into
  84. <filename>/etc/resolv.conf</filename>. Create the file by running the
  85. following:</para>
  86. <screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
  87. <literal># Begin /etc/resolv.conf
  88. domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
  89. nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
  90. nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
  91. # End /etc/resolv.conf</literal>
  92. EOF</userinput></screen>
  93. <para>The <varname>domain</varname> statement can be omitted
  94. or replaced with a <varname>search</varname> statement. See the man page for
  95. resolv.conf for more details.</para>
  96. <para>Replace <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
  97. with the IP address of the DNS most appropriate for the setup. There will
  98. often be more than one entry (requirements demand secondary servers for
  99. fallback capability). If you only need or want one DNS server, remove the
  100. second <emphasis>nameserver</emphasis> line from the file. The IP address
  101. may also be a router on the local network.</para>
  102. <note>
  103. <para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para>
  104. </note>
  105. </sect2>
  106. <sect2 id="ch-config-hostname">
  107. <title>Configuring the system hostname</title>
  108. <indexterm zone="ch-config-hostname">
  109. <primary sortas="d-hostname">hostname</primary>
  110. <secondary>configuring</secondary>
  111. </indexterm>
  112. <para>During the boot process, the file <filename>/etc/hostname</filename>
  113. is used for establishing the system's hostname.</para>
  114. <para>Create the <filename>/etc/hostname</filename> file and enter a
  115. hostname by running:</para>
  116. <screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
  117. <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
  118. name given to the computer. Do not enter the Fully Qualified Domain Name
  119. (FQDN) here. That information is put in the
  120. <filename>/etc/hosts</filename> file.</para>
  121. </sect2>
  122. <sect2 id="ch-config-hosts">
  123. <title>Customizing the /etc/hosts File</title>
  124. <indexterm zone="ch-config-hosts">
  125. <primary sortas="e-/etc/hosts">/etc/hosts</primary>
  126. </indexterm>
  127. <indexterm zone="ch-config-hosts">
  128. <primary sortas="d-localnet">localnet</primary>
  129. <secondary>/etc/hosts</secondary>
  130. </indexterm>
  131. <indexterm zone="ch-config-hosts">
  132. <primary sortas="d-network">network</primary>
  133. <secondary>/etc/hosts</secondary>
  134. </indexterm>
  135. <para>Decide on the IP address, fully-qualified domain name (FQDN), and
  136. possible aliases for use in the <filename>/etc/hosts</filename> file. The
  137. syntax is:</para>
  138. <screen><literal>IP_address myhost.example.org aliases</literal></screen>
  139. <para>Unless the computer is to be visible to the Internet (i.e., there is
  140. a registered domain and a valid block of assigned IP addresses&mdash;most
  141. users do not have this), make sure that the IP address is in the private
  142. network IP address range. Valid ranges are:</para>
  143. <screen><literal>Private Network Address Range Normal Prefix
  144. 10.0.0.1 - 10.255.255.254 8
  145. 172.x.0.1 - 172.x.255.254 16
  146. 192.168.y.1 - 192.168.y.254 24</literal></screen>
  147. <para>x can be any number in the range 16-31. y can be any number in the
  148. range 0-255.</para>
  149. <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
  150. this IP could be lfs.example.org.</para>
  151. <para>Even if not using a network card, a valid FQDN is still required.
  152. This is necessary for certain programs to operate correctly.</para>
  153. <para>Create the <filename>/etc/hosts</filename> file by running:</para>
  154. <screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
  155. <literal># Begin /etc/hosts
  156. 127.0.0.1 localhost.localdomain localhost
  157. 127.0.1.1 <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable>
  158. <replaceable>&lt;192.168.1.1&gt;</replaceable> <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> <replaceable>[alias1] [alias2 ...]</replaceable>
  159. ::1 localhost ip6-localhost ip6-loopback
  160. ff02::1 ip6-allnodes
  161. ff02::2 ip6-allrouters
  162. # End /etc/hosts</literal>
  163. EOF</userinput></screen>
  164. <para>The <replaceable>&lt;192.168.1.1&gt;</replaceable>,
  165. <replaceable>&lt;FQDN&gt;</replaceable>, and
  166. <replaceable>&lt;HOSTNAME&gt;</replaceable> values need to be
  167. changed for specific uses or requirements (if assigned an IP address by a
  168. network/system administrator and the machine will be connected to an
  169. existing network). The optional alias name(s) can be omitted.</para>
  170. <!-- This is not very useful
  171. <para>If a network card is not going to be configured, create the
  172. <filename>/etc/hosts</filename> file by running:</para>
  173. <screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
  174. <literal># Begin /etc/hosts (no network card version)
  175. 127.0.0.1 localhost
  176. 127.0.1.1 <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable>
  177. ::1 localhost ip6-localhost ip6-loopback
  178. ff02::1 ip6-allnodes
  179. ff02::2 ip6-allrouters
  180. # End /etc/hosts (no network card version)</literal>
  181. EOF</userinput></screen> -->
  182. </sect2>
  183. </sect1>