iptables端口转发

  1. #本机端口转发
  2. iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  3. iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $public_port -j REDIRECT --to-ports $private_port
  4.  
  5. #外网端口转发需要开启ip_forward
  6. echo "1" > /proc/sys/net/ipv4/ip_forward
  7. iptables -t nat -A PREROUTING -p tcp -m tcp --dport $local_port -j DNAT --to-destination $dest:$port
  8. iptables -t nat -A POSTROUTING -p tcp -m tcp --dport $local_port -j SNAT --to-source $local_ip

强帖留名: