Skip to content

Instantly share code, notes, and snippets.

@amboxer21
Last active January 6, 2020 02:34
Show Gist options
  • Save amboxer21/52636b65c20b15741bac0939a36668dd to your computer and use it in GitHub Desktop.
Save amboxer21/52636b65c20b15741bac0939a36668dd to your computer and use it in GitHub Desktop.
iptable rules for my 1200ac openwrt router to allow remote play on Chiaki
IPADDR='192.168.1.224'
SOURCE='192.168.1.0/24'
for PORT in 80 443 9295; do
iptables -I FORWARD -p tcp ! --source $SOURCE -d $IPADDR --dport $PORT -j ACCEPT ;
iptables -I PREROUTING -t nat -p tcp ! --source $SOURCE --dport $PORT -j DNAT --to $IPADDR:$PORT ;
done
for PORT in 9296 9297; do
iptables -I FORWARD -p udp ! --source $SOURCE -d $IPADDR --dport $PORT -j ACCEPT ;
iptables -I PREROUTING -t nat -p udp ! --source $SOURCE --dport $PORT -j DNAT --to $IPADDR:$PORT ;
done
@amboxer21
Copy link
Author

amboxer21 commented Jan 6, 2020

The above iptables rules will forward all of the necessary ports to use Chiaki unless you are on the LAN! If this is not done then no one on the LAN will be able to use the internet. You don't need to use Chiaki while you are on the LAN anyway. In case you do for odd reason though then you can omit the following portion of the iptables rules '! --source $SOURCE'. This will forward everyone's port requests whether it be over the LAN or WAN.

Example NATing for all(! Source IP omitted)

IPADDR='192.168.1.224'
SOURCE='192.168.1.0/24'

for PORT in 80 443 9295; do
    iptables -I FORWARD -p tcp -d $IPADDR --dport $PORT -j ACCEPT ;
    iptables -I PREROUTING -t nat -p tcp --dport $PORT -j DNAT --to $IPADDR:$PORT ;
done

for PORT in 9296 9297; do
    iptables -I FORWARD -p udp -d $IPADDR --dport $PORT -j ACCEPT ;
    iptables -I PREROUTING -t nat -p udp --dport $PORT -j DNAT --to $IPADDR:$PORT ;
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment