Wednesday, September 23, 2009

NAT without ICS using Windows XP and a Linux workstation

So I had a Windows system with an Internet connection that I wanted to share with a headless Linux system. Initially I tried Windows XP ICS but I ran into a limitation that didn't exist in earlier versions of the software.

The limitation is the device connecting to the internal network (in this case my headless Linux system) must be assigned the IP address 192.168.0.1. This was conflicting with my wireless router and as shown here Microsoft doesn't support or even suggest a work around so you're left scratching your head. Many message board responses break down to "just connect the other system to your router," but as I personally know there are situations where this is not always possible.

Thankfully there is another way to do NAT in Windows XP. All it involves is a little bit of command line magic and some basic administration tools. As described by Microsoft, "Netsh is a command-line scripting utility that allows you to, either locally or remotely, display or modify the network configuration of a computer that is currently running." It was pre-installed on my Windows XP Professional system. Ok, let's get down to business.

The first thing you should do is change the startup type for the "Routing and Remote Access" service. You do this by going to Control Panel > Administrative Tools > Services, finding the "Routing and Remote Access" item in the name column, double click it and change the "Startup type" to "Automatic."

Next open up your registry by going to Start > run and typing in "regedit". Now go to My Computer > HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > Services > Tcpip > Parameters and change the "IPEnableRouter" value to 1.

Restart your system.

Now make sure the "Routing and Remote Access" service is stopped for the next steps.

Find out the names of your two network devices by going to Control Panel > Network Connections. Open up the command line by going to Start > run and typing in "cmd". Enter the following changing "INTERNET DEVICE NAME" and "INTERNAL NETWORK NAME" to the appropriate values:
pushd routing ip nat
uninstall
install
set global tcptimeoutmins=1440 udptimeoutmins=1 loglevel=ERROR
add interface name="INTERNET DEVICE NAME" mode=FULL
add interface name="INTERNAL NETWORK NAME" mode=PRIVATE
popd
exit
Now enable the "Routing and Remote Access" service. Congratulations, you now have NAT set up properly on your Windows XP system. Now it's time to setup your Linux system with the proper gateway and DNS.

To specify the gateway enter the following in the command line of your Linux system changing 192.168.1.1 to the IP address of your Windows XP system on the internal network:
route add default gw 192.168.1.1 eth0
Now try pinging an Internet IP address like google at 74.125.91.104. If that works then your gateway is setup correctly and NAT is working on your Windows XP system. If it doesn't try restarting the Windows XP system and try pinging google again.

Now all you have to do is setup the DNS for your Linux system. All you have to do is add a line to /etc/resolv.conf with the following command, changing 192.168.0.1 to your routers IP address or your desired DNS address:
echo nameserver 192.168.0.1 >> /etc/resolv.conf
At this point everything should be working. Enjoy!

No comments:

Post a Comment