All of lore.kernel.org
 help / color / mirror / Atom feed
* DNAT with orignal source address
@ 2006-08-02 22:34 Robert LeBlanc
  2006-08-02 23:37 ` Pascal Hambourg
  0 siblings, 1 reply; 6+ messages in thread
From: Robert LeBlanc @ 2006-08-02 22:34 UTC (permalink / raw)
  To: netfilter

I'm having problems with my e-mail server saying that every connection
originates from the NAT box. I checked it on my other linux server and
sure enough even though I have 1:1 DNAT and a reverse SNAT configured,
packets destined for my server show the NAT box as the source. How do
you configure DNAT so that it keeps the original Internet address and
does not mangle it, only the destination address to my server on a
private subnet?

iptables -t nat -A PREROUTING -d 1.1.1.4 -j DNAT --to-destination
192.168.2.10
iptables -t nat -A POSTROUTING -s 192.168.2.10 -j SNAT --to-source
1.1.1.4

So the gateway's public address is 1.1.1.1 and the e-mail server is
1.1.1.4. The e-mail logs and ssh logins all show that every connection
is made from 1.1.1.1 even though the connections are made from the
Internet.

Thanks,
Robert LeBlanc


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

* Re: DNAT with orignal source address
  2006-08-02 22:34 DNAT with orignal source address Robert LeBlanc
@ 2006-08-02 23:37 ` Pascal Hambourg
  0 siblings, 0 replies; 6+ messages in thread
From: Pascal Hambourg @ 2006-08-02 23:37 UTC (permalink / raw)
  To: netfilter

Hello,

Robert LeBlanc a écrit :
> I'm having problems with my e-mail server saying that every connection
> originates from the NAT box. I checked it on my other linux server and
> sure enough even though I have 1:1 DNAT and a reverse SNAT configured,
> packets destined for my server show the NAT box as the source. How do
> you configure DNAT so that it keeps the original Internet address and
> does not mangle it, only the destination address to my server on a
> private subnet?

DNAT never mangles the source address in the PREROUTING chain. DNAT can 
mangle the source address only in the OUTPUT chain to match the new 
output interface.

> iptables -t nat -A PREROUTING -d 1.1.1.4 -j DNAT --to-destination
> 192.168.2.10
> iptables -t nat -A POSTROUTING -s 192.168.2.10 -j SNAT --to-source
> 1.1.1.4
> 
> So the gateway's public address is 1.1.1.1 and the e-mail server is
> 1.1.1.4. The e-mail logs and ssh logins all show that every connection
> is made from 1.1.1.1 even though the connections are made from the
> Internet.

I bet that is the result of another SNAT rule, maybe the one used to 
masquerade the private subnet on internet which matches more than it 
should. For instance you have :

iptables -t nat -A POSTROUTING -j SNAT --to 1.1.1.1

when you need :

iptables -t nat -A POSTROUTING -o <public_interface> -s 192.168.2.0/24 \
   -j SNAT --to 1.1.1.1


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

