All of lore.kernel.org
 help / color / mirror / Atom feed
* Combined Internal/External DNAT question
@ 2005-05-14  5:51 Jonathan Wheeler
  2005-05-15 23:56 ` Taylor, Grant
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Wheeler @ 2005-05-14  5:51 UTC (permalink / raw)
  To: netfilter

Hi Guys,

I have a number of internal servers sitting behind my iptables firewall
running various services (smtp/http/dns etc).
My public IP address sits on my DSL router's WAN interface, which nats
the specified ports for my public services to the firewall's interface &
IP which is attached to the router via crossover cable.

Iptables has about 15 entries all along the lines of

iptables -t nat -A PREROUTING -d 10.0.0.1 -i eth1 -p tcp --dport
<tcpservice> -j DNAT --to <relevant.internal. server>:<tcpservice>
And this works nicely.

However I have the classic situation of internal clients using the DNS
entries for these servers which points them to my external IP. The
firewall forwards the traffic out the dsl interface to the internet as
it has no knowledge of my public IP. It doesn't work, the DSL router
can't NAT to and from the LAN interface.

The following documentation is close to what I want, but doesn't quite work.
http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO-10.html

The reason it doesn't work is that my firewall doesn't actually have the
external IP.

What I need is rule along the lines of:
iptables -t nat -I PREROUTING -d <publicIP> -s <internal-lan> -j DNAT
--to 10.0.0.1.
I would then have traffic from the internal lan, going the same
destination IP that my public natting rules are already built for. Which
should then redirect internal clients to my internal servers using these
same natting rules.

It appears however that once iptables had done it's initial DNAT of a
session as per the rule above, it doesn't reevalute the PREROUTING chain.

Which means that clients try to connect to the firewall itself rather
then being DNATed again.

HELP, I need some kind of a double DNAT?

I know there are solutions to this problem like dual dns, but getting
this would be MUCH quicker to setup/manage/scale, and I wouldn't have to
play DNS games.

I could also create a whole second set of rules DNATing internal traffic
destined for my public IP, to go to the correct server, but then I'd
have 2 chains of traffic to maintain. Is there no way I can do this all
with one set of rules, on the one firewall?

Thanks,
Jonathan.


^ permalink raw reply	[flat|nested] 9+ messages in thread
* RE: Combined Internal/External DNAT question
@ 2005-05-15 16:35 Gary W. Smith
  0 siblings, 0 replies; 9+ messages in thread
From: Gary W. Smith @ 2005-05-15 16:35 UTC (permalink / raw)
  To: Jonathan Wheeler, netfilter

I've always received an answer which has never helped for this question
of this not being necessary.  Anyways, here is what we do that does work
which I'm sure you can change to suit your needs.

-A POSTROUTING -s 10.0.0.130 -o eth0 -j SNAT --to-source 30.40.50.130 
-A POSTROUTING -s 10.0.0.0/255.255.255.0 -d 10.0.0.130 -j SNAT
--to-source 30.40.50.130

eth0 is the external interface for some reason we loose the second line
internal machines cannot access other internal machines with the
external IP.  I've had mixed results dropping the eth0 on the first
line.  If I recall internal hosts pinging internal hosts on their
internal or external IP would always respond with their external IP
which also screwed things up.

It should be similar for you but with ports specified.

Hope that helps, 

Gary

> -----Original Message-----
> From: netfilter-bounces@lists.netfilter.org [mailto:netfilter-
> bounces@lists.netfilter.org] On Behalf Of Jonathan Wheeler
> Sent: Friday, May 13, 2005 10:52 PM
> To: netfilter@lists.netfilter.org
> Subject: Combined Internal/External DNAT question
> 
> Hi Guys,
> 
> I have a number of internal servers sitting behind my iptables
firewall
> running various services (smtp/http/dns etc).
> My public IP address sits on my DSL router's WAN interface, which nats
> the specified ports for my public services to the firewall's interface
&
> IP which is attached to the router via crossover cable.
> 
> Iptables has about 15 entries all along the lines of
> 
> iptables -t nat -A PREROUTING -d 10.0.0.1 -i eth1 -p tcp --dport
> <tcpservice> -j DNAT --to <relevant.internal. server>:<tcpservice>
> And this works nicely.
> 
> However I have the classic situation of internal clients using the DNS
> entries for these servers which points them to my external IP. The
> firewall forwards the traffic out the dsl interface to the internet as
> it has no knowledge of my public IP. It doesn't work, the DSL router
> can't NAT to and from the LAN interface.
> 
> The following documentation is close to what I want, but doesn't quite
> work.
> http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO-10.html
> 
> The reason it doesn't work is that my firewall doesn't actually have
the
> external IP.
> 
> What I need is rule along the lines of:
> iptables -t nat -I PREROUTING -d <publicIP> -s <internal-lan> -j DNAT
> --to 10.0.0.1.
> I would then have traffic from the internal lan, going the same
> destination IP that my public natting rules are already built for.
Which
> should then redirect internal clients to my internal servers using
these
> same natting rules.
> 
> It appears however that once iptables had done it's initial DNAT of a
> session as per the rule above, it doesn't reevalute the PREROUTING
chain.
> 
> Which means that clients try to connect to the firewall itself rather
> then being DNATed again.
> 
> HELP, I need some kind of a double DNAT?
> 
> I know there are solutions to this problem like dual dns, but getting
> this would be MUCH quicker to setup/manage/scale, and I wouldn't have
to
> play DNS games.
> 
> I could also create a whole second set of rules DNATing internal
traffic
> destined for my public IP, to go to the correct server, but then I'd
> have 2 chains of traffic to maintain. Is there no way I can do this
all
> with one set of rules, on the one firewall?
> 
> Thanks,
> Jonathan.



^ permalink raw reply	[flat|nested] 9+ messages in thread
* RE: Combined Internal/External DNAT question
@ 2005-05-15 16:54 Gary W. Smith
  0 siblings, 0 replies; 9+ messages in thread
From: Gary W. Smith @ 2005-05-15 16:54 UTC (permalink / raw)
  To: Jonathan Wheeler, netfilter

On that same topic, we a /25 subnet into the DMZ.  We end up with
something like section below.  You will notice that we also have the
double POSTROUTING entries as well as the output section.  In out case
we had to create a patch for the NETMAP code but that doesn't apply to
you though.



#############################################################
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
#############################################################
# Prerouting Maps
#############################################################
[0:0] -A PREROUTING -d 33.44.55.128 -j RETURN
[0:0] -A PREROUTING -d 33.44.55.129 -j RETURN
[0:0] -A PREROUTING -d 33.44.55.128/26 -j NETMAP --to 10.0.0.128/26
[0:0] -A PREROUTING -d 33.44.55.192/27 -j NETMAP --to 10.0.0.192/27
[0:0] -A PREROUTING -d 33.44.55.224/28 -j NETMAP --to 10.0.0.224/28
[0:0] -A PREROUTING -d 33.44.55.248/30 -j NETMAP --to 10.0.0.248/30
#############################################################
# Postrouting Maps
#############################################################
[0:0] -A POSTROUTING -s 10.0.0.128 -j RETURN
[0:0] -A POSTROUTING -s 10.0.0.129 -j RETURN
[0:0] -A POSTROUTING -o eth0 -s 10.0.0.128/26 -j NETMAP --to
33.44.55.128/26
[0:0] -A POSTROUTING -o eth0 -s 10.0.0.192/27 -j NETMAP --to
33.44.55.192/27
[0:0] -A POSTROUTING -o eth0 -s 10.0.0.224/28 -j NETMAP --to
33.44.55.224/28
[0:0] -A POSTROUTING -o eth0 -s 10.0.0.248/30 -j NETMAP --to
33.44.55.248/30


# Without these, local lookups on the same network fail to
# find the server

[0:0] -A POSTROUTING -s 10.0.0.0/24 -d 10.0.0.128/26   -j NETMAP --to
33.44.55.128/26
[0:0] -A POSTROUTING -s 10.0.0.0/24 -d 10.0.0.192/27   -j NETMAP --to
33.44.55.192/27
[0:0] -A POSTROUTING -s 10.0.0.0/24 -d 10.0.0.224/28   -j NETMAP --to
33.44.55.224/28
[0:0] -A POSTROUTING -s 10.0.0.0/24 -d 10.0.0.248/30   -j NETMAP --to
33.44.55.248/30

[0:0] -A POSTROUTING -o eth0 -p ! esp -j SNAT --to-source 33.44.55.254

#############################################################
# Output Maps
# customized NETMAP to support OUTPUT
#############################################################
[0:0] -A OUTPUT -d 33.44.55.128 -j RETURN
[0:0] -A OUTPUT -d 33.44.55.129 -j RETURN
[0:0] -A OUTPUT -d 33.44.55.128/26 -j NETMAP --to 10.0.0.128/26
[0:0] -A OUTPUT -d 33.44.55.192/27 -j NETMAP --to 10.0.0.192/27
[0:0] -A OUTPUT -d 33.44.55.224/28 -j NETMAP --to 10.0.0.224/28
[0:0] -A OUTPUT -d 33.44.55.248/30 -j NETMAP --to 10.0.0.248/30

COMMIT


> -----Original Message-----
> From: netfilter-bounces@lists.netfilter.org [mailto:netfilter-
> bounces@lists.netfilter.org] On Behalf Of Gary W. Smith
> Sent: Sunday, May 15, 2005 9:36 AM
> To: Jonathan Wheeler; netfilter@lists.netfilter.org
> Subject: RE: Combined Internal/External DNAT question
> 
> -A POSTROUTING -s 10.0.0.130 -o eth0 -j SNAT --to-source 30.40.50.130
> -A POSTROUTING -s 10.0.0.0/255.255.255.0 -d 10.0.0.130 -j SNAT
> --to-source 30.40.50.130
> 
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread
[parent not found: <42889941.5060507@griffous.net>]
* Combined Internal/External DNAT question
@ 2005-05-19 10:53 Jonathan Wheeler
  0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Wheeler @ 2005-05-19 10:53 UTC (permalink / raw)
  To: netfilter

The only other thing that comes to mind would be to use iphash (IP)sets of destination IP addresses on your original DNAT rules.  This would cause your iptables rule to match based on the destination of your external IP of your firewall OR your external IP of your DSL modem (/router) and DNAT the traffic to the real server on your 2nd internal subnet.  Here is an example rule for what you would need:

iptables -t nat -A PREROUTING -m set --set My_IP_Set dst -j DNAT --to-destination <relevant.internal.server>:<tcpservice>

To support this rule you would need to do the following (likely before you issued the above rule):

ipset -N My_IP_Set iphash
ipset -A My_IP_Set 10.0.0.1
ipset -A My_IP_Set <Public IP>

As stated before this should cause your one iptables rule to match packets that are destined to any IP in the ip set "My_IP_Set" and DNAT said packets to the <relevant.internal.server>:<tcpservice>.  I know that this is not the multiple passes through the iptables chains like you were asking for, but I think it will provide a solution comparable  to the result that you were after.  Rather than have a rule that will alter traffic such that it will be caught by another rule and then altered again why not have a rule that will catch either type of traffic.

Grant. . . .



Thanks for the reply Grant, 

Sorry for not getting back to you earlier. You're quite right, this should work nicely but I'm not so keen on running the non-default modules at the moment.
For simply getting my machine working for the testing that I need to be doing, a simply iptables -t nat -A OUTPUT is able to fix the problem for me, though
of course any other clients still have the problem.

Once I have all the rest of the network running I'll come back to using the set module.

Thanks again,
Jonathan.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-05-19 10:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-14  5:51 Combined Internal/External DNAT question Jonathan Wheeler
2005-05-15 23:56 ` Taylor, Grant
  -- strict thread matches above, loose matches on Subject: below --
2005-05-15 16:35 Gary W. Smith
2005-05-15 16:54 Gary W. Smith
     [not found] <42889941.5060507@griffous.net>
2005-05-16 18:35 ` Taylor, Grant
2005-05-16 19:27   ` R. DuFresne
2005-05-16 19:50     ` R. DuFresne
2005-05-16 21:06       ` Taylor, Grant
2005-05-19 10:53 Jonathan Wheeler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.