啟動 Gentoo 的 NAT 服務

打開 IP forwarding 功能,修改 /etc/sysctl.conf 
#Enable packet forwarding 
net.ipv4.ip_forward = 1 

將下面的指令存成 nat.sh 
#!/bin/sh 
IPTABLES='/sbin/iptables' 

# Set interface values 
INTIF='eth0' 
EXTIF='ppp0' 

# enable ip forwarding in the kernel 
/bin/echo 1 > /proc/sys/net/ipv4/ip_forward 

# flush rules and delete chains 
$IPTABLES -F 
$IPTABLES -X 

#Enable masquerading to allow LAN internet access 
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE 

#Forward LAN traffic from LAN $INTIF to Internet $EXTIF 
$IPTABLES -A FORWARD -i $INTIF -o $EXTIF -m state --state NEW,ESTABLISHED -j ACCEPT 

執行上面的 script 後儲存 iptables 
/etc/init.d/iptables save 

加到系統啟動列表中 
rc-update add iptables default