source: chapter07/network.xml@ 6249eea

Last change on this file since 6249eea was 37153e0, checked in by Matthew Burgess <matthew@…>, 19 years ago

Udev rules file update and improve the wording for module loading and persistent device naming

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

  • Property mode set to 100644
File size: 6.9 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3 "http://www.oasis-open.org/docbook/xml/4.4/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>Configuring the network Script</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
21 create any configuration files relating to network cards. If that is
22 the case, remove the <filename class="symlink">network</filename>
23 symlinks from all run-level directories (<filename
24 class="directory">/etc/rc.d/rc*.d</filename>).</para>
25
26 <sect2>
27 <title>Creating stable names for network interfaces</title>
28 <para>Instructions in this section are optional if you have only one
29 network card.</para>
30
31 <para>With Udev and modular network drivers, the network interface
32 numbering is not persistent across reboots by default, because the
33 drivers are loaded in parallel and, thus, in random order.
34 For example, on a computer having two network cards made by Intel and
35 Realtek, the network card manufactured by Intel may become eth0 and the
36 Realtek card becomes eth1. In some cases, after a reboot the cards get
37 renumbered the other way around. To avoid this, create Udev rules that
38 assign stable names to network cards based on their MAC addresses.</para>
39
40 <para>First, find out the MAC addresses of your network cards:</para>
41<screen role="nodump"><userinput>grep -H . /sys/class/net/*/address</userinput></screen>
42 <para>For each network card (but not for the loopback interface),
43 invent a descriptive name, such as <quote>realtek</quote>, and create
44 Udev rules similar to the following:</para>
45
46<screen role="nodump"><userinput>
47cat &gt; /etc/udev/rules.d/26-network.rules &lt;&lt; "EOF"
48ACTION=="add", SUBSYSTEM=="net", SYSFS{address}=="<replaceable>52:54:00:12:34:56</replaceable>", NAME="<replaceable>realtek</replaceable>"
49ACTION=="add", SUBSYSTEM=="net", SYSFS{address}=="<replaceable>00:a0:c9:78:9a:bc</replaceable>", NAME="<replaceable>intel</replaceable>"
50EOF</userinput></screen>
51
52 <para>These rules will always rename the network cards to
53 <quote>realtek</quote> and <quote>intel</quote>, independently of the
54 original numbering provided by the kernel. Use these names instead of
55 <quote>eth0</quote> in the network interface configuration files created
56 below.</para>
57
58 <note><para>Persistent names must be different from the default network
59 interface names assigned by the kernel.</para></note>
60 </sect2>
61 <sect2>
62 <title>Creating Network Interface Configuration Files</title>
63
64 <para>Which interfaces are brought up and down by the network script
65 depends on the files and directories in the <filename
66 class="directory">/etc/sysconfig/network-devices</filename> hierarchy.
67 This directory should contain a sub-directory for each interface to be
68 configured, such as <filename>ifconfig.xyz</filename>, where
69 <quote>xyz</quote> is a network interface name. Inside this directory
70 would be files defining the attributes to this interface, such as its IP
71 address(es), subnet masks, and so forth.</para>
72
73 <para>The following command creates a sample <filename>ipv4</filename>
74 file for the <emphasis>eth0</emphasis> device:</para>
75
76<screen><userinput>cd /etc/sysconfig/network-devices &amp;&amp;
77mkdir -v ifconfig.eth0 &amp;&amp;
78cat &gt; ifconfig.eth0/ipv4 &lt;&lt; "EOF"
79<literal>ONBOOT=yes
80SERVICE=ipv4-static
81IP=192.168.1.1
82GATEWAY=192.168.1.2
83PREFIX=24
84BROADCAST=192.168.1.255</literal>
85EOF</userinput></screen>
86
87 <para>The values of these variables must be changed in every file to match
88 the proper setup. If the <envar>ONBOOT</envar> variable is set to
89 <quote>yes</quote> the network script will bring up the Network Interface
90 Card (NIC) during booting of the system. If set to anything but
91 <quote>yes</quote> the NIC will be ignored by the network script and not
92 be brought up.</para>
93
94 <para>The <envar>SERVICE</envar> variable defines the method used for
95 obtaining the IP address. The LFS-Bootscripts package has a modular IP
96 assignment format, and creating additional files in the <filename
97 class="directory">/etc/sysconfig/network-devices/services</filename>
98 directory allows other IP assignment methods. This is commonly used for
99 Dynamic Host Configuration Protocol (DHCP), which is addressed in the
100 BLFS book.</para>
101
102 <para>The <envar>GATEWAY</envar> variable should contain the default
103 gateway IP address, if one is present. If not, then comment out the
104 variable entirely.</para>
105
106 <para>The <envar>PREFIX</envar> variable needs to contain the number of
107 bits used in the subnet. Each octet in an IP address is 8 bits. If the
108 subnet's netmask is 255.255.255.0, then it is using the first three octets
109 (24 bits) to specify the network number. If the netmask is 255.255.255.240,
110 it would be using the first 28 bits. Prefixes longer than 24 bits are
111 commonly used by DSL and cable-based Internet Service Providers (ISPs).
112 In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
113 <envar>PREFIX</envar> variable according to your specific subnet.</para>
114
115 </sect2>
116
117 <sect2 id="resolv.conf">
118 <title>Creating the /etc/resolv.conf File</title>
119
120 <indexterm zone="resolv.conf">
121 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
122 </indexterm>
123
124 <para>If the system is going to be connected to the Internet, it will
125 need some means of Domain Name Service (DNS) name resolution to
126 resolve Internet domain names to IP addresses, and vice versa. This is
127 best achieved by placing the IP address of the DNS server, available
128 from the ISP or network administrator, into
129 <filename>/etc/resolv.conf</filename>. Create the file by running the
130 following:</para>
131
132<screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
133<literal># Begin /etc/resolv.conf
134
135domain {<replaceable>[Your Domain Name]</replaceable>}
136nameserver <replaceable>[IP address of your primary nameserver]</replaceable>
137nameserver <replaceable>[IP address of your secondary nameserver]</replaceable>
138
139# End /etc/resolv.conf</literal>
140EOF</userinput></screen>
141
142 <para>Replace <replaceable>[IP address of the nameserver]</replaceable>
143 with the IP address of the DNS most appropriate for the setup. There will
144 often be more than one entry (requirements demand secondary servers for
145 fallback capability). If you only need or want one DNS server, remove the
146 second <emphasis>nameserver</emphasis> line from the file. The IP address
147 may also be a router on the local network.</para>
148
149 </sect2>
150
151</sect1>
Note: See TracBrowser for help on using the repository browser.