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
14 if [ $UID != 0 ]; then
15 eerror "Error: become root before starting $0"
19 if ! [ -r $CONFIG_FILE ] ; then
20 eerror "$CONFIG_FILE could not be read."
26 if [ -z "$OUTDEV" ] ; then
27 eewarn "Outgoing device is not set in $CONFIG_FILE"
28 eewarn "Setting Outgoing device to auto"
34 OUTDEV=$(defaultGWDev)
35 if [ -z "$OUTDEV" ] ; then
36 eerror "The outgoing device could not be determined."
37 eerror "Please adjust OUTDEV in $CONFIG_FILE"
43 [ -n "$IPTABLES" ] || IPTABLES=/sbin/iptables
45 check4progs $IPTABLES || exit 1
49 einfo "Adjusting kernel variables (net.ipv4.*)"
50 sysctl -w net.ipv4.conf.all.rp_filter=1 1>/dev/null && \
51 sysctl -w net.ipv4.conf.all.log_martians=1 1>/dev/null && \
52 sysctl -w net.ipv4.ip_forward=1 1>/dev/null
54 einfo "Setting up iptables rule"
57 einfo "Adding masquarade rule"
58 $IPTABLES -t nat -A POSTROUTING -o $OUTDEV -j MASQUERADE
64 einfo "Resetting kernel variables"
65 sysctl -w net.ipv4.ip_forward=0 1>/dev/null && \
66 sysctl -w net.ipv4.conf.all.log_martians=0 1>/dev/null
69 einfo "Removing iptables rule"
70 $IPTABLES -t nat -D POSTROUTING -o $OUTDEV -j MASQUERADE
81 einfo "$0 - script which turns on router capabilities (NAT)"
82 einfo "Configure it via $CONFIG_FILE" ; eend 0
86 echo "Usage: $0 {start|stop|restart|info}"
91 ## END OF FILE #################################################################
92 # vim: ft=sh expandtab ai