source: chapter07/network.xml@ 94cea1d

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 94cea1d was 94cea1d, checked in by Bruce Dubbs <bdubbs@…>, 7 years ago

Remove section disussing configuration without a network card.
Update boot scripts to unmount network file systems before bringing down the network.

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@11260 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 10.2 KB
Line 
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
8<sect1 id="ch-scripts-network" revision="sysv">
9 <?dbhtml filename="network.html"?>
10
11 <title>General Network Configuration</title>
12
13 <indexterm zone="ch-scripts-network">
14 <primary sortas="d-network">network</primary>
15 <secondary>configuring</secondary></indexterm>
16<!--
17 <para>This section only applies if a network card is to be
18 configured.</para>
19
20 <para>If a network card will not be used, there is likely no need to create
21 any configuration files relating to network cards. If that is the case, you
22 will need to remove the <filename class="symlink">network</filename> symlinks
23 from all run-level directories (<filename
24 class="directory">/etc/rc.d/rc*.d</filename>) after the bootscripts are
25 installed in <xref linkend="ch-scripts-bootscripts"/>.</para>
26-->
27 <sect2>
28 <title>Creating Network Interface Configuration Files</title>
29
30 <para>Which interfaces are brought up and down by the network script
31 usually depends on the files in <filename
32 class="directory">/etc/sysconfig/</filename>. This directory should
33 contain a file for each interface to be configured, such as
34 <filename>ifconfig.xyz</filename>, where <quote>xyz</quote> should describe
35 the network card. The interface name (e.g. eth0) is usually appropriate.
36 Inside this file are attributes to this interface, such as its IP
37 address(es), subnet masks, and so forth. It is necessary that the stem of
38 the filename be <emphasis>ifconfig</emphasis>.</para>
39
40 <note><para>If the procedure in the previous section was not used, Udev
41 will assign network card interface names based on system physical
42 characteristics such as enp2s1. If you are not sure what your interface
43 name is, you can always run <command>ip link</command> or <command>ls
44 /sys/class/net</command> after you have booted your system.
45 </para></note>
46
47 <para>The following command creates a sample file for the
48 <emphasis>eth0</emphasis> device with a static IP address:</para>
49
50<screen><userinput>cd /etc/sysconfig/
51cat &gt; ifconfig.eth0 &lt;&lt; "EOF"
52<literal>ONBOOT=yes
53IFACE=eth0
54SERVICE=ipv4-static
55IP=192.168.1.2
56GATEWAY=192.168.1.1
57PREFIX=24
58BROADCAST=192.168.1.255</literal>
59EOF</userinput></screen>
60
61 <para>The values of these variables must be changed in every file to match
62 the proper setup.</para>
63
64 <para>If the <envar>ONBOOT</envar> variable is set to <quote>yes</quote> the
65 System V network script will bring up the Network Interface Card (NIC) during
66 booting of the system. If set to anything but <quote>yes</quote> the NIC
67 will be ignored by the network script and not be automatically brought up.
68 The interface can be manually started or stopped with the
69 <command>ifup</command> and <command>ifdown</command> commands.</para>
70
71 <para>The <envar>IFACE</envar> variable defines the interface name,
72 for example, eth0. It is required for all network device configuration
73 files. </para>
74
75 <para>The <envar>SERVICE</envar> variable defines the method used for
76 obtaining the IP address. The LFS-Bootscripts package has a modular IP
77 assignment format, and creating additional files in the <filename
78 class="directory">/lib/services/</filename> directory allows other IP
79 assignment methods. This is commonly used for Dynamic Host Configuration
80 Protocol (DHCP), which is addressed in the BLFS book.</para>
81
82 <para>The <envar>GATEWAY</envar> variable should contain the default
83 gateway IP address, if one is present. If not, then comment out the
84 variable entirely.</para>
85
86 <para>The <envar>PREFIX</envar> variable contains the number of
87 bits used in the subnet. Each octet in an IP address is 8 bits. If the
88 subnet's netmask is 255.255.255.0, then it is using the first three octets
89 (24 bits) to specify the network number. If the netmask is 255.255.255.240,
90 it would be using the first 28 bits. Prefixes longer than 24 bits are
91 commonly used by DSL and cable-based Internet Service Providers (ISPs).
92 In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
93 <envar>PREFIX</envar> variable according to your specific subnet.
94 If omitted, the PREFIX defaults to 24.</para>
95
96 <para>For more information see the <command>ifup</command> man page.</para>
97
98 </sect2>
99 <sect2 id="resolv.conf">
100 <title>Creating the /etc/resolv.conf File</title>
101
102 <indexterm zone="resolv.conf">
103 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
104 </indexterm>
105
106 <para>The system will need some means of obtaining Domain Name Service
107 (DNS) name resolution to resolve Internet domain names to IP addresses, and
108 vice versa. This is best achieved by placing the IP address of the DNS
109 server, available from the ISP or network administrator, into
110 <filename>/etc/resolv.conf</filename>. Create the file by running the
111 following:</para>
112
113<screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
114<literal># Begin /etc/resolv.conf
115
116domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
117nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
118nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
119
120# End /etc/resolv.conf</literal>
121EOF</userinput></screen>
122
123 <para>The <varname>domain</varname> statement can be omitted
124 or replaced with a <varname>search</varname> statement. See the man page for
125 resolv.conf for more details.</para>
126
127 <para>Replace <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
128 with the IP address of the DNS most appropriate for the setup. There will
129 often be more than one entry (requirements demand secondary servers for
130 fallback capability). If you only need or want one DNS server, remove the
131 second <emphasis>nameserver</emphasis> line from the file. The IP address
132 may also be a router on the local network.</para>
133
134 <note>
135 <para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para>
136 </note>
137
138 </sect2>
139
140 <sect2 id="ch-scripts-hostname">
141 <title>Configuring the system hostname</title>
142
143 <indexterm zone="ch-scripts-hostname">
144 <primary sortas="d-hostname">hostname</primary>
145 <secondary>configuring</secondary>
146 </indexterm>
147
148 <para>During the boot process, the file <filename>/etc/hostname</filename>
149 is used for establishing the system's hostname.</para>
150
151 <para>Create the <filename>/etc/hostname</filename> file and enter a
152 hostname by running:</para>
153
154<screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
155
156 <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
157 name given to the computer. Do not enter the Fully Qualified Domain Name
158 (FQDN) here. That information is put in the
159 <filename>/etc/hosts</filename> file.</para>
160
161 </sect2>
162
163 <sect2 id="ch-scripts-hosts">
164 <title>Customizing the /etc/hosts File</title>
165
166 <indexterm zone="ch-scripts-hosts">
167 <primary sortas="e-/etc/hosts">/etc/hosts</primary>
168 </indexterm>
169
170 <indexterm zone="ch-scripts-hosts">
171 <primary sortas="d-localnet">localnet</primary>
172 <secondary>/etc/hosts</secondary>
173 </indexterm>
174
175 <indexterm zone="ch-scripts-hosts">
176 <primary sortas="d-network">network</primary>
177 <secondary>/etc/hosts</secondary>
178 </indexterm>
179
180 <para>Decide on the IP address, fully-qualified domain name (FQDN), and
181 possible aliases for use in the <filename>/etc/hosts</filename> file. The
182 syntax is:</para>
183
184<screen><literal>IP_address myhost.example.org aliases</literal></screen>
185
186 <para>Unless the computer is to be visible to the Internet (i.e., there is
187 a registered domain and a valid block of assigned IP addresses&mdash;most
188 users do not have this), make sure that the IP address is in the private
189 network IP address range. Valid ranges are:</para>
190
191<screen><literal>Private Network Address Range Normal Prefix
19210.0.0.1 - 10.255.255.254 8
193172.x.0.1 - 172.x.255.254 16
194192.168.y.1 - 192.168.y.254 24</literal></screen>
195
196 <para>x can be any number in the range 16-31. y can be any number in the
197 range 0-255.</para>
198
199 <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
200 this IP could be lfs.example.org.</para>
201
202 <para>Even if not using a network card, a valid FQDN is still required.
203 This is necessary for certain programs to operate correctly.</para>
204
205 <para>Create the <filename>/etc/hosts</filename> file by running:</para>
206
207<screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
208<literal># Begin /etc/hosts
209
210127.0.0.1 localhost
211127.0.1.1 <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable>
212<replaceable>&lt;192.168.1.1&gt;</replaceable> <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> <replaceable>[alias1] [alias2 ...]</replaceable>
213::1 localhost ip6-localhost ip6-loopback
214ff02::1 ip6-allnodes
215ff02::2 ip6-allrouters
216
217# End /etc/hosts</literal>
218EOF</userinput></screen>
219
220 <para>The <replaceable>&lt;192.168.1.1&gt;</replaceable>,
221 <replaceable>&lt;FQDN&gt;</replaceable>, and
222 <replaceable>&lt;HOSTNAME&gt;</replaceable> values need to be
223 changed for specific uses or requirements (if assigned an IP address by a
224 network/system administrator and the machine will be connected to an
225 existing network). The optional alias name(s) can be omitted.</para>
226
227<!-- This is not very useful
228
229 <para>If a network card is not going to be configured, create the
230 <filename>/etc/hosts</filename> file by running:</para>
231
232<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
233<literal># Begin /etc/hosts (no network card version)
234
235127.0.0.1 localhost
236127.0.1.1 <replaceable>&lt;FQDN&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable>
237::1 localhost ip6-localhost ip6-loopback
238ff02::1 ip6-allnodes
239ff02::2 ip6-allrouters
240
241# End /etc/hosts (no network card version)</literal>
242EOF</userinput></screen> -->
243
244 </sect2>
245
246</sect1>
Note: See TracBrowser for help on using the repository browser.