network.xml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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>Creating Network Interface Configuration Files</title>
  17. <para>Which interfaces are brought up and down by the network script
  18. depends on the files in <filename
  19. class="directory">/etc/sysconfig/</filename>. This directory should
  20. contain a file for each interface to be configured, such as
  21. <filename>ifconfig.xyz</filename>, where <quote>xyz</quote> is
  22. required to be a Network Card Interface name (e.g. eth0).
  23. Inside this file are attributes to this interface, such as its IP
  24. address(es), subnet masks, and so forth. It is necessary that
  25. the stem of the filename be <emphasis>ifconfig</emphasis>.</para>
  26. <note><para>Udev may assign random Network Card Interface names
  27. for some network cards such as enp2s1. If you are not sure what
  28. your Network Card Interface name is, you can always run
  29. <command>ip l</command> after you have booted your system. Again,
  30. it is important that <filename>ifconfig.xyz</filename> is named
  31. after correct Network Card Interface name (e.g.
  32. <filename>ifconfig.enp2s1</filename> or
  33. <filename>ifconfig.eth0</filename>) or Systemd will fail to bring
  34. up your network interface.</para></note>
  35. <para>The following command creates a sample file for the
  36. <emphasis>eth0</emphasis> device with a static IP address:</para>
  37. <screen><userinput>cd /etc/sysconfig/
  38. cat &gt; ifconfig.eth0 &lt;&lt; "EOF"
  39. <literal>IFACE=eth0
  40. SERVICE=ipv4-static
  41. IP=192.168.1.1
  42. GATEWAY=192.168.1.2
  43. PREFIX=24
  44. BROADCAST=192.168.1.255</literal>
  45. EOF</userinput></screen>
  46. <para>The values of these variables must be changed in every file to match
  47. the proper setup.</para>
  48. <para>The <envar>IFACE</envar> variable defines the interface name,
  49. for example, eth0. It is required for all network device configuration
  50. files.</para>
  51. <para>The <envar>SERVICE</envar> variable defines the method used for
  52. obtaining the IP address. The LFS-Network-Scripts package has a modular
  53. IP assignment format, and creating additional files in the <filename
  54. class="directory">/lib/services/</filename> directory allows other IP
  55. assignment methods. This is commonly used for Dynamic Host Configuration
  56. Protocol (DHCP), which is addressed in the BLFS book.</para>
  57. <para>The <envar>GATEWAY</envar> variable should contain the default
  58. gateway IP address, if one is present. If not, then comment out the
  59. variable entirely.</para>
  60. <para>The <envar>PREFIX</envar> variable contains the number of
  61. bits used in the subnet. Each octet in an IP address is 8 bits. If the
  62. subnet's netmask is 255.255.255.0, then it is using the first three octets
  63. (24 bits) to specify the network number. If the netmask is 255.255.255.240,
  64. it would be using the first 28 bits. Prefixes longer than 24 bits are
  65. commonly used by DSL and cable-based Internet Service Providers (ISPs).
  66. In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
  67. <envar>PREFIX</envar> variable according to your specific subnet.
  68. If omitted, the PREFIX defaults to 24.</para>
  69. <para>For more information see the <command>ifup</command> man page.</para>
  70. </sect2>
  71. <sect2>
  72. <title>Configuring the Network Interface Card at boot</title>
  73. <para>Enabling of the Network Interface Card configuration is
  74. done per interface. To enable Network Interface Card
  75. configuration at boot, run:</para>
  76. <screen><userinput>systemctl enable ifupdown@eth0</userinput></screen>
  77. <para>To disable previously enabled Network Interface
  78. Card configuration at boot, run:</para>
  79. <screen><userinput>systemctl disable ifupdown@eth0</userinput></screen>
  80. <para>To manually start the Network Interface Card configuration,
  81. run:</para>
  82. <screen><userinput>systemctl start ifupdown@eth0</userinput></screen>
  83. <para>Replace eth0 with the correct Network Interface Card
  84. name as described on the beginning of this page.</para>
  85. </sect2>
  86. <sect2 id="resolv.conf">
  87. <title>Creating the /etc/resolv.conf File</title>
  88. <indexterm zone="resolv.conf">
  89. <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
  90. </indexterm>
  91. <para>If the system is going to be connected to the Internet, it will
  92. need some means of Domain Name Service (DNS) name resolution to
  93. resolve Internet domain names to IP addresses, and vice versa. This is
  94. best achieved by placing the IP address of the DNS server, available
  95. from the ISP or network administrator, into
  96. <filename>/etc/resolv.conf</filename>. Create the file by running the
  97. following:</para>
  98. <screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
  99. <literal># Begin /etc/resolv.conf
  100. domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
  101. nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
  102. nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
  103. # End /etc/resolv.conf</literal>
  104. EOF</userinput></screen>
  105. <para>The <varname>domain</varname> statement can be omitted
  106. or replaced with a <varname>search</varname> statement. See the man page for
  107. resolv.conf for more details.</para>
  108. <para>Replace <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
  109. with the IP address of the DNS most appropriate for the setup. There will
  110. often be more than one entry (requirements demand secondary servers for
  111. fallback capability). If you only need or want one DNS server, remove the
  112. second <emphasis>nameserver</emphasis> line from the file. The IP address
  113. may also be a router on the local network.</para>
  114. <note><para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para></note>
  115. </sect2>
  116. </sect1>