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 ################################################################################
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
19 ewarn "Could not read $CONFIG_FILE"
22 # defaults if unconfigured
23 [ -n "$OUTDEV" ] || OUTDEV=auto
24 [ -n "$IPTABLES" ] || IPTABLES=/sbin/iptables
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"
37 check4progs $IPTABLES || exit 1
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
46 einfo "Setting up iptables rule"
49 einfo "Adding masquarade rule"
50 $IPTABLES -t nat -A POSTROUTING -o $OUTDEV -j MASQUERADE
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
61 einfo "Removing iptables rule"
62 $IPTABLES -t nat -D POSTROUTING -o $OUTDEV -j MASQUERADE
73 einfo "$0 - script which turns on router capabilities (NAT)"
74 einfo "Configure it via $CONFIG_FILE" ; eend 0
78 echo "Usage: $0 {start|stop|restart|info}"
83 ## END OF FILE #################################################################
84 # vim: ft=sh expandtab ai