[Openswan Users] NAT based upon tunnel

John A. Sullivan III jsullivan at opensourcedevelopmentcorp.com
Wed Oct 6 10:48:02 CEST 2004

Thanks again, Paul, this is really helping me out of a bit of a jam.

On Wed, 2004-10-06 at 09:02, Paul Wouters wrote:
> On Wed, 6 Oct 2004, John A. Sullivan III wrote:
> > There are potentially thousands of clients so the solution must scale to
> > handle many IP address conflicts.
> Just to clarify, the problem is not in receiving packets on the head end
> or sending packets on the branch. The problem is in distinguishing and
> sending packets from the head office to the correct branch office.
> So you will need to immediately NAT the packets when you decrypt them and
> still know where the packets came from (as you said, perhaps with marking?)
> so that answers to these packets are done on the NAT'ed range so you know
> which branch office these packets are.
Yes, exactly.
> >> AFAIK, klips has no idea about marking packets. You might get the desired
> >> result by using hidetos=no but it likely won't be copying all the IP options
> >> of the plaintext packets. Perhaps Michael can answer this question.
> > Ouch! If that's the case, then I am probably forced into the KAME,
> > Racoon and the native IPSec implementation unless someone else can
> > figure out how to distinguish the packets from OfficeB from the packets
> > from OfficeA within iptables.
> >
> > Does anyone know authoritatively if the mark survives decryption?
> Michael?
By the way, what mailing list supports questions about the native Linux
IPSec implementation? I haven't really started experimenting with it yet
but I need to soon.
> Another thought. Can you add more networks at the head office, and then have
> seperate tunnels from the same remote 10.a.b.0/24 networks to different *local*
> subnets, and then perform NAT locally?
> So officeA becomes to 10.a.0.0/24 and officeB becomes
> to 10.b.0.0/24. Then you can SNAT the range based on the destination
> range of the packet, and on the way back DNAT them back to before
> encrypting them and sending them over the tunnel. Since the head office network
> is then different, these two offices have non-identical tunnels, and no special
> marking needs to happen.
That's an outstanding idea.  I hesitate to add the complexity to the
Head Office where a mistake could have very profound effects on large
numbers of users but it sounds much simpler than my proposal above.

This is a little off topic but I'll bounce it off anyone still following
this thread:
I think I would not run a virtual network on the same media because I
would not want to have to add IP addresses to every back end server
every time there is another conflict for the same IP address space
(e.g.,in the illustration we've been using, a third client comes along
with  However, I would imagine that I could bind any
number of addresses to the gateway private interface and set up security
policies between the conflicting offices and these alternative

That is, OfficeA is, OfficeB is and the Head
Office is  I can bind to the Head Office GW,
create one policy between OfficeA's and and
another between OfficeB's and  I think that's
what you are suggesting.  Correct?

I would then, within the Head Office GW and on the decrypted packet on
the ipsec interface, DNAT to, as long as it does
not break anything at the application layer.  I could conceivably now
have two packets headed for the same server with the same IP address.  I
assume that iptables is smart enough that they will never have the same
source port, too.  The replies will come back and connection tracking
within iptables will magically identify the reply packet for OfficeB and
SNAT the reply back to

That sounds like it will work.  Does anyone see any caveats? 

This leads to another off topic but interesting question.  I'm pretty
sure this will work in *swan because of the complete traversal of the
packet through the netfilter hooks on each interface (e.g., eth0 and
ipsec0).  Will such a solution work if we are only using PLUTO and not
KLIPS? When a packet comes in from OfficeB using native IPSec, we
decrypt it and it is now destined for  Can we catch it and
DNAT it in the PREROUTING chain after it has been decrypted?

Thanks - John
> Paul
John A. Sullivan III
Open Source Development Corporation
Financially sustainable open source development

More information about the Users mailing list