Skip to contentSkip to conversation

SNAT before IPSEC - why?

DISCUSSION Stephen Clark 4 participants 10 messages Oct 8, 2011 – Oct 9, 2011 netfilter

lore
Share & tools
lore
#0 lore raw

Hi,

What is the reasoning for having SNAT happen before ipsec encryption?

It forces one to add special rules in the NAT table to keep this from happening and I can't think of one reason why you would want it to be this way.

Please someone enlighten me.

Thanks,
Steve

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#1 lore raw
Quoted 7 lines · On Sat 2011-10-08, 04:08:04 CEST Stephen Clark <[email protected]> wrote:

What is the reasoning for having SNAT happen before ipsec encryption?

It forces one to add special rules in the NAT table to keep this from happening and
I can't think of one reason why you would want it to be this way.

Please someone enlighten me.

IMHO the main reason is that addresses translation of IPsec encapsulated packet
wouldn't work without something like NAT Traversal.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Stephen Clark

Hi Stephen,

Quoted 1 line · Stephen Clark

What is the reasoning for having SNAT happen before ipsec encryption?

You might well want to SNAT or MASQUERADE packets going through the tunnel, to have them fit within the tunnel's subnet, for example if you add a new local subnet and you don't want to reconfigure thousands of clients.

Quoted 1 line

It forces one to add special rules in the NAT table to keep this from happening

You mean "iptables -t nat -A POSTROUTING -m policy --pol ipsec -j ACCEPT"? Doesn't seem very onerous to me.

Cheers, Chris.

Signature · 5 lines
Aptivate | http://www.aptivate.org | Phone: +44 1223 760887
The Humanitarian Centre, Fenner's, Gresham Road, Cambridge CB1 2ES

Aptivate is a not-for-profit company registered in England and Wales
with company number 04980791.
#3 lore raw
Quoted 4 lines · Chris Wilson

Hi Stephen,

On Fri, 7 Oct 2011, Stephen Clark wrote:

Quoted 8 lines
Quoted 1 line

What is the reasoning for having SNAT happen before ipsec encryption?

You might well want to SNAT or MASQUERADE packets going through the tunnel, to have them fit within the tunnel's subnet, for example if you add a new local subnet and you don't want to reconfigure thousands of clients.

Quoted 1 line

It forces one to add special rules in the NAT table to keep this from happening

You mean "iptables -t nat -A POSTROUTING -m policy --pol ipsec -j ACCEPT"? Doesn't seem very onerous to me.

No, but that is different than what I had been using which is:
-A POSTROUTING -o eth1 -s 10.152.35.0/24 -d 10.159.95.0/24 -j ACCEPT

How does -m policy --pol ipsec figure in? I am somewhat new to iptables having been working with ipfilter/ipnat on FreeBSD for the last 10 years, so pardon my ignorance.

Quoted 1 line

Cheers, Chris.

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#5 lore raw
Quoted 10 lines · Jan Engelhardt
Quoted 4 lines · Stephen Clark

Hi,

What is the reasoning for having SNAT happen before ipsec encryption?

It can happen before and/or after - see the nf flow graph.

Do you have a link to the graph?

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#7 lore raw
Quoted 14 lines · Jan Engelhardt
Quoted 11 lines · Stephen Clark
Quoted 9 lines · Jan Engelhardt
Quoted 5 lines · Stephen Clark

Hi,

What is the reasoning for having SNAT happen before ipsec encryption?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

It can happen before and/or after - see the nf flow graph.

Do you have a link to the graph?

http://jengelh.medozas.de/images/nf-packet-flow.png or .svg

Beautiful! Thanks,

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#8 lore raw
Quoted 9 lines · Stephen Clark
Quoted 8 lines · Jan Engelhardt
Quoted 6 lines · Stephen Clark
Quoted 5 lines · Jan Engelhardt
Quoted 2 lines · Stephen Clark

Hi,

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

What is the reasoning for having SNAT happen before ipsec encryption?

It can happen before and/or after - see the nf flow graph.

Do you have a link to the graph?

http://jengelh.medozas.de/images/nf-packet-flow.png or .svg

Beautiful! Thanks,

Hi Jan,

In looking at the graph - do in ipsec packets and out ipsec packet hit the INPUT and OUTPUT chains even if the packet is being forwarded and is not really destined for the machine running iptables?

Thanks for taking the time to respond.

Steve

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#9 lore raw
Quoted 7 lines · Stephen Clark
Quoted 2 lines
Quoted 1 line

http://jengelh.medozas.de/images/nf-packet-flow.png or .svg

Beautiful! Thanks,

In looking at the graph - do in ipsec packets and out ipsec packet hit the INPUT and OUTPUT chains even if the packet is being forwarded and is not really destined for the machine running iptables?

It always depends on the routing table.