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