Port Forwarding Server VPS

Hello

Need some help...

Is a way to set up port forwarding on VPS that will forward all my local pc traffic through a different port i have few app which listening on specific ports so best scenario will be connect to the VPS and pass through all traffic on ports like..

Local PC Priv connection maybe wireguard 1.1.1.1
VPS 5.5.5.5 (will have public IP)

1.1.1.1:80 -----> 5.5.5.5:80
1.1.1.1:500-----> 5.5.5.5:500
1.1.1.1:5500---->5.5.5.5:5500

1.1.1.1 (wireguard or openvpn but dont know if that will works)

and next ones could change listening port but need to set up in that kind way...

sysctl net.ipv4.ip_forward=1

iptables -t nat -A PREROUTING -p tcp -d 5.5.5.5 --dport 80 -j DNAT --to-destination 1.1.1.1:80
iptables -t nat -A PREROUTING -p tcp -d 5.5.5.5 --dport 500 -j DNAT --to-destination 1.1.1.1:500

or Dynamic port forwarding with ssh...??

Could any one help me please.....

Hi Mira5h,

both options are possible. On one side iptables(like the way you showed it) used together with a VPN software(wireguard, openvpn, ...) and on the other side SSH-Port-Forwarding.

I would prefer ssh port forwarding, because it seems easier to me. For that make sure to set GatewayPorts to yes ín the sshd_config within the vps, so binding the forwarded ports on public ip addresses is allowed.

On your local PC you have to try a command (for testing) like this:

ssh -L [LOCAL_IP:]LOCAL_PORT:0.0.0.0:DESTINATION_PORT [USER@]VPS_IP_OR_FQDN

You can use multiple -L switches within your ssh-commandline.

After that you may use autossh or a self created script, to have the port forwarding permanently running.

Regards,
Joker

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.