Test Sending Traffic From a Load Balancer To A NAT Gateway
ACM.469 Spoiler Alert: Q told me I could do this but I can’t :( but this might help someone trying to set up a network load balancer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
⚙️ Check out my series on Automating Cybersecurity Metrics. The Code.
🔒 Related Stories IAM | AWS Security | pfSense | Network Security
💻 Free Content on Jobs in Cybersecurity | ✉️ Sign up for the Email List
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the last post I set up a site to site VPN using pfSense and an AWS Virtual Private Gateway.
In this post, I show how I tried to deploy a load balancer to forward traffic to a NAT Gateway as a target.
TL;DR I asked Amazon Q if I could do this in a prior post and it told me I could. If you want to know why it doesn’t work, or you just want to understand how to create a load balancer (just don’t point it at a NAT Gateway) then read on. If you want a working solution to send traffic from your home network to an AWS NAT Gateway and don’t care about all this, read the other posts in this series involving a Transit Gateway.
A hypothetical architecture to send traffic from a Load Balancer directly to a NAT
I was pondering whether something like this would be possible. Don’t ask me why. I like to try different things just to see what happens.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*-MfMczJVR8SDAHZ5L7E6mQ.png)
The AWS Load Balancer would be a target for pfSense VPN routes.
Will it work? Well, I looked up some information in the documentation and here’s what I found:
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*MtDmiKwWrxRCZRoY_CseRw.png)
Well the NAT has a private IP address right? So in theory we can route traffic to it from the load balancer.
But somehow I knew this wasn’t going to work. So I looked for validation that it would before I started so as not to waste my time. It just felt like something that would not work for some reason.
Well, why not ask Q? Amazon’s AI widget in the AWS Console.
Q didn’t understand my first question. It’s telling me to forward data from the Load Balancer to instances here and that’s exactly what I am trying to avoid for this first test. I want to see if I can avoid those charges and send the traffic straight to the NAT from a Network Load Balancer.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*HuFA0LTAKgTuSj8S_OzXVQ.png)
So I modified my question to say “without instances.”
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*1tAAiVSJZfXHQcqjIDXjEw.png)
4. Traffic from the on-premises network can now be routed to the NAT gateway securely over the VPN tunnels. The NAT gateway will then allow this traffic to access the internet.
Well, it sounds like it will work. Though this part is a little off:
No EC2 instances are required as the NAT gateway itself can perform network address translation for resources in the VPC to access the internet.
I’m sending the data from my local network. But I guess from the NAT perspective the traffic will be coming from the Load Balancer which is “in the VPC.”
Well, based on that information, I proceeded. This information will still be useful to anyone trying to create a load balancer so I’m publishing it anyway. I’ll also explain why it doesn’t work below.
Create a Network Load Balancer
If you search for load balancers, you want the EC2 option.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*FL5H5OY00vuX_0YpKwi_Qg.png)
Click Create load balancer.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*IttKT9BHo4uUST5r44b_8g.png)
Click Create under Network Load Balancer.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*4uWUft6h4F-G-hI6fmFUsQ.png)
AWS explains what the load balancer does which is pretty cool:
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*7rBRnXSRR_JaLggkBdVR4w.png)
Enter a name. Choose internal. The load balancer will only be accessed via the VPN and private IP addresses. It will not be exposed to the Internet thanks to the NAT.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*FXRMHEiHWB0wYX0NKLw9Yw.png)
Choose the VPC we created.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*flJ69eOSG2i6btMg-i4vmA.png)
Click the region. Choose the subnet.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*_vDJG38n2FOKaUT9XKUdXg.png)
For high availability you’d possibly want more subnets but this is only a test.
Choose the security group we created that allows our private IP range on the pfSense to ping a host in the AWS subnet with ICMP. We will need to add some additional rules in a bit.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*4xY2_7U06tviTZvtiNLUSA.png)
Next we need to add ports to listen for traffic from pfSense.
I’m going to start with 443. However, we don’t have any targets that we can select. So hold this thought.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*tYd99RUDT1tfRU8lWh4Hkw.png)
Create a NAT
I’ve created a NAT with CloudFormation templates in prior posts. You can find those here:
For this test I’m going to do it manually.
As in prior posts, I am going to right click on the AWS logo and choose Open Link in new tab (or similar if you are in another browser).
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*bM5Pm_YQowr_t2-plLNzsA.png)
Search for and click on NAT gateways in the VPC Console.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*TrZAt5UwdK1ozp8Dux79sw.png)
Click Create NAT Gateway.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*xiaGF63VL8qmVG9yI-OW7w.png)
Enter a name.
Choose the pfSense subnet.
Leave Public selected so it can reach the Internet.
Click Allocate Elastic IP and an IP address will appear in the drop down.
Click Create NAT gateway.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*ElXyS9b8F89kEcLRnWF03g.png)
The state will initially be pending. The IP address shows up, which we need.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*2XqYmbaKUdJARIjwrqrWtA.png)
However, the deployment fails. Why? Because the VPC has no Internet Gateway attached.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*cdsvk4KGe94PPzZq_zp2iA.png)
So here I could do a couple of things. I could create a separate VPC with an Internet Gateway. Instead, I created a new subnet with a public route table (meaning it has an Internet Gateway). I tried to allow traffic from the private subnet to reach my public subnet via NACLs and security group rules.
Delete the NAT.
Create an Internet Gateway
Click on Internet gateways. Click Create Internet gateway.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*w5gWavMPUJIbREuXDyHldw.png)
Enter a name. Click Create internet gateway.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*GEfK13VIYMjD1QGGOPKqhw.png)
Click Actions > Attach to VPC.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*LS0t95pYgI0B1JrL3TWtfQ.png)
Select the pfSense VPC. Click Attach internet gateway.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*yjw541L0J4g-y15ayemCAA.png)
Create a public route table
Click Route tables on the VPC dashboard and Create route table.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*kxN3cqEuKCWQjAqZzoXejg.png)
Give it a name. Select the pfSense VPC. Click Create route table.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*8b66dD8KonmrAzESngH4xA.png)
Click on Routes. Click Edit routes.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*CUqZ4zg9D-fdJzYZNpOa7Q.png)
Click Add Route first. That tripped me up because I was trying to select from the drop down above that and you can’t select Internet Gateway there as that drop down is associated with the existing route. For those of us who are used to the old console that is confusing.
After you click Add route it adds a new row and you can select Internet Gateway.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*Afw8EH87BECt2S12AIM8PQ.png)
Then you can select the Internet Gateway.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*9jUvnVE3wMV3-86tKKPa9w.png)
Next add the IP ranges you want the route to access, which in our case is the entire Internet (0.0.0.0/0).
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*Zrg4Xv1DtGWRM_ZEPq53PA.png)
Click Save changes.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*REPHLAIbVVRFfym57xDadg.png)
I do not like this new screen. I wasted a bunch of time trying to figure out what it is doing.
Create the NAT subnet
Click on Subnets on the left. Click on your pfSense subnet.
Note the Availability Zone.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*SPEpzs7u6VP5oFXvoPYY2Q.png)
Return to the list of subnets. Click Create subnet.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*2r9FqowxmQXnyrYHKkHFsw.png)
Here’s where I realized I used the entire VPC CIDR block on my last subnet. Thankfully we can do something you couldn’t do when I started working in AWS and it used to be so painful. Rather than delete my subnet and all it’s configuration, including the VPN we set up, or the entire VPC to create a bigger CIDR block — we can add a CIDR.
Head over to the list of VPCs in a separate tab.
Click on your pfSense VPC. Click Actions > Edit CIDRS.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*hMQpUabwkbZr5649iPEIZA.png)
Click Add new IPv4 CIDR. (or IPv6 if you’re using that.)
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*TRSaS_3d8lUn_jclnbfYwA.png)
Add a second CIDR. Click Save. Click Close.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*etK206RfswbVNDc-e9axZw.png)
Back over on our subnet, unfortunately there is no refresh button. (#awswishlist)
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*ap0oPuVGXln1XSHnb4hocg.png)
Refresh the screen and start over creating a subnet and selecting the new CIDR we just added above as the CIDR for the Subnet.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*2HZ-fWugtVR5FEhifEFaBw.png)
Choose the pfSense VPC.
Enter a name for the subnet.
Choose the same availability zone as the first subnet.
Choose the CIDR block we just added.
Use that same CIDR block for the subnet CIDR.
Click Create Subnet.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*P6qdRBVvnaBc6fQFtfAUXw.png)
Recreate the NAT as we did above in the new Subnet.
Choose the existing Elastic IP instead of creating a new one.
Get the private IP address of the NAT.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*mGr2foklL-0cpTQt2cPNLg.png)
Now we can use that to create a target for our Load Balancer.
Create a Load Balancer Target Group
Back on the Load Balancer Tab, click Create target group.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*u5yvorSCGlr8ReCPblKf2A.png)
Enter Basic configuration.
Choose IP addresses.
Add a name.
Choose IPv4 (or IPv6 if you are using that).
Choose the pfSense VPC.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*xVn5Imel2GF8XTjlaJod7A.png)
I left defaults for the rest. Click Next.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*kFXfWsyGoNPldxn2wIUzTQ.png)
On the next screen choose Other private IP address.
Choose the Availability Zone we selected for both subnets.
Enter the private IP address of the NAT for the target.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*luUUP4Q4xOz7fm_qmsEgzg.png)
Click Include as pending below. Then Create target group.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*7jUG7zleC0k2KlMGQo9NJA.png)
Once that’s complete you can look at the details of the target group and see that our target is healthy.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*1MH-mVx_da--9Tfg02EGeg.png)
If you were creating some kind of system with multiple servers you could add multiple targets or servers to this target group. But the NAT Gateway is resilient and we only need one target.
Complete the Load Balancer Configuration
Now you can return to the Load Balancer.
Click the refresh button and select your new target group.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*aG-k1O3Ycy4pKyRXI1MEsQ.png)
Click Create Load Balancer.
So now I check my target group again and it says my target is unhealthy. Why is that?
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*J-SJ6ro_uNM8bC-Byz-I5Q.png)
There’s nothing wrong with my NAT:
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*4wrz32Qpjyz4j6gbqoD3PQ.png)
The problem is this. You can’t ping a NAT. In fact you can’t query a NAT in any way apparently. You can only pass traffic through it.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*30oZ5S6KM0oUsc0IubZZMw.png)
In addition to not being able to ping the NAT, there’s no way to override the health check on a target group as far as I can tell.
Even if I could override the health check, I was able to send HTTP requests to the NAT in a prior post to see if my routing was correct but the traffic got dropped at the NAT.
Well, Q told me I could do this. Can I get something from AWS for that like the person who got something from the Canadian airlines? 😆 JK.
I tried to ask Amazon Q if there’s any way around this to no avail. This is where you get into those tricky scenarios that AI can’t answer or gives you incorrect information as it did in a prior post. I’m sure someone will read this and fix it. But currently AI still takes human analysis.
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*u6aHjPncCVlXyR39EAi_nw.png)
So now what are my options?
What if I create a NAT instance? Yuck.
Do I even need the load balancer?
What if I could send traffic straight from the VPC to the NAT? Then I wouldn’t even have to configure or pay for the load balancer right?
Delete the load balancer if you’re following along. Leave the NAT.
See the next post in the series…
Follow for updates.
Teri Radichel | © 2nd Sight Lab 2024
About Teri Radichel:
~~~~~~~~~~~~~~~~~~~~
⭐️ Author: Cybersecurity Books
⭐️ Presentations: Presentations by Teri Radichel
⭐️ Recognition: SANS Award, AWS Security Hero, IANS Faculty
⭐️ Certifications: SANS ~ GSE 240
⭐️ Education: BA Business, Master of Software Engineering, Master of Infosec
⭐️ Company: Penetration Tests, Assessments, Phone Consulting ~ 2nd Sight Lab
Need Help With Cybersecurity, Cloud, or Application Security?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
🔒 Request a penetration test or security assessment
🔒 Schedule a consulting call
🔒 Cybersecurity Speaker for Presentation
Follow for more stories like this:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
❤️ Sign Up my Medium Email List
❤️ Twitter: @teriradichel
❤️ LinkedIn: https://www.linkedin.com/in/teriradichel
❤️ Mastodon: @teriradichel@infosec.exchange
❤️ Facebook: 2nd Sight Lab
❤️ YouTube: @2ndsightlab
![](https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*H9Ew1KCl-29nZiPR.jpeg)