* RE: DNAT with orignal source address
@ 2006-08-03 14:34 Robert LeBlanc
  2006-08-03 15:14 ` Pascal Hambourg
  0 siblings, 1 reply; 6+ messages in thread
From: Robert LeBlanc @ 2006-08-03 14:34 UTC (permalink / raw)
  To: netfilter

Pascal,
  Thanks for the feedback. I am currently using the following as my general NAT that catches everything that is not my servers. It is listed last in my script and so I thought it would be the last one to be executed if none of the above rules matched. I guess there is still some traffic that is not matching the specific rules or I misunderstood how iptables handled order and jumping. Here is my script in its entirety:

#! /bin/bash

modprobe ip_conntrack_ftp iptables_nat iptables_mangle ip_nat_ftp
echo "1" > /proc/sys/net/ipv4/ip_forward

iptables -t nat -F


# Static configs
# server1
iptables -t nat -A PREROUTING -d 1.1.1.2 -j DNAT --to-destination 192.168.2.10
iptables -t nat -A POSTROUTING -s 192.168.2.10 -j SNAT --to-source 1.1.1.2

# server2
iptables -t nat -A PREROUTING -d 1.1.1.3 -j DNAT --to-destination 192.168.2.11
iptables -t nat -A POSTROUTING -s 192.168.2.11 -j SNAT --to-source 1.1.1.3

# server3
iptables -t nat -A PREROUTING -d 1.1.1.4 -j DNAT --to-destination 192.168.2.12
iptables -t nat -A POSTROUTING -s 192.168.2.12 -j SNAT --to-source 1.1.1.4

# workstation1
iptables -t nat -A PREROUTING -d 1.1.1.5 -j DNAT --to-destination 192.168.2.13
iptables -t nat -A POSTROUTING -s 192.168.2.13 -j SNAT --to-source 1.1.1.5

# workstation2
iptables -t nat -A PREROUTING -d 1.1.1.6 -j DNAT --to-destination 192.168.2.21
iptables -t nat -A POSTROUTING -s 192.168.2.21 -j SNAT --to-source 1.1.1.6

#General nat

iptables -t nat -A POSTROUTING -j SNAT --to-source 1.1.1.1

I will give the recipe that you mentioned a try. What exactly is the difference between --to and --to-source/--to-destination, is it just an alias? One question that I have regarding the recipe that you provided is that since I have machines with public addresses scattered through the 192.168.2.0/24 subnet would it still be matching more then it should? Or does providing it a subnet and an out interface try to prevent NATing on inbound traffic as well?

Thanks,
Robert LeBlanc

> -----Original Message-----
> From: netfilter-bounces@lists.netfilter.org [mailto:netfilter-
> bounces@lists.netfilter.org] On Behalf Of Pascal Hambourg
> Sent: Wednesday, August 02, 2006 5:37 PM
> To: netfilter@lists.netfilter.org
> Subject: Re: DNAT with orignal source address
> 
> Hello,
> 
> Robert LeBlanc a écrit :
> > I'm having problems with my e-mail server saying that every connection
> > originates from the NAT box. I checked it on my other linux server and
> > sure enough even though I have 1:1 DNAT and a reverse SNAT configured,
> > packets destined for my server show the NAT box as the source. How do
> > you configure DNAT so that it keeps the original Internet address and
> > does not mangle it, only the destination address to my server on a
> > private subnet?
> 
> DNAT never mangles the source address in the PREROUTING chain. DNAT can
> mangle the source address only in the OUTPUT chain to match the new
> output interface.
> 
> > iptables -t nat -A PREROUTING -d 1.1.1.4 -j DNAT --to-destination
> > 192.168.2.10
> > iptables -t nat -A POSTROUTING -s 192.168.2.10 -j SNAT --to-source
> > 1.1.1.4
> >
> > So the gateway's public address is 1.1.1.1 and the e-mail server is
> > 1.1.1.4. The e-mail logs and ssh logins all show that every connection
> > is made from 1.1.1.1 even though the connections are made from the
> > Internet.
> 
> I bet that is the result of another SNAT rule, maybe the one used to
> masquerade the private subnet on internet which matches more than it
> should. For instance you have :
> 
> iptables -t nat -A POSTROUTING -j SNAT --to 1.1.1.1
> 
> when you need :
> 
> iptables -t nat -A POSTROUTING -o <public_interface> -s 192.168.2.0/24 \
>    -j SNAT --to 1.1.1.1



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

* RE: DNAT with orignal source address
@ 2006-08-03 14:52 Robert LeBlanc
  0 siblings, 0 replies; 6+ messages in thread
From: Robert LeBlanc @ 2006-08-03 14:52 UTC (permalink / raw)
  To: netfilter

The rule that Pascal specified worked great! Thanks for the help. If anyone can chime in, I'd still like to know the answers to the questions I posed below so that I can understand the process better.

Thanks,
Robert LeBlanc

> -----Original Message-----
> From: netfilter-bounces@lists.netfilter.org [mailto:netfilter-
> bounces@lists.netfilter.org] On Behalf Of Robert LeBlanc
> Sent: Thursday, August 03, 2006 8:34 AM
> To: netfilter@lists.netfilter.org
> Subject: RE: DNAT with orignal source address
> 
> Pascal,
>   Thanks for the feedback. I am currently using the following as my
> general NAT that catches everything that is not my servers. It is listed
> last in my script and so I thought it would be the last one to be executed
> if none of the above rules matched. I guess there is still some traffic
> that is not matching the specific rules or I misunderstood how iptables
> handled order and jumping. Here is my script in its entirety:
> 
> #! /bin/bash
> 
> modprobe ip_conntrack_ftp iptables_nat iptables_mangle ip_nat_ftp
> echo "1" > /proc/sys/net/ipv4/ip_forward
> 
> iptables -t nat -F
> 
> 
> # Static configs
> # server1
> iptables -t nat -A PREROUTING -d 1.1.1.2 -j DNAT --to-destination
> 192.168.2.10
> iptables -t nat -A POSTROUTING -s 192.168.2.10 -j SNAT --to-source 1.1.1.2
> 
> # server2
> iptables -t nat -A PREROUTING -d 1.1.1.3 -j DNAT --to-destination
> 192.168.2.11
> iptables -t nat -A POSTROUTING -s 192.168.2.11 -j SNAT --to-source 1.1.1.3
> 
> # server3
> iptables -t nat -A PREROUTING -d 1.1.1.4 -j DNAT --to-destination
> 192.168.2.12
> iptables -t nat -A POSTROUTING -s 192.168.2.12 -j SNAT --to-source 1.1.1.4
> 
> # workstation1
> iptables -t nat -A PREROUTING -d 1.1.1.5 -j DNAT --to-destination
> 192.168.2.13
> iptables -t nat -A POSTROUTING -s 192.168.2.13 -j SNAT --to-source 1.1.1.5
> 
> # workstation2
> iptables -t nat -A PREROUTING -d 1.1.1.6 -j DNAT --to-destination
> 192.168.2.21
> iptables -t nat -A POSTROUTING -s 192.168.2.21 -j SNAT --to-source 1.1.1.6
> 
> #General nat
> 
> iptables -t nat -A POSTROUTING -j SNAT --to-source 1.1.1.1
> 
> I will give the recipe that you mentioned a try. What exactly is the
> difference between --to and --to-source/--to-destination, is it just an
> alias? One question that I have regarding the recipe that you provided is
> that since I have machines with public addresses scattered through the
> 192.168.2.0/24 subnet would it still be matching more then it should? Or
> does providing it a subnet and an out interface try to prevent NATing on
> inbound traffic as well?
> 
> Thanks,
> Robert LeBlanc
> 
> > -----Original Message-----
> > From: netfilter-bounces@lists.netfilter.org [mailto:netfilter-
> > bounces@lists.netfilter.org] On Behalf Of Pascal Hambourg
> > Sent: Wednesday, August 02, 2006 5:37 PM
> > To: netfilter@lists.netfilter.org
> > Subject: Re: DNAT with orignal source address
> >
> > Hello,
> >
> > Robert LeBlanc a écrit :
> > > I'm having problems with my e-mail server saying that every connection
> > > originates from the NAT box. I checked it on my other linux server and
> > > sure enough even though I have 1:1 DNAT and a reverse SNAT configured,
> > > packets destined for my server show the NAT box as the source. How do
> > > you configure DNAT so that it keeps the original Internet address and
> > > does not mangle it, only the destination address to my server on a
> > > private subnet?
> >
> > DNAT never mangles the source address in the PREROUTING chain. DNAT can
> > mangle the source address only in the OUTPUT chain to match the new
> > output interface.
> >
> > > iptables -t nat -A PREROUTING -d 1.1.1.4 -j DNAT --to-destination
> > > 192.168.2.10
> > > iptables -t nat -A POSTROUTING -s 192.168.2.10 -j SNAT --to-source
> > > 1.1.1.4
> > >
> > > So the gateway's public address is 1.1.1.1 and the e-mail server is
> > > 1.1.1.4. The e-mail logs and ssh logins all show that every connection
> > > is made from 1.1.1.1 even though the connections are made from the
> > > Internet.
> >
> > I bet that is the result of another SNAT rule, maybe the one used to
> > masquerade the private subnet on internet which matches more than it
> > should. For instance you have :
> >
> > iptables -t nat -A POSTROUTING -j SNAT --to 1.1.1.1
> >
> > when you need :
> >
> > iptables -t nat -A POSTROUTING -o <public_interface> -s 192.168.2.0/24 \
> >    -j SNAT --to 1.1.1.1
> 



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

* Re: DNAT with orignal source address
  2006-08-03 14:34 Robert LeBlanc
@ 2006-08-03 15:14 ` Pascal Hambourg
  0 siblings, 0 replies; 6+ messages in thread
From: Pascal Hambourg @ 2006-08-03 15:14 UTC (permalink / raw)
  To: netfilter

Robert LeBlanc a écrit :
>   Thanks for the feedback. I am currently using the following as my
> general NAT that catches everything that is not my servers.
[...]
> #General nat
> 
> iptables -t nat -A POSTROUTING -j SNAT --to-source 1.1.1.1

And "everything" means *really* ANY source address from ANY interface, 
including not only your private subnet but also the whole internet 
0.0.0.0/0 !

> What exactly is the difference between --to and
> --to-source/--to-destination, is it just an alias?

Yes, --to is just shorter and can be used in both SNAT and DNAT.

> One question that I have regarding the recipe that you provided 
> is that since I have machines with public addresses scattered through 
> the 192.168.2.0/24 subnet would it still be matching more then it 
> should?

What do you mean ?

> Or does providing it a subnet and an out interface try to 
> prevent NATing on inbound traffic as well?

Yes. The subnet condition prevent the rule to apply to any internet 
source address (including the NAT box own public address), and the 
output interface condition prevent the rule to apply to any connection 
coming from the outside. Actually either condition should be sufficient 
to prevent the undesired behaviour you described, but both won't harm. 
Of course it must be placed after the more specific SNAT rules.


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

* RE: DNAT with orignal source address
@ 2006-08-03 15:50 Robert LeBlanc
  0 siblings, 0 replies; 6+ messages in thread
