Skip to content

Instantly share code, notes, and snippets.

@jantore
Created July 31, 2016 19:07
Show Gist options
  • Save jantore/8861c80a9d34ac3a5c5e48dace97d729 to your computer and use it in GitHub Desktop.
Save jantore/8861c80a9d34ac3a5c5e48dace97d729 to your computer and use it in GitHub Desktop.
NAT-PMP hole punching with natpmpc and ferm
def &FORWARD($interface, $port, $dest) = {
table nat chain PREROUTING interface $interface proto tcp dport $port mod comment comment "forward $port" DNAT to $dest;
table filter chain FORWARD interface $interface proto tcp dport $port daddr $dest ACCEPT;
}
@hook post "pmp-request-forwards 86400";
&FORWARD(eth0, 49152, 192.0.2.1);
&FORWARD(eth0, 49153, 192.0.2.2);
#!/bin/sh
iptables -n -tnat -L PREROUTING | sed -rne 's#^.*/\* forward ([^ ]+) \*/.*$#\1#p'
#!/bin/sh
LIFETIME=$1
if [ -z $LIFETIME ]; then
echo "Usage: $0 <lifetime>"
exit
fi
for PORT in $( pmp-get-forwards ); do
natpmpc -a $PORT $PORT tcp $LIFETIME >/dev/null 2>&1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment