1 | <sect1 id="ch07-ethnet">
|
---|
2 | <title>Creating the /etc/init.d/ethnet script</title>
|
---|
3 |
|
---|
4 | <para>
|
---|
5 | This section only applies if a user is going to configure a network card.
|
---|
6 | If not, this section can be skipped.
|
---|
7 | </para>
|
---|
8 |
|
---|
9 | <para>
|
---|
10 | A new file <filename>/etc/init.d/ethnet</filename> is created containing the
|
---|
11 | following:
|
---|
12 | </para>
|
---|
13 |
|
---|
14 | <para>
|
---|
15 | <screen>
|
---|
16 | <userinput>cat > /etc/init.d/ethnet << "EOF"</userinput>
|
---|
17 | #!/bin/sh
|
---|
18 | # Begin /etc/init.d/ethnet
|
---|
19 | #
|
---|
20 | # Main script by Gerard Beekmans - gerard@linuxfromscratch.org
|
---|
21 | # GATEWAY check by Jean-François Le Ray - jfleray@club-internet.fr
|
---|
22 | # "Specify which IF to use to reach default GATEWAY" by
|
---|
23 | # Graham Cantin - gcantin@pacbell.net
|
---|
24 | #
|
---|
25 |
|
---|
26 | #
|
---|
27 | # Include the functions declared in the /etc/init.d/functions file
|
---|
28 | # and the variables from the /etc/sysconfig/network file.
|
---|
29 | #
|
---|
30 |
|
---|
31 | source /etc/init.d/functions
|
---|
32 | source /etc/sysconfig/network
|
---|
33 |
|
---|
34 | case "$1" in
|
---|
35 | start)
|
---|
36 |
|
---|
37 | #
|
---|
38 | # Obtain all the network card configuration files
|
---|
39 | #
|
---|
40 |
|
---|
41 | for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
|
---|
42 | grep -v ifcfg-lo)
|
---|
43 | do
|
---|
44 | #
|
---|
45 | # Load the variables from that file
|
---|
46 | #
|
---|
47 |
|
---|
48 | source $interface
|
---|
49 | #
|
---|
50 | # If the ONBOOT variable is set to yes, process this file and bring the
|
---|
51 | # interface up.
|
---|
52 | #
|
---|
53 |
|
---|
54 | if [ "$ONBOOT" == yes ]
|
---|
55 | then
|
---|
56 | echo -n "Bringing up the $DEVICE interface..."
|
---|
57 | /sbin/ifconfig $DEVICE $IP broadcast $BROADCAST \
|
---|
58 | netmask $NETMASK
|
---|
59 | evaluate_retval
|
---|
60 | fi
|
---|
61 | done
|
---|
62 |
|
---|
63 | #
|
---|
64 | # If the /etc/sysconfig/network file contains a GATEWAY variable, set
|
---|
65 | # the default gateway and the interface through which the default
|
---|
66 | # gateway can be reached.
|
---|
67 | #
|
---|
68 |
|
---|
69 | if [ "$GATEWAY" != "" ]; then
|
---|
70 | echo -n "Setting up routing for $GATEWAY_IF interface..."
|
---|
71 | /sbin/route add default gateway $GATEWAY \
|
---|
72 | metric 1 dev $GATEWAY_IF
|
---|
73 | evaluate_retval
|
---|
74 | fi
|
---|
75 | ;;
|
---|
76 |
|
---|
77 | stop)
|
---|
78 |
|
---|
79 | #
|
---|
80 | # Obtain all the network card configuration files
|
---|
81 | #
|
---|
82 |
|
---|
83 | for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
|
---|
84 | grep -v ifcfg-lo)
|
---|
85 | do
|
---|
86 | #
|
---|
87 | # Load the variables from that file
|
---|
88 | #
|
---|
89 |
|
---|
90 | source $interface
|
---|
91 | #
|
---|
92 | # If the ONBOOT variable is set, process the file and bring the
|
---|
93 | # interface down
|
---|
94 | #
|
---|
95 |
|
---|
96 | if [ $ONBOOT == yes ]
|
---|
97 | then
|
---|
98 | echo -n "Bringing down the $DEVICE interface..."
|
---|
99 | /sbin/ifconfig $DEVICE down
|
---|
100 | evaluate_retval
|
---|
101 | fi
|
---|
102 | done
|
---|
103 | ;;
|
---|
104 |
|
---|
105 | restart)
|
---|
106 | $0 stop
|
---|
107 | sleep 1
|
---|
108 | $0 start
|
---|
109 | ;;
|
---|
110 | *)
|
---|
111 | echo "Usage: $0 {start|stop|restart}"
|
---|
112 | exit 1
|
---|
113 | ;;
|
---|
114 | esac
|
---|
115 |
|
---|
116 | # End /etc/init.d/ethnet
|
---|
117 | <userinput>EOF</userinput>
|
---|
118 | </screen>
|
---|
119 | </para>
|
---|
120 |
|
---|
121 | <sect2>
|
---|
122 | <title>Adding default gateway to /etc/sysconfig/network</title>
|
---|
123 |
|
---|
124 | <para>
|
---|
125 | If a default gateway is required to be setup, the following command does that:
|
---|
126 | </para>
|
---|
127 |
|
---|
128 | <para>
|
---|
129 | <screen>
|
---|
130 | <userinput>cat >> /etc/sysconfig/network << "EOF"</userinput>
|
---|
131 | GATEWAY=192.168.1.2
|
---|
132 | GATEWAY_IF=eth0
|
---|
133 | <userinput>EOF</userinput>
|
---|
134 | </screen>
|
---|
135 | </para>
|
---|
136 |
|
---|
137 | <para>
|
---|
138 | GATEWAY and GATEWAY_IF need to be changed to match the network setup.
|
---|
139 | GATEWAY contains the address of the default gateway, and GATEWAY_IF
|
---|
140 | contains the network interface through which that default gateway can
|
---|
141 | be reached.
|
---|
142 | </para>
|
---|
143 |
|
---|
144 | </sect2>
|
---|
145 |
|
---|
146 | <sect2>
|
---|
147 | <title>Creating NIC configuration files</title>
|
---|
148 |
|
---|
149 | <para>
|
---|
150 | Which interfaces are brought up and down by the ethnet script depends on
|
---|
151 | the files in the /etc/sysconfig/nic-config directory. This
|
---|
152 | directory should contain files in the form of ifcfg-x where x is an
|
---|
153 | identification number (or whatever a user named it).
|
---|
154 | </para>
|
---|
155 |
|
---|
156 | <para>
|
---|
157 | First the nic-config directory is created by running:
|
---|
158 | </para>
|
---|
159 |
|
---|
160 | <para>
|
---|
161 | <screen>
|
---|
162 | <userinput>mkdir /etc/sysconfig/nic-config</userinput>
|
---|
163 | </screen>
|
---|
164 | </para>
|
---|
165 |
|
---|
166 | <para>
|
---|
167 |
|
---|
168 | Now, new files are created in that directory containing the following.
|
---|
169 | This creates a sample file ifcfg-eth0:
|
---|
170 | </para>
|
---|
171 |
|
---|
172 | <para>
|
---|
173 | <screen>
|
---|
174 | <userinput>cat > /etc/sysconfig/nic-config/ifcfg-eth0 << "EOF"</userinput>
|
---|
175 | ONBOOT=yes
|
---|
176 | DEVICE=eth0
|
---|
177 | IP=192.168.1.1
|
---|
178 | NETMASK=255.255.255.0
|
---|
179 | BROADCAST=192.168.1.255
|
---|
180 | <userinput>EOF</userinput>
|
---|
181 | </screen>
|
---|
182 | </para>
|
---|
183 |
|
---|
184 | <para>
|
---|
185 | Of course, the values of those four variables have to be changed
|
---|
186 | in every file to
|
---|
187 | match the proper setup. Usually NETMASK and BROADCAST will remain the
|
---|
188 | same, just the DEVICE IP variables will change per network interface. If
|
---|
189 | the ONBOOT variable is set to yes, the ethnet script will bring it up
|
---|
190 | during boot up of the system. If set to anything else but yes it will be
|
---|
191 | ignored by the ethnet script and thus not brought up.
|
---|
192 | </para>
|
---|
193 |
|
---|
194 | </sect2>
|
---|
195 |
|
---|
196 | </sect1>
|
---|
197 |
|
---|