From: Robert LeBlanc @ 2006-08-03 15:50 UTC (permalink / raw)
  To: netfilter



> -----Original Message-----
> From: netfilter-bounces@lists.netfilter.org [mailto:netfilter-
> bounces@lists.netfilter.org] On Behalf Of Pascal Hambourg
> Sent: Thursday, August 03, 2006 9:14 AM
> To: netfilter@lists.netfilter.org
> Subject: Re: DNAT with orignal source address
> 
> > One question that I have regarding the recipe that you provided
> > is that since I have machines with public addresses scattered
through
> > the 192.168.2.0/24 subnet would it still be matching more then it
> > should?
> 
> What do you mean ?
> 
The question more specifically was: if I had a server at 192.168.2.10
would it also be caught by the 192.168.2.0/24 rule? But, I think you
answered it with the answer to my last question. It would be caught by
the more specific rule as long as it was placed before the general one.
This would prevent traffic from/to the server from going through the
general rule.

Thanks for all the help,
Robert LeBlanc


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

end of thread, other threads:[~2006-08-03 15:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-02 22:34 DNAT with orignal source address Robert LeBlanc
2006-08-02 23:37 ` Pascal Hambourg
  -- strict thread matches above, loose matches on Subject: below --
2006-08-03 14:34 Robert LeBlanc
2006-08-03 15:14 ` Pascal Hambourg
2006-08-03 14:52 Robert LeBlanc
2006-08-03 15:50 Robert LeBlanc

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.