source: chapter07/network.xml@ 976040f

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 7.6 7.7 7.8 7.9 8.0 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 976040f was 976040f, checked in by Bruce Dubbs <bdubbs@…>, 10 years ago

Update to man-pages-3.65.
Text changes in Chapter 7.

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

  • Property mode set to 100644
File size: 12.1 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">
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> is required to
35 be a Network Card Interface name (e.g. eth0). Inside this file are
36 attributes to this interface, such as its IP address(es), subnet masks, and
37 so forth. It is necessary that the stem of the filename be
38 <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> after you have
44 booted your system. Again, it is important that ifconfig.xyz is named
45 after correct network card interface name (e.g. ifconfig.enp2s1 or
46 ifconfig.eth0) or your network interface will not be initialized during
47 the boot process.</para></note>
48
49 <para>The following command creates a sample file for the
50 <emphasis>eth0</emphasis> device with a static IP address:</para>
51
52<screen><userinput>cd /etc/sysconfig/
53cat &gt; ifconfig.eth0 &lt;&lt; "EOF"
54<literal>ONBOOT=yes
55IFACE=eth0
56SERVICE=ipv4-static
57IP=192.168.1.2
58GATEWAY=192.168.1.1
59PREFIX=24
60BROADCAST=192.168.1.255</literal>
61EOF</userinput></screen>
62
63 <para>The values of these variables must be changed in every file to match
64 the proper setup.</para>
65
66 <para>If the <envar>ONBOOT</envar> variable is set to <quote>yes</quote> the
67 System V network script will bring up the Network Interface Card (NIC) during
68 booting of the system. If set to anything but <quote>yes</quote> the NIC
69 will be ignored by the network script and not be automatically brought up.
70 The interface can be manually started or stopped with the
71 <command>ifup</command> and <command>ifdown</command> commands.</para>
72
73 <para>The <envar>IFACE</envar> variable defines the interface name,
74 for example, eth0. It is required for all network device configuration
75 files. </para>
76
77 <para>The <envar>SERVICE</envar> variable defines the method used for
78 obtaining the IP address. The LFS-Bootscripts package has a modular IP
79 assignment format, and creating additional files in the <filename
80 class="directory">/lib/services/</filename> directory allows other IP
81 assignment methods. This is commonly used for Dynamic Host Configuration
82 Protocol (DHCP), which is addressed in the BLFS book.</para>
83
84 <para>The <envar>GATEWAY</envar> variable should contain the default
85 gateway IP address, if one is present. If not, then comment out the
86 variable entirely.</para>
87
88 <para>The <envar>PREFIX</envar> variable contains the number of
89 bits used in the subnet. Each octet in an IP address is 8 bits. If the
90 subnet's netmask is 255.255.255.0, then it is using the first three octets
91 (24 bits) to specify the network number. If the netmask is 255.255.255.240,
92 it would be using the first 28 bits. Prefixes longer than 24 bits are
93 commonly used by DSL and cable-based Internet Service Providers (ISPs).
94 In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
95 <envar>PREFIX</envar> variable according to your specific subnet.
96 If omitted, the PREFIX defaults to 24.</para>
97
98 <para>For more information see the <command>ifup</command> man page.</para>
99
100 </sect2>
101
102 <sect2 id="systemd-net-enable">
103 <title>Configuring the Network Interface Card at boot (systemd)</title>
104
105 <para>Enabling of the network interface card configuration
106 in systemd is done per interface. To enable network interface card
107 configuration at boot, run:</para>
108
109<screen><userinput>systemctl enable ifupdown@eth0</userinput></screen>
110
111 <para>To disable a previously enabled network interface
112 card configuration at boot, run:</para>
113
114<screen role="nodump"><userinput>systemctl disable ifupdown@eth0</userinput></screen>
115
116 <para>To manually start the network interface card configuration,
117 run:</para>
118
119<screen role="nodump"><userinput>systemctl start ifupdown@eth0</userinput></screen>
120
121 <para>Replace eth0 with the correct network interface card
122 name as described on the beginning of this page.</para>
123
124 <note><para>These procedures require the configuration files as specified
125 in the previous section.</para></note>
126
127 <note><para>The network card can also be started or stopped
128 with the traditional <command>ifup &lt;device&gt;</command> or
129 <command>ifdown &lt;device&gt;</command> commands.</para></note>
130
131 </sect2>
132
133 <sect2 id="systemd2-net-enable">
134 <title>Configuring the Network Interface Card for systemd-networkd</title>
135
136 <para>An alternative way to configure a NIC when booting with with
137 systemd is to create a configuration file recognized by the
138 systemd-networkd daemon. To configure the device create a file similar
139 to this:</para>
140
141<screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-static-eth0.network &lt;&lt; "EOF"
142[Match]
143Name=eth0
144
145[Network]
146Address=192.168.0.2/24
147Gateway=192.168.0.1
148EOF</userinput></screen>
149
150 <para>You can use multiple .network files if desired. You can also specify
151 DHCP=yes instead of the Address and Gateway settings. See the man page for
152 systemd.network for more details,</para>
153
154 <note><para>If this method is used, be sure to disable ifupdown@eth0 as
155 described in the previous section (if it was enabled).</para></note>
156
157 </sect2>
158
159 <sect2 id="resolv.conf">
160 <title>Creating the /etc/resolv.conf File</title>
161
162 <indexterm zone="resolv.conf">
163 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
164 </indexterm>
165
166 <para>If the system is going to be connected to the Internet, it will
167 need some means of Domain Name Service (DNS) name resolution to
168 resolve Internet domain names to IP addresses, and vice versa. This is
169 best achieved by placing the IP address of the DNS server, available
170 from the ISP or network administrator, into
171 <filename>/etc/resolv.conf</filename>. Create the file by running the
172 following:</para>
173
174<screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
175<literal># Begin /etc/resolv.conf
176
177domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
178nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
179nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
180
181# End /etc/resolv.conf</literal>
182EOF</userinput></screen>
183
184 <para>The <varname>domain</varname> statement can be omitted
185 or replaced with a <varname>search</varname> statement. See the man page for
186 resolv.conf for more details.</para>
187
188 <para>Replace <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
189 with the IP address of the DNS most appropriate for the setup. There will
190 often be more than one entry (requirements demand secondary servers for
191 fallback capability). If you only need or want one DNS server, remove the
192 second <emphasis>nameserver</emphasis> line from the file. The IP address
193 may also be a router on the local network.</para>
194
195 <note><para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para></note>
196
197 </sect2>
198
199 <sect2 id="ch-scripts-hostname">
200 <title>Configuring the system hostname</title>
201
202 <indexterm zone="ch-scripts-hostname">
203 <primary sortas="d-hostname">hostname</primary>
204 <secondary>configuring</secondary>
205 </indexterm>
206
207 <para>During the boot process, both Systemd and System V use the same file
208 for establishing the system's hostname. This needs to be configured by
209 creating <filename>/etc/hostname</filename>.</para>
210
211 <para>Create the <filename>/etc/hostname</filename> file and enter a
212 hostname by running:</para>
213
214<screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
215
216 <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
217 name given to the computer. Do not enter the Fully Qualified Domain Name
218 (FQDN) here. That information is put in the
219 <filename>/etc/hosts</filename> file.</para>
220
221 </sect2>
222
223 <sect2 id="ch-scripts-hosts">
224 <title>Customizing the /etc/hosts File</title>
225
226 <indexterm zone="ch-scripts-hosts">
227 <primary sortas="e-/etc/hosts">/etc/hosts</primary>
228 </indexterm>
229
230 <indexterm zone="ch-scripts-hosts">
231 <primary sortas="d-localnet">localnet</primary>
232 <secondary>/etc/hosts</secondary>
233 </indexterm>
234
235 <indexterm zone="ch-scripts-hosts">
236 <primary sortas="d-network">network</primary>
237 <secondary>/etc/hosts</secondary>
238 </indexterm>
239
240 <para>Decide on the IP address, fully-qualified domain name (FQDN), and
241 possible aliases for use in the <filename>/etc/hosts</filename> file. The
242 syntax is:</para>
243
244<screen><literal>IP_address myhost.example.org aliases</literal></screen>
245
246 <para>Unless the computer is to be visible to the Internet (i.e., there is
247 a registered domain and a valid block of assigned IP addresses&mdash;most
248 users do not have this), make sure that the IP address is in the private
249 network IP address range. Valid ranges are:</para>
250
251<screen><literal>Private Network Address Range Normal Prefix
25210.0.0.1 - 10.255.255.254 8
253172.x.0.1 - 172.x.255.254 16
254192.168.y.1 - 192.168.y.254 24</literal></screen>
255
256 <para>x can be any number in the range 16-31. y can be any number in the
257 range 0-255.</para>
258
259 <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
260 this IP could be lfs.example.org.</para>
261
262 <para>Even if not using a network card, a valid FQDN is still required.
263 This is necessary for certain programs to operate correctly.</para>
264
265 <para>Create the <filename>/etc/hosts</filename> file by running:</para>
266
267<screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
268<literal># Begin /etc/hosts (network card version)
269
270127.0.0.1 localhost
271<replaceable>&lt;192.168.1.1&gt;</replaceable> <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>[alias1] [alias2 ...]</replaceable>
272
273# End /etc/hosts (network card version)</literal>
274EOF</userinput></screen>
275
276 <para>The <replaceable>&lt;192.168.1.1&gt;</replaceable> and
277 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> values need to be
278 changed for specific uses or requirements (if assigned an IP address by a
279 network/system administrator and the machine will be connected to an
280 existing network). The optional alias name(s) can be omitted.</para>
281
282 <para>If a network card is not going to be configured, create the
283 <filename>/etc/hosts</filename> file by running:</para>
284
285<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
286<literal># Begin /etc/hosts (no network card version)
287
288127.0.0.1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost
289
290# End /etc/hosts (no network card version)</literal>
291EOF</userinput></screen>
292
293 </sect2>
294
295</sect1>
Note: See TracBrowser for help on using the repository browser.