Disable default configuration in routersetup config file, use defaults in main scripts
[grml-network.git] / sbin / grml-router
1 #!/bin/sh
2 # Filename:      grml-router
3 # Purpose:       set up your box as NAT-router
4 # Authors:       grml-team (grml.org), Ulrich Dangel <mru@grml.org>, Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 CONFIG_FILE=/etc/grml/routersetup
10 . /etc/grml/lsb-functions
11 . /etc/grml/net-functions
12 . /etc/grml/script-functions
13
14 check4root || exit 1
15
16 if [ -r "$CONFIG_FILE" ] ; then
17   . "$CONFIG_FILE"
18 else
19   ewarn "Could not read $CONFIG_FILE"
20 fi
21
22 # defaults if unconfigured
23 [ -n "$OUTDEV" ]   || OUTDEV=auto
24 [ -n "$IPTABLES" ] || IPTABLES=/sbin/iptables
25
26 case "$OUTDEV" in
27   auto|default)
28     OUTDEV=$(defaultGWDev)
29     if [ -z "$OUTDEV" ] ; then
30       eerror "The outgoing device could not be determined."
31       eerror "Please adjust OUTDEV in $CONFIG_FILE or set OUTDEV as environment variable"
32       exit 1
33     fi
34     ;;
35 esac
36
37 check4progs $IPTABLES || exit 1
38
39 case "$1" in
40     start)
41         einfo "Adjusting kernel variables (net.ipv4.*)"
42           sysctl -w net.ipv4.conf.all.rp_filter=1    1>/dev/null && \
43           sysctl -w net.ipv4.conf.all.log_martians=1 1>/dev/null && \
44           sysctl -w net.ipv4.ip_forward=1            1>/dev/null
45         eend $?
46         einfo "Setting up iptables rule"
47           eindent
48
49             einfo "Adding masquarade rule"
50             $IPTABLES -t nat -A POSTROUTING -o $OUTDEV -j MASQUERADE
51             eend $?
52           eoutdent
53    ;;
54
55    stop)
56        einfo "Resetting kernel variables"
57          sysctl -w net.ipv4.ip_forward=0            1>/dev/null && \
58          sysctl -w net.ipv4.conf.all.log_martians=0 1>/dev/null
59        eend $?
60
61        einfo "Removing iptables rule"
62          $IPTABLES -t nat -D POSTROUTING -o $OUTDEV -j MASQUERADE
63        eend $?
64    ;;
65
66    restart)
67         $0 stop
68         sleep 1
69         $0 start
70    ;;
71
72    info)
73     einfo "$0 - script which turns on router capabilities (NAT)"
74     einfo "Configure it via $CONFIG_FILE" ; eend 0
75    ;;
76
77    *)
78     echo "Usage: $0 {start|stop|restart|info}"
79     exit 1
80    ;;
81 esac
82
83 ## END OF FILE #################################################################
84 # vim: ft=sh expandtab ai