network.xml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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>Configuring the network Script</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. <para>If a network card will not be used, there is likely no need to
  16. create any configuration files relating to network cards. If that is
  17. the case, remove the <filename class="symlink">network</filename>
  18. symlinks from all run-level directories (<filename
  19. class="directory">/etc/rc.d/rc*.d</filename>).</para>
  20. <sect2>
  21. <title>Creating stable names for network interfaces</title>
  22. <para>With Udev and modular network drivers, the network interface numbering
  23. is not persistent across reboots by default, because the drivers are loaded
  24. in parallel and, thus, in random order. For example, on a computer having
  25. two network cards made by Intel and Realtek, the network card manufactured
  26. by Intel may become <filename class="devicefile">eth0</filename> and the
  27. Realtek card becomes <filename class="devicefile">eth1</filename>. In some
  28. cases, after a reboot the cards get renumbered the other way around. To
  29. avoid this, Udev comes with a script and some rules to assign stable names
  30. to network cards based on their MAC address.</para>
  31. <para>Pre-generate the rules to ensure the same names get assigned to the
  32. same devices at every boot, including the first:</para>
  33. <screen><userinput>for NIC in /sys/class/net/* ; do
  34. INTERFACE=${NIC##*/} udevadm test --action=add --subsystem=net $NIC
  35. done</userinput></screen>
  36. <para>Now, inspect the <filename>/etc/udev/rules.d/70-persistent-net.rules</filename>
  37. file, to find out which name was assigned to which network device:</para>
  38. <screen><userinput>cat /etc/udev/rules.d/70-persistent-net.rules</userinput></screen>
  39. <para>The file begins with a comment block followed by two lines for each
  40. NIC. The first line for each NIC is a commented description showing its
  41. hardware IDs (e.g. its PCI vendor and device IDs, if it's a PCI card),
  42. along with its driver in parentheses, if the driver can be found. Neither
  43. the hardware ID nor the driver is used to determine which name to give an
  44. interface; this information is only for reference. The second line is the
  45. Udev rule that matches this NIC and actually assigns it a name.</para>
  46. <para>All Udev rules are made up of several keys, separated by commas and
  47. optional whitespace. This rule's keys and an explanation of each of them
  48. are as follows:</para>
  49. <itemizedlist>
  50. <listitem>
  51. <para><literal>SUBSYSTEM=="net"</literal> - This tells Udev to ignore
  52. devices that are not network cards.</para>
  53. </listitem>
  54. <listitem>
  55. <para><literal>ACTION=="add"</literal> - This tells Udev to ignore this
  56. rule for a uevent that isn't an add ("remove" and "change" uevents also
  57. happen, but don't need to rename network interfaces).</para>
  58. </listitem>
  59. <listitem>
  60. <para><literal>DRIVERS=="?*"</literal> - This exists so that Udev will
  61. ignore VLAN or bridge sub-interfaces (because these sub-interfaces do
  62. not have drivers). These sub-interfaces are skipped because the name
  63. that would be assigned would collide with their parent devices.</para>
  64. </listitem>
  65. <listitem>
  66. <para><literal>ATTR{address}</literal> - The value of this key is the
  67. NIC's MAC address.</para>
  68. </listitem>
  69. <listitem>
  70. <para><literal>ATTR{type}=="1"</literal> - This ensures the rule only
  71. matches the primary interface in the case of certain wireless drivers,
  72. which create multiple virtual interfaces. The secondary interfaces are
  73. skipped for the same reason that VLAN and bridge sub-interfaces are
  74. skipped: there would be a name collision otherwise.</para>
  75. </listitem>
  76. <listitem>
  77. <para><literal>KERNEL=="eth*"</literal> - This key was added to the
  78. Udev rule generator to handle machines that have multiple network
  79. interfaces, all with the same MAC address (the PS3 is one such
  80. machine). If the independent interfaces have different basenames,
  81. this key will allow Udev to tell them apart. This is generally not
  82. necessary for most Linux From Scratch users, but does not hurt.</para>
  83. </listitem>
  84. <listitem>
  85. <para><literal>NAME</literal> - The value of this key is the name that
  86. Udev will assign to this interface.</para>
  87. </listitem>
  88. </itemizedlist>
  89. <para>The value of <literal>NAME</literal> is the important part. Make sure
  90. you know which name has been assigned to each of your network cards before
  91. proceeding, and be sure to use that <literal>NAME</literal> value when
  92. creating your configuration files below.</para>
  93. </sect2>
  94. <sect2>
  95. <title>Creating Network Interface Configuration Files</title>
  96. <para>Which interfaces are brought up and down by the network script
  97. depends on the files and directories in the <filename
  98. class="directory">/etc/sysconfig/network-devices</filename> hierarchy.
  99. This directory should contain a sub-directory for each interface to be
  100. configured, such as <filename>ifconfig.xyz</filename>, where
  101. <quote>xyz</quote> is a network interface name. Inside this directory
  102. would be files defining the attributes to this interface, such as its IP
  103. address(es), subnet masks, and so forth.</para>
  104. <para>The following command creates a sample <filename>ipv4</filename>
  105. file for the <emphasis>eth0</emphasis> device:</para>
  106. <screen><userinput>cd /etc/sysconfig/network-devices
  107. mkdir -v ifconfig.eth0
  108. cat &gt; ifconfig.eth0/ipv4 &lt;&lt; "EOF"
  109. <literal>ONBOOT=yes
  110. SERVICE=ipv4-static
  111. IP=192.168.1.1
  112. GATEWAY=192.168.1.2
  113. PREFIX=24
  114. BROADCAST=192.168.1.255</literal>
  115. EOF</userinput></screen>
  116. <para>The values of these variables must be changed in every file to match
  117. the proper setup. If the <envar>ONBOOT</envar> variable is set to
  118. <quote>yes</quote> the network script will bring up the Network Interface
  119. Card (NIC) during booting of the system. If set to anything but
  120. <quote>yes</quote> the NIC will be ignored by the network script and not
  121. be brought up.</para>
  122. <para>The <envar>SERVICE</envar> variable defines the method used for
  123. obtaining the IP address. The LFS-Bootscripts package has a modular IP
  124. assignment format, and creating additional files in the <filename
  125. class="directory">/etc/sysconfig/network-devices/services</filename>
  126. directory allows other IP assignment methods. This is commonly used for
  127. Dynamic Host Configuration Protocol (DHCP), which is addressed in the
  128. BLFS book.</para>
  129. <para>The <envar>GATEWAY</envar> variable should contain the default
  130. gateway IP address, if one is present. If not, then comment out the
  131. variable entirely.</para>
  132. <para>The <envar>PREFIX</envar> variable needs to contain the number of
  133. bits used in the subnet. Each octet in an IP address is 8 bits. If the
  134. subnet's netmask is 255.255.255.0, then it is using the first three octets
  135. (24 bits) to specify the network number. If the netmask is 255.255.255.240,
  136. it would be using the first 28 bits. Prefixes longer than 24 bits are
  137. commonly used by DSL and cable-based Internet Service Providers (ISPs).
  138. In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
  139. <envar>PREFIX</envar> variable according to your specific subnet.</para>
  140. </sect2>
  141. <sect2 id="resolv.conf">
  142. <title>Creating the /etc/resolv.conf File</title>
  143. <indexterm zone="resolv.conf">
  144. <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
  145. </indexterm>
  146. <para>If the system is going to be connected to the Internet, it will
  147. need some means of Domain Name Service (DNS) name resolution to
  148. resolve Internet domain names to IP addresses, and vice versa. This is
  149. best achieved by placing the IP address of the DNS server, available
  150. from the ISP or network administrator, into
  151. <filename>/etc/resolv.conf</filename>. Create the file by running the
  152. following:</para>
  153. <screen><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>Replace <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
  161. with the IP address of the DNS most appropriate for the setup. There will
  162. often be more than one entry (requirements demand secondary servers for
  163. fallback capability). If you only need or want one DNS server, remove the
  164. second <emphasis>nameserver</emphasis> line from the file. The IP address
  165. may also be a router on the local network.</para>
  166. </sect2>
  167. </sect1>