LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2008, 06:30 PM   #1
TruckStuff
Member
 
Registered: Apr 2002
Posts: 498

Rep: Reputation: 30
Router w/ two networks: NAT one network but not the other?


My setup:
Code:
     eth0
      |
      |
   Router
   /    \
  /      \
eth1    eth2
eth0 is a routable public IP. eth1 is a private LAN (172.16.31.0/24). eth2 is a publicly routable address block from my ISP. Is it possible to only NAT outgoing connections from eth1? I would like for the block on eth2 to expose their correct public IP when connecting out. Currently, these connections are also NAT'ed and so it looks like all connections are coming from the address on eth0. I'm using iptables MASQUERADE to do the NATing:
Code:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
I'm thinking this could be done using some combination of other chains, but I'm not sure the correct combination. Advise is appreciated.
 
Old 04-22-2008, 08:54 PM   #2
xnomad
Member
 
Registered: Jun 2005
Posts: 53

Rep: Reputation: 15
Hi,

This might not be of much help to you. But this is possible and should be fairly easy. I don't ever manually change the iptables myself. I have shorewall installed on all my firewall systems. It is a front end to iptables and makes everything so much easier.

You would just add the line below to /etc/shorewall/masq file.

eth0 eth1

or

eth0 172.16.31.0/24

That's all it takes.

Cheers,
 
Old 04-22-2008, 11:14 PM   #3
dkm999
Member
 
Registered: Nov 2006
Location: Seattle, WA
Distribution: Fedora
Posts: 407

Rep: Reputation: 35
I have a different perspective than xnomad; I like to know what is actually happening in the iptables ruleset, and I find shorewall to be an irritant. Therefore, I recommend the following amendment to your NAT rule:
Code:
iptables -t nat POSTROUTING -o eth0 -s 172.16.31.0/255.255.255.0 -j SNAT --to-source {your eth0 address}
This rule will accomplish the NAT only for your private network address block, and will forward stuff from eth2 (which has IP addresses outside the specified block) unmolested.

Parenthetically, the MASQUERADE target is really only intended for use on Internet connection links that are subject to changeable IP addresses (like dial-up lines). The distinction between MASQUERADE and SNAT is that connections are remembered when a link goes down under SNAT, but are forgotten under MASQUERADE. So if you have a DHCP link that goes down a lot, use MASQUERADE; if the IP of eth0 is constant, use SNAT.
 
Old 04-23-2008, 10:57 AM   #4
TruckStuff
Member
 
Registered: Apr 2002
Posts: 498

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by dkm999 View Post
Therefore, I recommend the following amendment to your NAT rule:
Code:
iptables -t nat POSTROUTING -o eth0 -s 172.16.31.0/255.255.255.0 -j SNAT --to-source {your eth0 address}
This rule will accomplish the NAT only for your private network address block, and will forward stuff from eth2 (which has IP addresses outside the specified block) unmolested.
<edit>
Err... whoops nm. Yup, that did the trick. Thanks!
</edit>

Last edited by TruckStuff; 04-23-2008 at 11:36 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux box as a router between two networks LinuxLover Linux - Server 1 08-04-2007 01:25 AM
RH8 server is NAT router, but getting a new router. WorldBuilder Linux - Networking 1 06-08-2006 05:54 PM
Wireless Router to Connect 2+ Wired Networks fadeone Linux - Wireless Networking 1 03-23-2006 03:14 PM
2 networks and 2 internet connections on linux router seer_tenedos Linux - Networking 6 03-27-2005 07:24 AM
Cannot bridge networks on FC2/VPC, yet NAT(Shared) works fine quinthar Linux - Networking 1 09-24-2004 08:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration