4 |
- |
1 |
#! /bin/bash
|
|
|
2 |
#
|
|
|
3 |
# network Bring up/down networking
|
|
|
4 |
#
|
|
|
5 |
# chkconfig: 2345 10 90
|
|
|
6 |
# description: Activates/Deactivates all network interfaces configured to \
|
|
|
7 |
# start at boot time.
|
|
|
8 |
#
|
|
|
9 |
### BEGIN INIT INFO
|
|
|
10 |
# Provides: $network
|
|
|
11 |
# Should-Start: iptables ip6tables
|
|
|
12 |
# Short-Description: Bring up/down networking
|
|
|
13 |
# Description: Bring up/down networking
|
|
|
14 |
### END INIT INFO
|
|
|
15 |
|
|
|
16 |
# Source function library.
|
|
|
17 |
. /etc/init.d/functions
|
|
|
18 |
|
|
|
19 |
if [ ! -f /etc/sysconfig/network ]; then
|
|
|
20 |
exit 6
|
|
|
21 |
fi
|
|
|
22 |
|
|
|
23 |
. /etc/sysconfig/network
|
|
|
24 |
|
|
|
25 |
if [ -f /etc/sysconfig/pcmcia ]; then
|
|
|
26 |
. /etc/sysconfig/pcmcia
|
|
|
27 |
fi
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
# Check that networking is up.
|
|
|
31 |
[ "${NETWORKING}" = "no" ] && exit 6
|
|
|
32 |
|
|
|
33 |
# if the ip configuration utility isn't around we can't function.
|
|
|
34 |
[ -x /sbin/ip ] || exit 1
|
|
|
35 |
|
|
|
36 |
CWD=$(pwd)
|
|
|
37 |
cd /etc/sysconfig/network-scripts
|
|
|
38 |
|
|
|
39 |
. ./network-functions
|
|
|
40 |
|
|
|
41 |
# find all the interfaces besides loopback.
|
|
|
42 |
# ignore aliases, alternative configurations, and editor backup files
|
|
|
43 |
interfaces=$(ls ifcfg* | \
|
|
|
44 |
LANG=C sed -e "$__sed_discard_ignored_files" \
|
|
|
45 |
-e '/\(ifcfg-lo$\|:\|ifcfg-.*-range\)/d' \
|
|
|
46 |
-e '/ifcfg-[A-Za-z0-9#\._-]\+$/ { s/^ifcfg-//g;s/[0-9]/ &/}' | \
|
|
|
47 |
LANG=C sort -k 1,1 -k 2n | \
|
|
|
48 |
LANG=C sed 's/ //')
|
|
|
49 |
rc=0
|
|
|
50 |
|
|
|
51 |
# See how we were called.
|
|
|
52 |
case "$1" in
|
|
|
53 |
start)
|
|
|
54 |
[ "$EUID" != "0" ] && exit 4
|
|
|
55 |
rc=0
|
|
|
56 |
# IPv6 hook (pre IPv4 start)
|
|
|
57 |
if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
|
|
|
58 |
/etc/sysconfig/network-scripts/init.ipv6-global start pre
|
|
|
59 |
fi
|
|
|
60 |
|
|
|
61 |
apply_sysctl
|
|
|
62 |
|
|
|
63 |
# bring up loopback interface
|
|
|
64 |
action $"Bringing up loopback interface: " ./ifup ifcfg-lo
|
|
|
65 |
|
|
|
66 |
case "$VLAN" in
|
|
|
67 |
yes)
|
|
|
68 |
if [ ! -d /proc/net/vlan ] && ! modprobe 8021q >/dev/null 2>&1 ; then
|
|
|
69 |
net_log $"No 802.1Q VLAN support available in kernel."
|
|
|
70 |
fi
|
|
|
71 |
;;
|
|
|
72 |
esac
|
|
|
73 |
|
|
|
74 |
vlaninterfaces=""
|
|
|
75 |
xdslinterfaces=""
|
|
|
76 |
bridgeinterfaces=""
|
|
|
77 |
|
|
|
78 |
# bring up all other interfaces configured to come up at boot time
|
|
|
79 |
for i in $interfaces; do
|
|
|
80 |
unset DEVICE TYPE SLAVE
|
|
|
81 |
eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
|
|
|
82 |
eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
|
|
|
83 |
eval $(LANG=C fgrep "SLAVE=" ifcfg-$i)
|
|
|
84 |
|
|
|
85 |
if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
|
|
|
86 |
|
|
|
87 |
if [ "$SLAVE" = "yes" ]; then
|
|
|
88 |
continue
|
|
|
89 |
fi
|
|
|
90 |
|
|
|
91 |
if [ "$TYPE" = "xDSL" ]; then
|
|
|
92 |
xdslinterfaces="$xdslinterfaces $i"
|
|
|
93 |
continue
|
|
|
94 |
fi
|
|
|
95 |
|
|
|
96 |
if [ "$TYPE" = "Bridge" ]; then
|
|
|
97 |
bridgeinterfaces="$bridgeinterfaces $i"
|
|
|
98 |
continue
|
|
|
99 |
fi
|
|
|
100 |
|
|
|
101 |
if [ "${DEVICE%%.*}" != "$DEVICE" -o "${DEVICE##vlan}" != "$DEVICE" ] ; then
|
|
|
102 |
vlaninterfaces="$vlaninterfaces $i"
|
|
|
103 |
continue
|
|
|
104 |
fi
|
|
|
105 |
|
|
|
106 |
if LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i > /dev/null ; then
|
|
|
107 |
# this loads the module, to preserve ordering
|
|
|
108 |
is_available $i
|
|
|
109 |
continue
|
|
|
110 |
fi
|
|
|
111 |
# If we're in confirmation mode, get user confirmation.
|
|
|
112 |
if [ -f /var/run/confirm ]; then
|
|
|
113 |
confirm $i
|
|
|
114 |
test $? = 1 && continue
|
|
|
115 |
fi
|
|
|
116 |
action $"Bringing up interface $i: " ./ifup $i boot
|
|
|
117 |
[ $? -ne 0 ] && rc=1
|
|
|
118 |
done
|
|
|
119 |
|
|
|
120 |
# Bring up xDSL and VPN interfaces
|
|
|
121 |
for i in $vlaninterfaces $bridgeinterfaces $xdslinterfaces ; do
|
|
|
122 |
if ! LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i >/dev/null 2>&1 ; then
|
|
|
123 |
# If we're in confirmation mode, get user confirmation.
|
|
|
124 |
if [ -f /var/run/confirm ]; then
|
|
|
125 |
confirm $i
|
|
|
126 |
test $? = 1 && continue
|
|
|
127 |
fi
|
|
|
128 |
action $"Bringing up interface $i: " ./ifup $i boot
|
|
|
129 |
[ $? -ne 0 ] && rc=1
|
|
|
130 |
fi
|
|
|
131 |
done
|
|
|
132 |
|
|
|
133 |
# Add non interface-specific static-routes.
|
|
|
134 |
if [ -f /etc/sysconfig/static-routes ]; then
|
|
|
135 |
grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
|
|
|
136 |
/sbin/route add -$args
|
|
|
137 |
done
|
|
|
138 |
fi
|
|
|
139 |
# Add non interface-specific static arp entries.
|
|
|
140 |
if [ -f /etc/ethers ]; then
|
|
|
141 |
/sbin/arp -f /etc/ethers
|
|
|
142 |
fi
|
|
|
143 |
|
|
|
144 |
# IPv6 hook (post IPv4 start)
|
|
|
145 |
if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
|
|
|
146 |
/etc/sysconfig/network-scripts/init.ipv6-global start post
|
|
|
147 |
fi
|
|
|
148 |
# Run this again to catch any interface-specific actions
|
|
|
149 |
apply_sysctl
|
|
|
150 |
|
|
|
151 |
touch /var/lock/subsys/network
|
|
|
152 |
|
|
|
153 |
[ -n "${NETWORKDELAY}" ] && /bin/sleep ${NETWORKDELAY}
|
|
|
154 |
;;
|
|
|
155 |
stop)
|
|
|
156 |
[ "$EUID" != "0" ] && exit 4
|
|
|
157 |
# Don't shut the network down if root is on NFS or a network
|
|
|
158 |
# block device.
|
|
|
159 |
rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/" && $3 != "rootfs") { print $3; }}' /proc/mounts)
|
|
|
160 |
rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
|
|
|
161 |
|
|
|
162 |
if [[ "$rootfs" == nfs* || "$rootopts" =~ _r?netdev ]] ; then
|
|
|
163 |
exit 1
|
|
|
164 |
fi
|
|
|
165 |
|
|
|
166 |
# If this is a final shutdown/halt, check for network FS,
|
|
|
167 |
# and unmount them even if the user didn't turn on netfs
|
|
|
168 |
if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
|
|
|
169 |
NETMOUNTS=$(findmnt -m -t nfs,nfs4,smbfs,ncpfs,cifs 2>/dev/null)
|
|
|
170 |
if [ -n "$NETMOUNTS" ] ; then
|
|
|
171 |
/etc/init.d/netfs stop
|
|
|
172 |
fi
|
|
|
173 |
fi
|
|
|
174 |
|
|
|
175 |
vlaninterfaces=""
|
|
|
176 |
xdslinterfaces=""
|
|
|
177 |
bridgeinterfaces=""
|
|
|
178 |
remaining=""
|
|
|
179 |
rc=0
|
|
|
180 |
|
|
|
181 |
# get list of bonding, vpn, and xdsl interfaces
|
|
|
182 |
for i in $interfaces; do
|
|
|
183 |
unset DEVICE TYPE
|
|
|
184 |
eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
|
|
|
185 |
eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
|
|
|
186 |
|
|
|
187 |
if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
|
|
|
188 |
|
|
|
189 |
if [ "$TYPE" = "Bridge" ]; then
|
|
|
190 |
bridgeinterfaces="$bridgeinterfaces $i"
|
|
|
191 |
continue
|
|
|
192 |
fi
|
|
|
193 |
if [ "$TYPE" = "xDSL" ]; then
|
|
|
194 |
xdslinterfaces="$xdslinterfaces $i"
|
|
|
195 |
continue
|
|
|
196 |
fi
|
|
|
197 |
|
|
|
198 |
if [ "${DEVICE%%.*}" != "$DEVICE" -o "${DEVICE##vlan}" != "$DEVICE" ] ; then
|
|
|
199 |
vlaninterfaces="$vlaninterfaces $i"
|
|
|
200 |
continue
|
|
|
201 |
fi
|
|
|
202 |
remaining="$remaining $i"
|
|
|
203 |
done
|
|
|
204 |
|
|
|
205 |
for i in $xdslinterfaces $bridgeinterfaces $vlaninterfaces $remaining; do
|
|
|
206 |
(. ./ifcfg-$i
|
|
|
207 |
if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
|
|
|
208 |
|
|
|
209 |
if ! check_device_down $DEVICE; then
|
|
|
210 |
action $"Shutting down interface $i: " ./ifdown $i boot
|
|
|
211 |
[ $? -ne 0 ] && rc=1
|
|
|
212 |
fi
|
|
|
213 |
)
|
|
|
214 |
done
|
|
|
215 |
|
|
|
216 |
action $"Shutting down loopback interface: " ./ifdown ifcfg-lo
|
|
|
217 |
|
|
|
218 |
sysctl -w net.ipv4.ip_forward=0 > /dev/null 2>&1
|
|
|
219 |
|
|
|
220 |
# IPv6 hook (post IPv4 stop)
|
|
|
221 |
if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
|
|
|
222 |
/etc/sysconfig/network-scripts/init.ipv6-global stop post
|
|
|
223 |
fi
|
|
|
224 |
|
|
|
225 |
rm -f /var/lock/subsys/network
|
|
|
226 |
;;
|
|
|
227 |
status)
|
|
|
228 |
echo $"Configured devices:"
|
|
|
229 |
echo lo $interfaces
|
|
|
230 |
|
|
|
231 |
echo $"Currently active devices:"
|
|
|
232 |
echo $(/sbin/ip -o link show up | awk -F ": " '{ print $2 }')
|
|
|
233 |
;;
|
|
|
234 |
restart|reload|force-reload)
|
|
|
235 |
cd "$CWD"
|
|
|
236 |
$0 stop
|
|
|
237 |
$0 start
|
|
|
238 |
rc=$?
|
|
|
239 |
;;
|
|
|
240 |
*)
|
|
|
241 |
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
|
|
|
242 |
exit 2
|
|
|
243 |
esac
|
|
|
244 |
|
|
|
245 |
exit $rc
|