Setting Up OpenVPN Relay to Hide Server IP
Posted: Tue Dec 14, 2021 11:07 pm
I'm trying to use OpenVPN to act as a relay for a game server I want to host locally. For privacy reasons, I want to hide my own public IP but I want to be able to allow other people online to connect to this server publicly and then route the traffic over a tunnel to reach my actual house.
I followed a setup guide and I have gotten as far as setting up the OVPN server, certs, firewall, etc. I also setup the OVPN client on my local game server and I have successfully connected to the OVPN/relay server. This is where I have hit a roadblock and exceeded my expertise in network routing. The goal is:
Game Client (Windows) -> Internet (via Public IP) -> Relay Server (OpenVPN server)(Debian) -> VPN Tunnel -> Game Server (OpenVPN client)(Windows)
The game runs on ports 2456-2458 TCP + UDP so my ultimate goal is that ONLY traffic on those ports is allowed through or directed across the VPN between the game server and the relay. I tried a variety of iptables alterations based on other forums online but I can't reach a state where the game will actually connect to the server over the public IP.
iptables -t nat -A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE
iptables -A INPUT -p tcp --match multiport --dports 2456:2458 -j ACCEPT
iptables -t filter -A FORWARD -p tcp -d 10.8.0.6 --dport 2456:2458 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 2456:2458 -j DNAT --to 10.8.0.6
My OVPN config also has this line uncommented:
push "redirect-gateway def1 bypass-dhcp"
This level of routing between subnets is admittedly out of my depth so any help in the right direction is greatly appreciated.
I followed a setup guide and I have gotten as far as setting up the OVPN server, certs, firewall, etc. I also setup the OVPN client on my local game server and I have successfully connected to the OVPN/relay server. This is where I have hit a roadblock and exceeded my expertise in network routing. The goal is:
Game Client (Windows) -> Internet (via Public IP) -> Relay Server (OpenVPN server)(Debian) -> VPN Tunnel -> Game Server (OpenVPN client)(Windows)
The game runs on ports 2456-2458 TCP + UDP so my ultimate goal is that ONLY traffic on those ports is allowed through or directed across the VPN between the game server and the relay. I tried a variety of iptables alterations based on other forums online but I can't reach a state where the game will actually connect to the server over the public IP.
iptables -t nat -A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE
iptables -A INPUT -p tcp --match multiport --dports 2456:2458 -j ACCEPT
iptables -t filter -A FORWARD -p tcp -d 10.8.0.6 --dport 2456:2458 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 2456:2458 -j DNAT --to 10.8.0.6
My OVPN config also has this line uncommented:
push "redirect-gateway def1 bypass-dhcp"
This level of routing between subnets is admittedly out of my depth so any help in the right direction is greatly appreciated.