network.xml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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>/lib/udev/write_net_rules all_interfaces</userinput></screen>
  34. <para>Now, inspect the <filename>/etc/udev/rules.d/70-persistent-net.rules</filename>
  35. file, to find out which name was assigned to which network device:</para>
  36. <screen><userinput>cat /etc/udev/rules.d/70-persistent-net.rules</userinput></screen>
  37. <para>Each NIC takes up two lines in the file. The first line is a
  38. description of the NIC itself, showing its hardware IDs (e.g. its PCI
  39. vendor and device IDs, if it's a PCI card), along with its driver in
  40. parentheses, if the driver can be found. This line is a comment; neither
  41. the hardware ID nor the driver is used to determine which name to give an
  42. interface. The second line is the Udev rule that matches this NIC and
  43. actually assigns it a name.</para>
  44. <para>All Udev rules are made up of several keys, separated by commas and
  45. optional whitespace. This rule's keys and an explanations of each of them
  46. are as follows:</para>
  47. <itemizedlist>
  48. <listitem>
  49. <para><literal>SUBSYSTEM=="net"</literal> - This tells Udev to ignore
  50. devices that are not network cards.</para>
  51. </listitem>
  52. <listitem>
  53. <para><literal>DRIVERS=="?*"</literal> - This exists so that Udev will
  54. ignore VLAN or bridge sub-interfaces (because these sub-interfaces do
  55. not have drivers). These sub-interfaces are skipped because the name
  56. that would be assigned would collide with their parent devices.</para>
  57. </listitem>
  58. <listitem>
  59. <para><literal>ATTRS{type}=="1"</literal> - Optional. This key will
  60. only be added if this NIC is a wireless NIC whose driver creates
  61. multiple virtual interfaces; it ensures the rule only matches the
  62. primary interface. The secondary interfaces are not matched for the
  63. same reason that VLAN and bridge sub-interfaces are not matched: there
  64. would be a name collision.</para>
  65. </listitem>
  66. <listitem>
  67. <para><literal>ATTRS{address}</literal> - The value of this key is the
  68. NIC's MAC address.</para>
  69. </listitem>
  70. <listitem>
  71. <para><literal>NAME</literal> - The value of this key is the name that
  72. Udev will assign to this interface.</para>
  73. </listitem>
  74. </itemizedlist>
  75. <para>The value of <literal>NAME</literal> is the important part. Make sure
  76. you know which name has been assigned to each of your network cards before
  77. proceeding, and be sure to use that <literal>NAME</literal> value when
  78. creating your configuration files below.</para>
  79. </sect2>
  80. <sect2>
  81. <title>Creating Network Interface Configuration Files</title>
  82. <para>Which interfaces are brought up and down by the network script
  83. depends on the files and directories in the <filename
  84. class="directory">/etc/sysconfig/network-devices</filename> hierarchy.
  85. This directory should contain a sub-directory for each interface to be
  86. configured, such as <filename>ifconfig.xyz</filename>, where
  87. <quote>xyz</quote> is a network interface name. Inside this directory
  88. would be files defining the attributes to this interface, such as its IP
  89. address(es), subnet masks, and so forth.</para>
  90. <para>The following command creates a sample <filename>ipv4</filename>
  91. file for the <emphasis>eth0</emphasis> device:</para>
  92. <screen><userinput>cd /etc/sysconfig/network-devices &amp;&amp;
  93. mkdir -v ifconfig.eth0 &amp;&amp;
  94. cat &gt; ifconfig.eth0/ipv4 &lt;&lt; "EOF"
  95. <literal>ONBOOT=yes
  96. SERVICE=ipv4-static
  97. IP=192.168.1.1
  98. GATEWAY=192.168.1.2
  99. PREFIX=24
  100. BROADCAST=192.168.1.255</literal>
  101. EOF</userinput></screen>
  102. <para>The values of these variables must be changed in every file to match
  103. the proper setup. If the <envar>ONBOOT</envar> variable is set to
  104. <quote>yes</quote> the network script will bring up the Network Interface
  105. Card (NIC) during booting of the system. If set to anything but
  106. <quote>yes</quote> the NIC will be ignored by the network script and not
  107. be brought up.</para>
  108. <para>The <envar>SERVICE</envar> variable defines the method used for
  109. obtaining the IP address. The LFS-Bootscripts package has a modular IP
  110. assignment format, and creating additional files in the <filename
  111. class="directory">/etc/sysconfig/network-devices/services</filename>
  112. directory allows other IP assignment methods. This is commonly used for
  113. Dynamic Host Configuration Protocol (DHCP), which is addressed in the
  114. BLFS book.</para>
  115. <para>The <envar>GATEWAY</envar> variable should contain the default
  116. gateway IP address, if one is present. If not, then comment out the
  117. variable entirely.</para>
  118. <para>The <envar>PREFIX</envar> variable needs to contain the number of
  119. bits used in the subnet. Each octet in an IP address is 8 bits. If the
  120. subnet's netmask is 255.255.255.0, then it is using the first three octets
  121. (24 bits) to specify the network number. If the netmask is 255.255.255.240,
  122. it would be using the first 28 bits. Prefixes longer than 24 bits are
  123. commonly used by DSL and cable-based Internet Service Providers (ISPs).
  124. In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
  125. <envar>PREFIX</envar> variable according to your specific subnet.</para>
  126. </sect2>
  127. <sect2 id="resolv.conf">
  128. <title>Creating the /etc/resolv.conf File</title>
  129. <indexterm zone="resolv.conf">
  130. <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
  131. </indexterm>
  132. <para>If the system is going to be connected to the Internet, it will
  133. need some means of Domain Name Service (DNS) name resolution to
  134. resolve Internet domain names to IP addresses, and vice versa. This is
  135. best achieved by placing the IP address of the DNS server, available
  136. from the ISP or network administrator, into
  137. <filename>/etc/resolv.conf</filename>. Create the file by running the
  138. following:</para>
  139. <screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
  140. <literal># Begin /etc/resolv.conf
  141. domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
  142. nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
  143. nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
  144. # End /etc/resolv.conf</literal>
  145. EOF</userinput></screen>
  146. <para>Replace <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
  147. with the IP address of the DNS most appropriate for the setup. There will
  148. often be more than one entry (requirements demand secondary servers for
  149. fallback capability). If you only need or want one DNS server, remove the
  150. second <emphasis>nameserver</emphasis> line from the file. The IP address
  151. may also be a router on the local network.</para>
  152. </sect2>
  153. </sect1>