Saturday, March 13, 2010

NAT and IPsec - Application sequence

To my surprise, after so many years of IPsec deployments,  I keep hearing questions related to NAT and IPsec.  It appears that there is some confusion still on the sequence of operations between NAT and IPsec. That is why I thought I will write a blob on this subject.

Before going further into the technical aspects, it is good to introduce two scenarios.
  • Branch Office VPN :  This term is typically used to connect offices of an organization over public Internet with IPsec VPN security.
  • Partner VPN :  This term is typically used to connect some part of network or machine(s) with partner network securely using IPsec VPN.
If IPsec VPN is being used to secure networks of different offices of same organization, one can assume that the private IP addresses of different networks are unique within the organization.  Hence IPsec VPN can be applied on the private networks of offices.

While connecting with Partners,  one can't assume that the private networks of partners are unique. It is very much possible that both the networks might have same private IP address networks.  Hence the IPsec VPN must always happen with public IP addresses.  In this case, typically source NAT is applied before IPsec VPN is applied on the packet.  Source NAT translated the local network IP addresses to public IP address and the IPsec sessions negotiated with public IP addresses.

Note that it is also possible that a given a branch office VPN router, not only used to connect to the other offices of the organization, nut also connect partner networks. So, VPN routers must be able to support multiple site-to-site VPN within its organization, but also support site-to-site VPN with partner networks.

Let us take a simple scenarios where one secure gateway  is securing network. It is expected to securely connect to its head office VPN router which is securing network. Let us also say that  this router is expected to secure traffic to/from two machines on its local network (say and with three partner machines in partner network.  For this purpose, let us say that two public IP addresses are allocated for the local security gateway - and   Let us also say that partner provided IP address to connect to the partner machines -, and

On the security gateway, following NAT rules are required:
  • Source Range: -,  Destination Range:,  Apply Source One-to-One NAT with - :   This rule does source NAT  on the connections that are originated from local network identified by source. It replaces source IP of the packet it is receiving from local network if it matches with range and if destination IP is in the range of -  NAT IP address are given as -  Since it is One-to-One NAT,  it replaces with and with
  • Source Range: -, Destination Range: -, Apply Destination One-to-One NAT with -  This rule is applied for connections that are originated by partner network.  It translated destination IP so that the connections land at the right machines in local network.
IPsec policy rules would look like this:
  •  Branch office VPN rule:  Source:  Destination Apply Security (Algorithms and proposals are not shown here).
  •  Partner Office VPN rule:   Source :  Destination : -, Apply Security. 
I hope I could make it clear on how NAT and IPsec can be used to connect with partner network. Note that private IP addresses can be used to talk to partner network too as long as administrators of both organizations ensure that there are no duplicate private IP addresses in their networks that need communication.

No comments: