2 # Filename: grml-router
3 # Purpose: set up your box as NAT-router
4 # Authors: grml-team (grml.org), Ulrich Dangel <schula@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 ################################################################################
9 CONFIG_FILE=/etc/grml/routersetup
10 . /etc/grml/lsb-functions
11 . /etc/grml/net-functions
12 . /etc/grml/script-functions
16 if ! [ -r $CONFIG_FILE ] ; then
17 eerror "$CONFIG_FILE could not be read."
23 if [ -z "$OUTDEV" ] ; then
24 eewarn "Outgoing device is not set in $CONFIG_FILE"
25 eewarn "Setting Outgoing device to auto"
31 OUTDEV=$(defaultGWDev)
32 if [ -z "$OUTDEV" ] ; then
33 eerror "The outgoing device could not be determined."
34 eerror "Please adjust OUTDEV in $CONFIG_FILE"
40 [ -n "$IPTABLES" ] || IPTABLES=/sbin/iptables
42 check4progs $IPTABLES || exit 1
46 einfo "Adjusting kernel variables (net.ipv4.*)"
47 sysctl -w net.ipv4.conf.all.rp_filter=1 1>/dev/null && \
48 sysctl -w net.ipv4.conf.all.log_martians=1 1>/dev/null && \
49 sysctl -w net.ipv4.ip_forward=1 1>/dev/null
51 einfo "Setting up iptables rule"
54 einfo "Adding masquarade rule"
55 $IPTABLES -t nat -A POSTROUTING -o $OUTDEV -j MASQUERADE
61 einfo "Resetting kernel variables"
62 sysctl -w net.ipv4.ip_forward=0 1>/dev/null && \
63 sysctl -w net.ipv4.conf.all.log_martians=0 1>/dev/null
66 einfo "Removing iptables rule"
67 $IPTABLES -t nat -D POSTROUTING -o $OUTDEV -j MASQUERADE
78 einfo "$0 - script which turns on router capabilities (NAT)"
79 einfo "Configure it via $CONFIG_FILE" ; eend 0
83 echo "Usage: $0 {start|stop|restart|info}"
88 ## END OF FILE #################################################################
89 # vim: ft=sh expandtab ai