Redundant Site-to-Site IPSecVPN between AWS and pfSense
Tags: networking, vpn, ipsec, pfsense
Published: 2024-01-11 21:09:38

Disclaimer: this article was published originally on Medium, in December 2021 and may not be 100% up to date.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/63pucub9yv472gtvbfia.png)

While setting up a IPSec tunnel between an AWS VPC and a pfSense gateway is simple at first look, there’s a little trick to make it work with both tunnels provided by AWS active at same time, working with VTI tunnels.

Here’s a simple guide, if you ever need to connect your local network to a AWS VPC.

Part 1: Amazon side
===================

First, let’s set things up on Amazon side. Go to VPC menu, then to Customer Gateways and Create Customer Gateway

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2iz4idnm8698esv719lh.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/66jwsheabtpqnh13mqpk.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mb6gmj3491m8z37jxd36.png)

On the new Customer Gateway screen, set a name for your gateway, choose Static Routing and insert your static public IP address (the one that will be used as gateway on your IPSec tunnel). Then, create the Customer Gateway.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z67xm5rwjmke2r44n1tm.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2u243vc6bc8ro9mpd098.png)



You can check the State to make sure it’s available.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ivrekqhpqk6aegm5lcns.png)


Now, got to Virtual Private Gateways menu and create a new Virtual Private Gateway.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/skeudaxg36p5186w4po2.png)


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ejn76enl8nd94d689vw5.png)


Name tag field is optional, and for ASN, pick Amazon Default ASN.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5uymmpgyhzedmbgvyjyv.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c53mt7r8ua8dglzbqai4.png)



The Virtual Private Gateway will be created on a detached state.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f58afluu595zo81td1ty.png)


Then, select the Virtual Private Gateway you just created, go to the Actions menu and select Attach to VPC.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mh2jvxixrm7p6qjszh4b.png)


On the next screen, select the VPC you want to connect with your local network and click on Yes, Attach.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/61nvkrkoso9y767944tc.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxrnn3ng9n00215762qn.png)

After a while, it will change the state from attaching to attached.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nvuv8o18a10mh35k11qs.png)


Then, move to Site-to-Site VPN Connections and Create VPN Connection.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/znnbev1irhavoct5kiib.png)


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cd8sog5av9usvg0mc4ip.png)


For the new VPN Connection, choose a name and pick the previously created Virtual Private Gateway and Customer Gateway. On Static IP Prefixes insert each network on your local side that will need to be accessed by AWS resources.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n90atwnmu35pdd5cq9nh.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7lxag2no2h1lsk1png04.png)

Leave all the other options as default and then create the VPN Connection.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/75m36fsrir09p4cvyp3b.png)

On the next screen it will appear as pending, and after a while, will change to available.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lic8gyv8drfvwvjmh08.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/px6ag5t980uz2undepkj.png)

Select the connection, go to Tunne Details, save the network CIDRs in there, that will be used later.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bb2ch7vel3agfoyl6v45.png)

Go to Static Routes tab and check if your local network is there.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zz5xtvtxqsvoiqlodg85.png)

At the top of the screen, click into Download Configuration button, choose pfSense and save the provided TXT that will be used on the next steps.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h7f8iu0pgcntm7158h4x.png)

Still into AWS Console, go to Route Tables and find the Route Table in use by your VPC.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lsm6d14lh00zwszdcbbn.png)

After selecting the proper Route Table, go to Route Propagation tab and click Edit route propagation. Check the Propagate box and save.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qgz3dr75hcpmm80arcj4.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ma9li1awt0xglax0l9t0.png)

Validate if the Propagate field changed to Yes on the previous screen.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rltpvgc2vtttoijcolqn.png)

Steps on Amazon are completed.

Part 2: pfSense side
====================

*   Go to VPN > IPSec > Add P1 as you would normally do.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cata6pl4jvw7ewpah28u.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/un9ihy4lm7mjgovwn345.png)

*   Use the instructions provided on the downloaded file to fill the P1 tunnel settings.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/glu5iv0uqm3mwj8ym6ah.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/69ygl8bhjrfcw658k18s.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hpzmlpf8pnt82wqzy80.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/py8r6yjaggh4eauiw7ce.png)

Save the settings matching what was provided and then Apply Changes on pfSense. P1 tunnels won’t be triggered until a P2 tunnel is set up.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrj2folsrr9fez687nuv.png)

To the next step, add a P2 tunnel:

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t437j3futcodmczowgm1.png)

Now, the trick:

Instead of picking Tunnel IPv4, set mode as Routed (VTI). Now we gonna use the Tunnel IPs provided on the AWS console.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hgyblkau1aekv4u29df4.png)

Since each block is a /30, IPs are distributed as follows:

First IP: 169.254.43.192 — Network

Second IP: 169.254.43.193 — Is used on AWS side

Third IP: 169.254.43.194 — The one that should be used on pfSense

Fourth IP: 169.254.43.195 — Broadcast

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e0rw0xezqxodkim80dpb.png)

Other settings are default as provided by AWS on the TXT file

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/713hw9s5jydcjmysxeo5.png)

To keep the tunnel UP, set ping to the AWS side IP

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lj5dwxmp1inw9ickgoxx.png)

Repeat the same process for the second tunnel.

Now, go to Interfaces > Assignments

There you’ll have two new virtual network ports that you must add as interface

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mss8th2d5h5mf8nx6e1d.png)

They will be created as new OPT interfaces, and must be renamed and enabled. It’s also a good idea to rename them to something related to the tunnel they belong to.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2l3y3zu24kjp16jzum6u.png)
https://miro.medium.com/v2/resize:fit:640/format:webp/1*I8SxP2H6FCdsHcfSoYotrQ.png

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l96hmqeo3qw6mn16k4uf.png)

After a while both tunnels will be up. You can validate that on AWS console.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7qin5c73z2w0lfa1962.png)

For the last step, it’s important to set the routes on pfSense, so it will know how to reach private IPs on the other side of the tunnel. For that, go to System > Routing

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jgqurxji91j5ft5ic8mh.png)

Another important trick: to set routing, if your VPC has a CIRD /16 for example, one of the gateways will have the destination network matching the VPC IP and CIRD, and the second one will have two networks /17.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r2csr1kscib1gg2g47a3.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0swyz9grlxhxym3pe280.png)

This way, the traffic will flow only through tunnel A. However, if it fails, it will be automatically routed through tunnel B.

Don’t forget to create a firewall rule on IPSec if you don’t have it already

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/agctcmgyg030lazxlkjw.png)

And also don’t forget to set a security group to allow incoming connections to your AWS instances from your local network IPs.