network.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/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>Instructions in this section are optional if you have only one
  23. network card.</para>
  24. <para>With Udev and modular network drivers, the network interface numbering
  25. is not persistent across reboots by default, because the drivers are loaded
  26. in parallel and, thus, in random order. For example, on a computer having
  27. two network cards made by Intel and Realtek, the network card manufactured
  28. by Intel may become <filename class="devicefile">eth0</filename> and the
  29. Realtek card becomes <filename class="devicefile">eth1</filename>. In some
  30. cases, after a reboot the cards get renumbered the other way around. To
  31. avoid this, create Udev rules that assign stable names to network cards
  32. based on their MAC addresses.</para>
  33. <para>First, find out the MAC addresses of your network cards:</para>
  34. <screen role="nodump"><userinput>grep -H . /sys/class/net/*/address</userinput></screen>
  35. <para>For each network card (but not for the loopback interface),
  36. invent a descriptive name, such as <quote>realtek</quote>, and create
  37. Udev rules similar to the following:</para>
  38. <screen role="nodump"><userinput>cat &gt; /etc/udev/rules.d/26-network.rules &lt;&lt; "EOF"
  39. <literal>ACTION=="add", SUBSYSTEM=="net", SYSFS{address}=="<replaceable>52:54:00:12:34:56</replaceable>", NAME="<replaceable>realtek</replaceable>"
  40. ACTION=="add", SUBSYSTEM=="net", SYSFS{address}=="<replaceable>00:a0:c9:78:9a:bc</replaceable>", NAME="<replaceable>intel</replaceable>"</literal>
  41. EOF</userinput></screen>
  42. <para>These rules will always rename the network cards to
  43. <quote>realtek</quote> and <quote>intel</quote>, independently of the
  44. original numbering provided by the kernel. Use these names instead of
  45. <quote>eth0</quote> in the network interface configuration files created
  46. below.</para>
  47. <note>
  48. <para>Persistent names must be different from the default network
  49. interface names assigned by the kernel.</para>
  50. </note>
  51. </sect2>
  52. <sect2>
  53. <title>Creating Network Interface Configuration Files</title>
  54. <para>Which interfaces are brought up and down by the network script
  55. depends on the files and directories in the <filename
  56. class="directory">/etc/sysconfig/network-devices</filename> hierarchy.
  57. This directory should contain a sub-directory for each interface to be
  58. configured, such as <filename>ifconfig.xyz</filename>, where
  59. <quote>xyz</quote> is a network interface name. Inside this directory
  60. would be files defining the attributes to this interface, such as its IP
  61. address(es), subnet masks, and so forth.</para>
  62. <para>The following command creates a sample <filename>ipv4</filename>
  63. file for the <emphasis>eth0</emphasis> device:</para>
  64. <screen><userinput>cd /etc/sysconfig/network-devices &amp;&amp;
  65. mkdir -v ifconfig.eth0 &amp;&amp;
  66. cat &gt; ifconfig.eth0/ipv4 &lt;&lt; "EOF"
  67. <literal>ONBOOT=yes
  68. SERVICE=ipv4-static
  69. IP=192.168.1.1
  70. GATEWAY=192.168.1.2
  71. PREFIX=24
  72. BROADCAST=192.168.1.255</literal>
  73. EOF</userinput></screen>
  74. <para>The values of these variables must be changed in every file to match
  75. the proper setup. If the <envar>ONBOOT</envar> variable is set to
  76. <quote>yes</quote> the network script will bring up the Network Interface
  77. Card (NIC) during booting of the system. If set to anything but
  78. <quote>yes</quote> the NIC will be ignored by the network script and not
  79. be brought up.</para>
  80. <para>The <envar>SERVICE</envar> variable defines the method used for
  81. obtaining the IP address. The LFS-Bootscripts package has a modular IP
  82. assignment format, and creating additional files in the <filename
  83. class="directory">/etc/sysconfig/network-devices/services</filename>
  84. directory allows other IP assignment methods. This is commonly used for
  85. Dynamic Host Configuration Protocol (DHCP), which is addressed in the
  86. BLFS book.</para>
  87. <para>The <envar>GATEWAY</envar> variable should contain the default
  88. gateway IP address, if one is present. If not, then comment out the
  89. variable entirely.</para>
  90. <para>The <envar>PREFIX</envar> variable needs to contain the number of
  91. bits used in the subnet. Each octet in an IP address is 8 bits. If the
  92. subnet's netmask is 255.255.255.0, then it is using the first three octets
  93. (24 bits) to specify the network number. If the netmask is 255.255.255.240,
  94. it would be using the first 28 bits. Prefixes longer than 24 bits are
  95. commonly used by DSL and cable-based Internet Service Providers (ISPs).
  96. In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
  97. <envar>PREFIX</envar> variable according to your specific subnet.</para>
  98. </sect2>
  99. <sect2 id="resolv.conf">
  100. <title>Creating the /etc/resolv.conf File</title>
  101. <indexterm zone="resolv.conf">
  102. <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
  103. </indexterm>
  104. <para>If the system is going to be connected to the Internet, it will
  105. need some means of Domain Name Service (DNS) name resolution to
  106. resolve Internet domain names to IP addresses, and vice versa. This is
  107. best achieved by placing the IP address of the DNS server, available
  108. from the ISP or network administrator, into
  109. <filename>/etc/resolv.conf</filename>. Create the file by running the
  110. following:</para>
  111. <screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
  112. <literal># Begin /etc/resolv.conf
  113. domain {<replaceable>[Your Domain Name]</replaceable>}
  114. nameserver <replaceable>[IP address of your primary nameserver]</replaceable>
  115. nameserver <replaceable>[IP address of your secondary nameserver]</replaceable>
  116. # End /etc/resolv.conf</literal>
  117. EOF</userinput></screen>
  118. <para>Replace <replaceable>[IP address of the nameserver]</replaceable>
  119. with the IP address of the DNS most appropriate for the setup. There will
  120. often be more than one entry (requirements demand secondary servers for
  121. fallback capability). If you only need or want one DNS server, remove the
  122. second <emphasis>nameserver</emphasis> line from the file. The IP address
  123. may also be a router on the local network.</para>
  124. </sect2>
  125. </sect1>