Skip to content

Instantly share code, notes, and snippets.

@briandunn
Created August 7, 2010 23:29
Show Gist options
  • Save briandunn/513318 to your computer and use it in GitHub Desktop.
Save briandunn/513318 to your computer and use it in GitHub Desktop.
/etc/firewall.user
# This assumes your gateway is an OpenWRT box at 192.168.1.1,
# your lan is 192.168.1.0/24,
# and your OpenWRT stock chains are intact.
# It is different than the built in /etc/config/firewall rules in that it allows you to address
# your linux box at example.com, whether your request originates from within your lan, or from outside.
WIN_XP_HOST=192.168.1.184
LINUX_HOST=192.168.1.202
WWW_NAME=example.com
forward () {
DESTINATION_HOST=$1
PORT_LIST=$2
iptables -A forwarding_wan -d $DESTINATION_HOST -j ACCEPT
iptables -t nat -A prerouting_wan -p tcp -m multiport --dports $PORT_LIST -j DNAT --to $DESTINATION_HOST
iptables -t nat -A prerouting_rule -d $WWW_NAME -s 192.168.1.0/24 -p tcp -m multiport --dports $PORT_LIST -j DNAT --to $DESTINATION_HOST
iptables -t nat -A postrouting_rule -d $DESTINATION_HOST -s 192.168.1.0/24 -p tcp -m multiport --dports $PORT_LIST -j SNAT --to 192.168.1.1
}
forward $WIN_XP_HOST 21,3389,50000,50001,50002,50003,50004,50005
forward $LINUX_HOST 22,80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment