I have been trying to get this working for a long time and finally decided I would join serverfault in hope that someone can help before I lose my mind.
Current setup:
Users connect into the AWS network via a WireGuard VPN server I setup. Its configured in NAT mode which means all users are hidden behind the WireGuard server IP address. They can SSH to machines using hostnames, or IP addresses and can also connect to the internet. Their WireGuard client config is set to route all traffic through the VPN as this adds a layer of protection if they are working in say a coffee shop.
Desired setup:
I would like to change the config so WireGuard is running in routing mode rather than NAT mode. This way users will get a unique IP address and I will be able to use AWS security groups to prevent certain users from reaching certain servers. Adds an extra layer of security which is nice.
How far I have got:
I can get routing mode "working", in that users get a unique IP address, they are still able to SSH to machines using hostnames or IP addresses. The problem I am facing is that they lose internet connection! So I solve one problem but create another. I have tried pinging 8.8.8.8 to rule out DNS being the problem.
Server config (NAT mode commented out):
[Interface]
Address = 10.0.0.162
SaveConfig = false
PrivateKey = abcdefg
ListenPort = 51820
#NAT mode:
#PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;
#PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE;
#Routing Mode attempt 1:
#Machines in AWS show connections from the actual client IP which is good. No internet access though.
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT;
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT;
[Peer] #My_Laptop
PublicKey = abcdefg
PresharedKey = abcdefg
AllowedIPs = 192.168.1.2/32
Client config:
[Interface]
PrivateKey = abcdefg
Address = 192.168.1.2/32
DNS = 10.0.0.162
[Peer]
PublicKey = abcdefg
PresharedKey = abcdefg
AllowedIPs = 0.0.0.0/0
Endpoint = x.x.x.x:51820
PersistentKeepalive = 25
Hopefully the above is enough information to show what I have tried. Note I have BIND running on the same machine as WireGuard. BIND simply forwards all DNS queries to AWS Route53.
I feel like its so close to working but I have been stuck at this point for months.