NAT Routing on Linux

Linux configure Network Address Translation or NAT

# echo "1" > /proc/sys/net/ipv4/ip_forward
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# iptables -L
####### ROUTER / GATEWAY #######

# Flush rules from iptables
iptables -F

# Flush rules from nat table in iptables
iptables -t nat -F

# IP Forwarding (global)
echo 1 > /proc/sys/net/ipv4/ip_forward
# oder (für jedes Interface einzeln)
echo 1 > /proc/sys/net/ipv4/conf/eth0/forwarding

# Regeln definieren
INET_IF=eth0
LOCAL_IF=eth4
iptables -t nat -A POSTROUTING -o $INET_IF -j MASQUERADE
iptables -A FORWARD -i $INET_IF -o $LOCAL_IF -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $LOCAL_IF -o $INET_IF -j ACCEPT

# Überprüfen
iptables -t nat -v --list
iptables -v --list

#######  CLIENT #######

GATEWAY=192.168.1.1
route add default gw $GATEWAY

Leave a Reply

Your email address will not be published. Required fields are marked *