Networking Forums

Networking Forums > Computer Networking > Linux Networking > SNAT/DNAT works but doesn't look right. Looking for feedback.

Reply
Thread Tools Display Modes

SNAT/DNAT works but doesn't look right. Looking for feedback.

 
 
Gary Smith
Guest
Posts: n/a

 
      09-24-2003, 10:31 PM
It works, but did I do it right?

Config is as follows

eth0 -> Internet 22.44.66.x IP's
eth1 -> DMZ 10.0.0.x IP's
eth2 -> LAN 10.0.1.x IP's
ppp+ -> VPN 10.0.2.x IP's

Below is what we did to make a machine work in the DMZ. We are
defining "work" very loosly.

# Route everything coming in on 22.x.x.141 to 10.0.0.141. This works
fine
[0:0]-A PREROUTING -d 22.44.66.141 -j DNAT --to-destination 10.0.0.141

# notice the double rule here. look at the explanation below
[0:0] -A POSTROUTING -o eth0 -s 10.0.0.141 -j SNAT --to-source
22.44.66.141
[0:0] -A POSTROUTING -d 10.0.0.141 -s 10.0.0.141 -j SNAT --to-source
22.44.66.141

# Generic address for going out through
[0:0] -A POSTROUTING -o eth0 -j SNAT --to-source 22.44.66.254

# So firewall can hit the DMZ machine using the external IP
[0:0] -A OUTPUT -d 22.44.66.141 -j DNAT --to-destination 10.0.0.141


If we logged into machine 10.0.0.141 and ping'ed 10.0.0.141 it would
work just fine but pinging 22.44.66.141 would then fail. Traceroute
would fail as well. Looking into the firewall server log we would
find that 10.0.0.141 was going directly to 10.0.0.141. It wasn't
violating a rule or anything, it just didn't work. (enabled general
logging for firewall for diagnostics)

So we changed rule "-A POSTROUTING -eth0 -s 10.0.0.141 -j SNAT
--to-source 22.44.66.141" to "-A POSTROUTING -s 10.0.0.141 -j SNAT
--to-source 22.44.66.141". We could now successfully ping the machine
by using the external IP pointing to the same machine. Remember, we
are ping from 10.0.0.141 to 22.44.66.141. But then another odditity
occured. The machine could no longer ping anything on any of the ppp+
nodes. These are VPN connections. It could ping anything on the eth2
LAN that was allowable by filtering rules.

So, I added that -d 10.0.0141 -s 10.0.0.141 and restablished the
original rule. It all works great but...

I have to do this for 128 IP, which means a bunch of cut and pasting
(actually I wrote a 4 line php script to cheat) but this looks like a
nasty work around to get it to work.

Shouldn't I be able to accomplish this better? The problem is that
many DNS addresses point to the external interface. Sicne we have no
control over the
DNS process we cannot change this. So, when a machine is looking to
itself for a resource it might have to do it by domain name and then
the process breaks down because of the above problem.

Yet, no matter which rule we have in place the server on 10.0.0.140
can ping both 10.0.0.141 and 22.44.66.141. It only happens when a
machine tries to ping its own external IP.

Gary Smith
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Suggest an assignment using iptables and SNAT/DNAT jeniffer Linux Networking 0 05-05-2006 04:21 AM
iptables: fake ip using DNAT and SNAT =?ISO-8859-1?Q?Bj=F8rnar_Lib=E6k?= Linux Networking 19 04-08-2006 12:08 AM
iptables SNAT and DNAT on same packets chris-usenet@roaima.co.uk Linux Networking 6 07-08-2005 09:19 AM
Strange: Works, doesn't works, then works Anthony Giorgianni Wireless Internet 23 05-24-2005 02:43 AM
iptables SNAT & DNAT won't accept name Ming-Ching Tiew Linux Networking 2 10-08-2004 07:37 AM



1 2 3 4 5 6 7 8 9 10 11