Traffic Forwarder using IPTables: Difference between revisions

From Leo's Notes
This page was last edited on 15 April 2013, at 05:05.
Created page with "To make a linux box act as the gateway for a NAT (in this example, 10.10.2.0/24) using IPTables, run: # Enables forwarding echo 1 > /proc/sys/net/ipv4/ip_forward # Defin..."
 
No edit summary
Line 9: Line 9:
  # Route traffic destined to 10.10.2.0/24 to $INSIDE
  # Route traffic destined to 10.10.2.0/24 to $INSIDE
  route add -net 10.10.2.0/24 dev $INSIDE
  route add -net 10.10.2.0/24 dev $INSIDE
  # Masquerade traffic going to $OUTSIDE
  # Masquerade traffic going to $OUTSIDE
  iptables -t nat -A POSTROUTING -o $OUTSIDE -j MASQUERADE
  iptables -t nat -A POSTROUTING -o $OUTSIDE -j MASQUERADE
  # Forward traffic coming from $INSIDE
  # Forward traffic coming from $INSIDE
  iptables -A FORWARD -i $INSIDE -j ACCEPT
  iptables -A FORWARD -i $INSIDE -j ACCEPT


Add additional tweaks as required to the firewall.
Add additional tweaks as required to the firewall. You will probably want to run <code>iptables-save</code> to make the changes persistent.

Revision as of 05:05, 15 April 2013

To make a linux box act as the gateway for a NAT (in this example, 10.10.2.0/24) using IPTables, run:

# Enables forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Define $INSIDE as the interface going into the NAT
# Define $OUTSIDE as the interface going to the internet

# Route traffic destined to 10.10.2.0/24 to $INSIDE
route add -net 10.10.2.0/24 dev $INSIDE

# Masquerade traffic going to $OUTSIDE
iptables -t nat -A POSTROUTING -o $OUTSIDE -j MASQUERADE

# Forward traffic coming from $INSIDE
iptables -A FORWARD -i $INSIDE -j ACCEPT

Add additional tweaks as required to the firewall. You will probably want to run iptables-save to make the changes persistent.