Skip to content

Instantly share code, notes, and snippets.

@versatran01
Last active August 29, 2015 14:12
Show Gist options
  • Save versatran01/f48122f30ff0ab5c5337 to your computer and use it in GitHub Desktop.
Save versatran01/f48122f30ff0ab5c5337 to your computer and use it in GitHub Desktop.
Forward packet from wlan0 to eth0
function sharenet()
{
if [ $# -eq 0 ]; then
echo "usage: sharenet <on/off>"
return 0
fi
local if_from=wlan0
local if_to=eth0
# check command-line commands
cmd=$1
case $cmd in
on )
sudo su -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
echo "Enable sharing internet from $if_from to $if_to"
sudo /sbin/iptables -A FORWARD -i $if_to -o $if_from -j ACCEPT
sudo /sbin/iptables -A FORWARD -i $if_from -o $if_to -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo /sbin/iptables -t nat -A POSTROUTING -o $if_from -j MASQUERADE
;;
off )
sudo su -c "echo 0 > /proc/sys/net/ipv4/ip_forward"
echo "Disable sharing internet from $if_from to $if_to"
;;
* )
echo "sharenet: $1: invalid command"
echo "usage: sharenet <on/off>"
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment