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 # Latest change: Sam Okt 07 23:18:38 CEST 2006 [mika]
8 ################################################################################
13 CONFIG_FILE=/etc/grml/routersetup
14 . /etc/grml/lsb-functions
15 . /etc/grml/net-functions
16 . /etc/grml/script-functions
18 if [ $UID != 0 ]; then
19 eerror "Error: become root before starting $0"
23 if ! [ -r $CONFIG_FILE ] ; then
24 eerror "$CONFIG_FILE could not be read."
30 if [ -z "$OUTDEV" ] ; then
31 eewarn "Outgoing device is not set in $CONFIG_FILE"
32 eewarn "Setting Outgoing device to auto"
38 OUTDEV=$(defaultGWDev)
39 if [ -z "$OUTDEV" ] ; then
40 eerror "The outgoing device could not be determined."
41 eerror "Please adjust OUTDEV in $CONFIG_FILE"
47 [ -n "$IPTABLES" ] || IPTABLES=/sbin/iptables
49 check4progs $IPTABLES || exit 1
53 einfo "Adjusting kernel variables (net.ipv4.*)"
54 sysctl -w net.ipv4.conf.all.rp_filter=1 1>/dev/null && \
55 sysctl -w net.ipv4.conf.all.log_martians=1 1>/dev/null && \
56 sysctl -w net.ipv4.ip_forward=1 1>/dev/null
58 einfo "Setting up iptables rule"
61 einfo "Adding masquarade rule"
62 $IPTABLES -t nat -A POSTROUTING -o $OUTDEV -j MASQUERADE
68 einfo "Resetting kernel variables"
69 sysctl -w net.ipv4.ip_forward=0 1>/dev/null && \
70 sysctl -w net.ipv4.conf.all.log_martians=0 1>/dev/null
73 einfo "Removing iptables rule"
74 $IPTABLES -t nat -D POSTROUTING -o $OUTDEV -j MASQUERADE
85 einfo "$0 - script which turns on router capabilities (NAT)"
86 einfo "Configure it via $CONFIG_FILE" ; eend 0
90 echo "Usage: $0 {start|stop|restart|info}"
95 ## END OF FILE #################################################################
96 # vim: ft=sh expandtab ai