How I set up my own NAT-network


Computers

PII-350 192MB
Ethernet: Realtek Chipset
OS: Windows 2000

P-MMX 266 64MB
Ethernet: 2 x D-Link DFE-530TX (VIA-RHINE chipset)
OS: Linux
Slackware base (distribution)
kernel 2.4.0 (custom compile)
iptables (compile)
iproute2 (compile)


Netinfo

ISP-info

My IP 172.16.48.248
Netmask 255.255.248.0
Gateway 172.16.55.254

Localnet-info

Linux

IP 10.0.0.1
Netmask 255.255.255.0
Gateway 172.16.55.254 (there is only one default gateway)

Windows

IP 10.0.0.2
Netmask 255.255.255.0
Gateway 10.0.0.1

# eth0 is on the Lan where my ISP:s gateway is through a Cable Modem
# eth1 is connected to my Windows Computer by a crossed tp-cable
# 10.0.0.1 and 10.0.0.2 I have set myself


Startup code

# First the standard ethernet setup
/sbin/ifconfig lo 127.0.0.1                                                     # Loopback
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo                             # Route for loopback
/sbin/ifconfig eth0 172.16.48.248 broadcast 172.16.55.255 netmask 255.255.248.0 # Outer interface
/sbin/ifconfig eth1 10.0.0.1 broadcast 10.0.0.255 netmask 255.255.255.0         # Inner interface
/sbin/route add default gw 172.16.55.254 netmask 0.0.0.0 metric 1               # Default gateway
# Pass a parameter to the kernel that it should do forwarding:
echo 1 > /proc/sys/net/ipv4/ip_forward
# I have previously done
# echo 200 Burken >> /etc/iproute2/rc_rtables
ip rule add from 10.0.0.2 table Burken                                          # Set route source ip 10.0.0.2 and make rule
ip route add default via 172.16.55.254 dev eth0 table Burken                    # Set the gateway for source ip 10.0.0.2 to default gateway on outer interface
ip route flush cache                                                            # Well, flush
iptables -t nat -I POSTROUTING -s 10.0.0.2 -j SNAT --to-source 172.16.48.248    # This acctually sets the NAT-rule
                                                                                # States that it should do POSTROUTING where the source-adress is
                                                                                # 10.0.0.2 and to mask the ip to 172.16.48.248
                                                                                # "-j SNAT" is the action to be performed

Author Per-Olof Pettersson