Welcome to Dream.In.Code
Getting Help is Easy!

Join 99,783 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,530 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Setting Up NAT

 
Reply to this topicStart new topic

> Setting Up NAT, Network Address Translation

Nova Dragoon
Group Icon



post 9 Aug, 2006 - 09:27 AM
Post #1


For this tutorial, we are using a modern linux os with IPTables, on a computer with two ethernet cards.
All commands run should be done with root privs


[The Phyical Setup]
Connect to the first ethernet card (eth0) the line that gets this computer connected to the internet.
Connect to the second ethernet card (eth1) to a hub/switch
Connect all clients to be NAT'ed to the hub/switch.

Logical Setup
The NAT'ed network will be 192.168.0.0/24
And the NAT'ing computer will be 192.168.0.1 on eth1

On the NAT'ing computer:
ifconfig eth1 192.168.0.1 netmask 255.255.255.0



Enabling IP Forwarding in the Kernel
Check and see if your computer is already doing forwarding with:
sysctl net.ipv4.ip_forward
If what it returns is 0, its off
if what it return is 1 then its already enabled.

Turn it on now by running:
sysctl -w net.ipv4.ip_forward=1

and to enable it at boot, add this line to your /etc/sysctl.conf:
net.ipv4.ip_forward = 1

Now restart your networking:
/etc/init.d/networking restart


Forwarding Rules in IPTables
CODE

iptables -A FORWARD -i eth1 -o eth0 -s 192.168.0.0/24 -m state --state NEW -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE




Finally setup you clients to have a 192.168.0.0/24 address, with the gateway as 192.168.0.1


Register to Make This Ad Go Away!


Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 7/25/08 01:07AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month
-->