I was looking for an alternative to AWS nat gateway because the billing was high. The nat gateway costs $32 and per GB data charges on top. Then I found fck-nat. It is basically a nat solution that runs on a EC2 instance.
They have their own AMI image which is preconfigured but I wanted to understand how it works so I set it up manually on minimal amazon linux 2023(al2023-ami-minimal-kernel-5.12-arm64). The instance needs to be in a public subnet with a public ip.
I ran the following commands on the instance.
yum install amazon-cloudwatch-agent amazon-ssm-agent iptables conntrack-tools -y
curl -fL https://github.com/AndrewGuenther/fck-nat/releases/download/v1.4.0/fck-nat-1.4.0-any.rpm -o /tmp/fck-nat-1.4.0.rpm
yum --nogpgcheck -y localinstall /tmp/fck-nat-1.4.0.rpm
dnf install -y kpatch-dnf
dnf kernel-livepatch -y auto
dnf install -y kpatch-runtime
dnf update kpatch-runtime
systemctl enable kpatch.service
systemctl start kpatch.service
Disable source and destination check on instance eni settings.
Update the private subnet route table for 0.0.0.0/0 to point fck-nat instance id.
Run curl ifconfig.me on instance in private subnet. It will output fck-nat instance public ip.