I'm setting up a server that connects to an ovpn server through which it's able to access some remote devices.
Some of these devices have private IPs (no problems here), however the ones that have a public IP have a strict rule that allows access only from the ovpn server's public IP .
My server therefore needs to redirect all internet traffic through this vpn.
The trouble is that once i configure the default route through the vpn i completely lose access to the server through it's original public IP.
Is there a way to route all outgoing traffic through the vpn while still allowing replies incoming traffic from the EC2's original IP?
When i connect to the vpn these are the routes that get installed on my system, with 172.16.220.0/24 being the vpn server's private range and 172.29.64.0/18 being the EC2 VPC's private range.
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.16.220.161 128.0.0.0 UG 0 0 0 tun0
0.0.0.0 172.29.64.1 0.0.0.0 UG 100 0 0 ens5
10.0.0.0 172.16.220.161 255.0.0.0 UG 0 0 0 tun0
*vpn_public_ip* 172.29.64.1 255.255.255.255 UGH 0 0 0 ens5
128.0.0.0 172.16.220.161 128.0.0.0 UG 0 0 0 tun0
172.16.220.160 0.0.0.0 255.255.255.224 U 0 0 0 tun0
172.29.64.0 0.0.0.0 255.255.192.0 U 0 0 0 ens5
172.29.64.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens5
192.168.0.0 172.16.220.161 255.255.0.0 UG 0 0 0 tun0
With these routes i'm able to access the EC2 through it's private ip with another machine in the same private network, but i have no success reaching it's public ip.
Some info : the server runs on an AWS EC2 with ubuntu server 20.04 and the network interface has a private ip with a 1-to-1 nat with the public ip