]>
Commit | Line | Data |
---|---|---|
9c16cd92 MT |
1 | #!/bin/sh |
2 | ######################################################################## | |
3 | # Begin $network_devices/services/ipv4-static | |
4 | # | |
5 | # Description : IPV4 Static Boot Script | |
6 | # | |
7 | # Authors : Nathan Coulson - nathan@linuxfromscratch.org | |
8 | # Kevin P. Fleming - kpfleming@linuxfromscratch.org | |
9 | # Michael Tremer - mitch@ipfire.org | |
10 | # | |
11 | # Version : 00.00 | |
12 | # | |
13 | # Notes : | |
14 | # | |
15 | ######################################################################## | |
16 | ||
17 | . /etc/sysconfig/rc | |
18 | . ${rc_functions} | |
19 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
20 | ||
21 | if [ -z "${BROADCAST}" ]; then | |
22 | boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE} | |
23 | echo_failure | |
24 | exit 1 | |
25 | fi | |
26 | ||
27 | if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then | |
28 | PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-` | |
29 | args="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}" | |
30 | else | |
31 | boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE} | |
32 | echo_failure | |
33 | exit 1 | |
34 | fi | |
35 | ||
36 | case "${2}" in | |
37 | up) | |
38 | boot_mesg "Adding IPv4 address ${ADDRESS} to the ${1} interface..." | |
39 | ip addr add ${args} dev ${1} | |
40 | evaluate_retval | |
41 | ||
42 | if [ -n "${GATEWAY}" ]; then | |
43 | if ip route | grep -q default; then | |
44 | boot_mesg "Gateway already setup; skipping." ${WARNING} | |
45 | echo_warning | |
46 | else | |
47 | boot_mesg "Setting up default gateway..." | |
f3770039 | 48 | echo $DEFAULT_GATEWAY > /var/ipfire/red/remote-ipaddress |
9c16cd92 MT |
49 | ip route add default via ${GATEWAY} dev ${1} |
50 | evaluate_retval | |
f3770039 MT |
51 | boot_mesg "Registering DNS server..." |
52 | echo $DNS1 > /var/ipfire/red/dns1 | |
53 | echo $DNS2 > /var/ipfire/red/dns2 | |
54 | echo $ADDRESS > /var/ipfire/red/local-ipaddress | |
55 | evaluate_retval | |
56 | fi | |
9c16cd92 MT |
57 | fi |
58 | ;; | |
59 | ||
60 | down) | |
61 | if [ -n "${GATEWAY}" ]; then | |
62 | boot_mesg "Removing default gateway..." | |
63 | ip route del default | |
64 | evaluate_retval | |
65 | fi | |
66 | ||
67 | boot_mesg "Removing IPv4 address ${ADDRESS} from the ${1} interface..." | |
68 | ip addr del ${args} dev ${1} | |
69 | evaluate_retval | |
70 | ;; | |
71 | ||
72 | *) | |
73 | echo "Usage: ${0} [interface] {up|down}" | |
74 | exit 1 | |
75 | ;; | |
76 | esac | |
77 | ||
78 | # End $network_devices/services/ipv4-static |