Friday, November 6, 2009

Share your 3G/HSDPA connection with friends using simple Linux router/gateway

1. Copy following script to a file (say router_man.sh )
2. Set your local interface and Internet interface in the script
3. Make the file executable (use chmod +x router_man.sh)
4. To start(add) the router
router_man.sh -a

To stop(delete) the router
router_man.sh -d

To see the information
router_man.sh -s

5. In your friends laptop set your local IP as the gateway(router)

thats all...

#!/bin/bash
# Copyright (C) 2008 Nayanajit Mahendra Laxaman mail: nmlaxaman@gmail.com

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

INTERNET=ppp0
LOCAL=eth0
if [[ $1 == '-a' ]]
then
iptables --table nat -A POSTROUTING --out-interface $INTERNET -j MASQUERADE
iptables -A FORWARD --in-interface $LOCAL -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward
elif [[ $1 == '-d' ]]
then
iptables --table nat -D POSTROUTING --out-interface $INTERNET -j MASQUERADE
iptables -D FORWARD --in-interface $LOCAL -j ACCEPT
echo 0 > /proc/sys/net/ipv4/ip_forward
elif [[ $1 == '-s' ]]
then
echo "==iptables=="
iptables -nL
iptables -t nat -nL
echo "==ip_forward=="
cat /proc/sys/net/ipv4/ip_forward
else
echo "Invalide param!"
echo "try -a for add or -d for delete -s for status"
fi


No comments:

Post a Comment