User Tools

Site Tools


nat

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

nat [2017/01/05 06:21] (current)
felixonmars created
Line 1: Line 1:
 +==== Enable IP Forwarding First ====
 +<​code>​
 +sed -i '​s/​.*net\.ipv4\.ip_forward.*/​net.ipv4.ip_forward = 1/' /​etc/​sysctl.conf
 +sysctl -p
 +</​code>​
 +
 +==== NAT using iptables ====
 +
 +=== Recommended Way (If IP is static) ===
 +<​code>​
 +iptables -t nat -A POSTROUTING -s 10.0.0.0/8 -j SNAT --to-source <IP>
 +</​code>​
 +
 +=== Another Way (OpenVZ won't work this way) ===
 +<​code>​
 +iptables -t nat -A POSTROUTING -s 10.0.0.0/8 -j MASQUERADE
 +</​code>​
 +
 +Or if you want to MASQUERADE all interfaces:
 +<​code>​
 +iptables -t nat -A POSTROUTING ! -o lo -j MASQUERADE
 +</​code>​
  
nat.txt ยท Last modified: 2017/01/05 06:21 by felixonmars