[673b0d8] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
[b06ca36] | 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
[673b0d8] | 4 | <!ENTITY % general-entities SYSTEM "../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
[d781ffb] | 7 |
|
---|
[3be4d97] | 8 | <sect1 id="ch-scripts-network">
|
---|
[d781ffb] | 9 | <?dbhtml filename="network.html"?>
|
---|
| 10 |
|
---|
[0cda898] | 11 | <title>General Network Configuration</title>
|
---|
[d781ffb] | 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 |
|
---|
[d7f2eb0] | 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>
|
---|
[d781ffb] | 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
|
---|
[bf58c1e] | 31 | usually depends on the files in <filename
|
---|
[0cda898] | 32 | class="directory">/etc/sysconfig/</filename>. This directory should
|
---|
| 33 | contain a file for each interface to be configured, such as
|
---|
[cba2d4e] | 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>
|
---|
[0cda898] | 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/
|
---|
| 53 | cat > ifconfig.eth0 << "EOF"
|
---|
[d72e04a] | 54 | <literal>ONBOOT=yes
|
---|
[0cda898] | 55 | IFACE=eth0
|
---|
[a088964] | 56 | SERVICE=ipv4-static
|
---|
[cba2d4e] | 57 | IP=192.168.1.2
|
---|
| 58 | GATEWAY=192.168.1.1
|
---|
[c0155c7] | 59 | PREFIX=24
|
---|
[d72e04a] | 60 | BROADCAST=192.168.1.255</literal>
|
---|
[f67f5cf] | 61 | EOF</userinput></screen>
|
---|
[00a2bd12] | 62 |
|
---|
[d781ffb] | 63 | <para>The values of these variables must be changed in every file to match
|
---|
[0cda898] | 64 | the proper setup.</para>
|
---|
| 65 |
|
---|
| 66 | <para>If the <envar>ONBOOT</envar> variable is set to <quote>yes</quote> the
|
---|
[cba2d4e] | 67 | System V network script will bring up the Network Interface Card (NIC) during
|
---|
[0cda898] | 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,
|
---|
[2ca8941] | 74 | for example, eth0. It is required for all network device configuration
|
---|
[0cda898] | 75 | files. </para>
|
---|
[d781ffb] | 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
|
---|
[f874424] | 80 | class="directory">/lib/services/</filename> directory allows other IP
|
---|
[0cda898] | 81 | assignment methods. This is commonly used for Dynamic Host Configuration
|
---|
| 82 | Protocol (DHCP), which is addressed in the BLFS book.</para>
|
---|
[d781ffb] | 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 |
|
---|
[19e4f62] | 88 | <para>The <envar>PREFIX</envar> variable contains the number of
|
---|
[d781ffb] | 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
|
---|
[7bfe7df] | 95 | <envar>PREFIX</envar> variable according to your specific subnet.
|
---|
[970a126] | 96 | If omitted, the PREFIX defaults to 24.</para>
|
---|
| 97 |
|
---|
| 98 | <para>For more information see the <command>ifup</command> man page.</para>
|
---|
[d781ffb] | 99 |
|
---|
| 100 | </sect2>
|
---|
[b3eb525] | 101 | <!--
|
---|
[cba2d4e] | 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 |
|
---|
[c729bc9] | 114 | <screen role="nodump"><userinput>systemctl disable ifupdown@eth0</userinput></screen>
|
---|
[cba2d4e] | 115 |
|
---|
| 116 | <para>To manually start the network interface card configuration,
|
---|
| 117 | run:</para>
|
---|
| 118 |
|
---|
[c729bc9] | 119 | <screen role="nodump"><userinput>systemctl start ifupdown@eth0</userinput></screen>
|
---|
[cba2d4e] | 120 |
|
---|
| 121 | <para>Replace eth0 with the correct network interface card
|
---|
| 122 | name as described on the beginning of this page.</para>
|
---|
| 123 |
|
---|
[976040f] | 124 | <note><para>These procedures require the configuration files as specified
|
---|
[bf58c1e] | 125 | in the previous section.</para></note>
|
---|
| 126 |
|
---|
[cba2d4e] | 127 | <note><para>The network card can also be started or stopped
|
---|
| 128 | with the traditional <command>ifup <device></command> or
|
---|
| 129 | <command>ifdown <device></command> commands.</para></note>
|
---|
| 130 |
|
---|
| 131 | </sect2>
|
---|
| 132 |
|
---|
[bf58c1e] | 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 > /etc/systemd/network/10-static-eth0.network << "EOF"
|
---|
| 142 | [Match]
|
---|
| 143 | Name=eth0
|
---|
| 144 |
|
---|
| 145 | [Network]
|
---|
| 146 | Address=192.168.0.2/24
|
---|
| 147 | Gateway=192.168.0.1
|
---|
| 148 | EOF</userinput></screen>
|
---|
| 149 |
|
---|
[976040f] | 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>
|
---|
[bf58c1e] | 156 |
|
---|
| 157 | </sect2>
|
---|
[c858814a] | 158 | -->
|
---|
[d781ffb] | 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>
|
---|
[45340ae] | 173 |
|
---|
[f67f5cf] | 174 | <screen><userinput>cat > /etc/resolv.conf << "EOF"
|
---|
[d72e04a] | 175 | <literal># Begin /etc/resolv.conf
|
---|
[45340ae] | 176 |
|
---|
[4b51ca76] | 177 | domain <replaceable><Your Domain Name></replaceable>
|
---|
[0090db5] | 178 | nameserver <replaceable><IP address of your primary nameserver></replaceable>
|
---|
| 179 | nameserver <replaceable><IP address of your secondary nameserver></replaceable>
|
---|
[45340ae] | 180 |
|
---|
[d72e04a] | 181 | # End /etc/resolv.conf</literal>
|
---|
[f67f5cf] | 182 | EOF</userinput></screen>
|
---|
[45340ae] | 183 |
|
---|
[0cda898] | 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 |
|
---|
[0090db5] | 188 | <para>Replace <replaceable><IP address of the nameserver></replaceable>
|
---|
[d781ffb] | 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>
|
---|
[45340ae] | 194 |
|
---|
[0cda898] | 195 | <note><para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para></note>
|
---|
| 196 |
|
---|
[d781ffb] | 197 | </sect2>
|
---|
[c858814a] | 198 |
|
---|
[bf58c1e] | 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 |
|
---|
[b3eb525] | 207 | <para>During the boot process, the file <filename>/etc/hostname</filename>
|
---|
| 208 | is used for establishing the system's hostname.</para>
|
---|
[bf58c1e] | 209 |
|
---|
| 210 | <para>Create the <filename>/etc/hostname</filename> file and enter a
|
---|
| 211 | hostname by running:</para>
|
---|
| 212 |
|
---|
| 213 | <screen><userinput>echo "<replaceable><lfs></replaceable>" > /etc/hostname</userinput></screen>
|
---|
| 214 |
|
---|
| 215 | <para><replaceable><lfs></replaceable> needs to be replaced with the
|
---|
| 216 | name given to the computer. Do not enter the Fully Qualified Domain Name
|
---|
| 217 | (FQDN) here. That information is put in the
|
---|
| 218 | <filename>/etc/hosts</filename> file.</para>
|
---|
| 219 |
|
---|
| 220 | </sect2>
|
---|
| 221 |
|
---|
| 222 | <sect2 id="ch-scripts-hosts">
|
---|
| 223 | <title>Customizing the /etc/hosts File</title>
|
---|
| 224 |
|
---|
| 225 | <indexterm zone="ch-scripts-hosts">
|
---|
| 226 | <primary sortas="e-/etc/hosts">/etc/hosts</primary>
|
---|
| 227 | </indexterm>
|
---|
| 228 |
|
---|
| 229 | <indexterm zone="ch-scripts-hosts">
|
---|
| 230 | <primary sortas="d-localnet">localnet</primary>
|
---|
| 231 | <secondary>/etc/hosts</secondary>
|
---|
| 232 | </indexterm>
|
---|
| 233 |
|
---|
| 234 | <indexterm zone="ch-scripts-hosts">
|
---|
| 235 | <primary sortas="d-network">network</primary>
|
---|
| 236 | <secondary>/etc/hosts</secondary>
|
---|
| 237 | </indexterm>
|
---|
| 238 |
|
---|
| 239 | <para>Decide on the IP address, fully-qualified domain name (FQDN), and
|
---|
| 240 | possible aliases for use in the <filename>/etc/hosts</filename> file. The
|
---|
| 241 | syntax is:</para>
|
---|
| 242 |
|
---|
| 243 | <screen><literal>IP_address myhost.example.org aliases</literal></screen>
|
---|
| 244 |
|
---|
| 245 | <para>Unless the computer is to be visible to the Internet (i.e., there is
|
---|
| 246 | a registered domain and a valid block of assigned IP addresses—most
|
---|
| 247 | users do not have this), make sure that the IP address is in the private
|
---|
| 248 | network IP address range. Valid ranges are:</para>
|
---|
| 249 |
|
---|
| 250 | <screen><literal>Private Network Address Range Normal Prefix
|
---|
| 251 | 10.0.0.1 - 10.255.255.254 8
|
---|
| 252 | 172.x.0.1 - 172.x.255.254 16
|
---|
| 253 | 192.168.y.1 - 192.168.y.254 24</literal></screen>
|
---|
| 254 |
|
---|
| 255 | <para>x can be any number in the range 16-31. y can be any number in the
|
---|
| 256 | range 0-255.</para>
|
---|
| 257 |
|
---|
| 258 | <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
|
---|
| 259 | this IP could be lfs.example.org.</para>
|
---|
| 260 |
|
---|
| 261 | <para>Even if not using a network card, a valid FQDN is still required.
|
---|
| 262 | This is necessary for certain programs to operate correctly.</para>
|
---|
| 263 |
|
---|
| 264 | <para>Create the <filename>/etc/hosts</filename> file by running:</para>
|
---|
| 265 |
|
---|
| 266 | <screen><userinput>cat > /etc/hosts << "EOF"
|
---|
| 267 | <literal># Begin /etc/hosts (network card version)
|
---|
| 268 |
|
---|
| 269 | 127.0.0.1 localhost
|
---|
| 270 | <replaceable><192.168.1.1></replaceable> <replaceable><HOSTNAME.example.org></replaceable> <replaceable>[alias1] [alias2 ...]</replaceable>
|
---|
| 271 |
|
---|
| 272 | # End /etc/hosts (network card version)</literal>
|
---|
| 273 | EOF</userinput></screen>
|
---|
| 274 |
|
---|
| 275 | <para>The <replaceable><192.168.1.1></replaceable> and
|
---|
| 276 | <replaceable><HOSTNAME.example.org></replaceable> values need to be
|
---|
| 277 | changed for specific uses or requirements (if assigned an IP address by a
|
---|
| 278 | network/system administrator and the machine will be connected to an
|
---|
| 279 | existing network). The optional alias name(s) can be omitted.</para>
|
---|
| 280 |
|
---|
| 281 | <para>If a network card is not going to be configured, create the
|
---|
| 282 | <filename>/etc/hosts</filename> file by running:</para>
|
---|
| 283 |
|
---|
| 284 | <screen role="nodump"><userinput>cat > /etc/hosts << "EOF"
|
---|
| 285 | <literal># Begin /etc/hosts (no network card version)
|
---|
| 286 |
|
---|
| 287 | 127.0.0.1 <replaceable><HOSTNAME.example.org></replaceable> <replaceable><HOSTNAME></replaceable> localhost
|
---|
| 288 |
|
---|
| 289 | # End /etc/hosts (no network card version)</literal>
|
---|
| 290 | EOF</userinput></screen>
|
---|
| 291 |
|
---|
| 292 | </sect2>
|
---|
| 293 |
|
---|
[d781ffb] | 294 | </sect1>
|
---|