Skip to content

Instantly share code, notes, and snippets.

@diablowu
Created March 10, 2015 01:30
Show Gist options
  • Save diablowu/4a6761e231a551f44d63 to your computer and use it in GitHub Desktop.
Save diablowu/4a6761e231a551f44d63 to your computer and use it in GitHub Desktop.
add a nat rule of iptables
#!/bin/bash
pro='tcp'
cntip=$1
cntport=$2
hostip=$3
hostport=$4
sudo iptables -t nat -A PREROUTING -m $pro -p $pro --dport $hostport -j DNAT --to-destination $cntip:$cntport
sudo iptables -t nat -A POSTROUTING -m $pro -p $pro --dport $cntport -d $cntip -j SNAT --to-source $hostip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment