aboutsummaryrefslogtreecommitdiffstats
path: root/chapter07/ethnet.xml
blob: ac1cca09d0f1b73a894718d71c9407c32f8ee4d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<sect1 id="ch09-ethnet">
<title>Creating the /etc/init.d/ethnet script</title>

<para>
This section only applies if a user is going to configure a network card.
If not, this section can be skipped.
</para>

<para>
A new file <filename>/etc/init.d/ethnet</filename> is created containing the
following:
</para>

<literallayout>
<userinput>cat &gt; /etc/init.d/ethnet &lt;&lt; "EOF"</userinput>
#!/bin/sh
# Begin /etc/init.d/ethnet
#
# Main script by Gerard Beekmans - gerard@linuxfromscratch.org
# GATEWAY check by Jean-Fran�ois Le Ray - jfleray@club-internet.fr
#

#
# Include the functions declared in the /etc/init.d/functions file
# and the variables from the /etc/sysconfig/network file.
#

source /etc/init.d/functions
source /etc/sysconfig/network

case "$1" in
        start)

#
# Obtain all the network card configuration files
#

        for interface in $(ls /etc/sysconfig/network-scripts/ifcfg* | \
            grep -v ifcfg-lo)
        do
#
# Load the variables from that file
#

            source $interface
#
# If the ONBOOT variable is set to yes, process this file and bring the
# interface up.
#

            if [ "$ONBOOT" == yes ]
            then
                echo -n "Bringing up the $DEVICE interface..."
                /sbin/ifconfig $DEVICE $IP broadcast $BROADCAST \
                    netmask $NETMASK
                evaluate_retval
            fi
        done

#
# If the /etc/sysconfig/network file contains a GATEWAY variable, set
# the gateway.
#

            if [ "$GATEWAY" != "" ]; then
                echo -n "Setting up routing for eth0 interface..."
                /sbin/route add default gw $GATEWAY metric 1
                evaluate_retval
            fi
                ;;

        stop)

#
# Obtain all the network card configuration files
#

        for interface in $(ls /etc/sysconfig/network-scripts/ifcfg* | \
            grep -v ifcfg-lo)
        do
#
# Load the variables from that file
#

            source $interface
#
# If the ONBOOT variable is set, process the file and bring the
# interface down
#

            if [ $ONBOOT == yes ]
            then
                echo -n "Bringing down the $DEVICE interface..."
                /sbin/ifconfig $DEVICE down
                evaluate_retval
            fi
        done
                ;;

        restart)
                $0 stop
                sleep 1
                $0 start
                ;;
        *)
                echo "Usage: $0 {start|stop|restart}"
                exit 1
                ;;
esac

# End /etc/init.d/ethnet
<userinput>EOF</userinput>
</literallayout>

<sect2>
<title>Adding default gateway to /etc/sysconfig/network</title>

<para>
If a default gateway is required to be setup, the following command does that:
</para>

<literallayout>
<userinput>cat &gt;&gt; /etc/sysconfig/network &lt;&lt; "EOF"</userinput>
GATEWAY=192.168.1.2
<userinput>EOF</userinput>
</literallayout>

<para>
GATEWAY needs to be changed to match the network setup.
</para>

</sect2>

<sect2>
<title>Creating NIC configuration files</title>

<para>
Which interfaces are brought up and down by the ethnet script depends on
the files in the /etc/sysconfig/network-scripts directory. This
directory should contain files in the form of ifcfg-x where x is an
identification number (or whatever a user named it).
</para>

<para>
First the network-scripts directory is created by running:
</para>

<blockquote><literallayout>
	<userinput>mkdir /etc/sysconfig/network-scripts</userinput>
</literallayout></blockquote>

<para>

Now, new files are created in that directory containing the following.
This creates a sample file ifcfg-eth0:
</para>

<literallayout>
<userinput>cat &gt; /etc/sysconfig/network-scripts/ifcfg-eth0
	&lt;&lt; EOF</userinput>
ONBOOT=yes
DEVICE=eth0
IP=192.168.1.1
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
<userinput>EOF</userinput>
</literallayout>

<para>
Of course, the values of those four variables have to be changed 
in every file to
match the proper setup. Usually NETMASK and BROADCAST will remain the
same, just the DEVICE IP variables will change per network interface. If 
the ONBOOT variable is set to yes, the ethnet script will bring it up 
during boot up of the system. If set to anything else but yes it will be 
ignored by the ethnet script and thus not brought up.
</para>

</sect2>

&c9-ethnet-symperm;

</sect1>