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