NAT

From blagwiki
Jump to: navigation, search

This is a simple config for doing NAT. Quick & dirty. :)

You can copy this script to /usr/local/sbin/nat-on and then have it run from /etc/rc.d/rc.local so it comes up on boot. Don't forget to

chmod +x /usr/local/sbin/nat-on


eth0 is the interface with the Internet connection. Substitute your interface with the Internet connection for eth0 (e.g. eth1, wlan0, whatever).

#!/bin/sh
# insert masquerade module
modprobe ipt_MASQUERADE

# flush old rules
iptables -F
iptables -t nat -F
iptables -t mangle -F

# turn on NAT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# forward IPs
echo 1 > /proc/sys/net/ipv4/ip_forward