# Port Forwarding Server VPS

**URL:** <https://community.unix.com/t/port-forwarding-server-vps/390160>\
**Category:** IP Networking\
**Created:** [February 22, 2023, 9:29am UTC](https://community.unix.com/t/port-forwarding-server-vps/390160 "2023-02-22T09:29:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mira5h](https://community.unix.com/letter_avatar/mira5h/32/6_449c533f586939b6e5f246632a46421f.png) [@Mira5h](https://community.unix.com/u/Mira5h)\
**Post date:** [February 22, 2023, 9:29am UTC](https://community.unix.com/t/port-forwarding-server-vps/390160/1 "2023-02-22T09:29:45Z")

</div>

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.....

---

<div class="post-metadata">

**Author:** ![joker](https://community.unix.com/user_avatar/community.unix.com/joker/32/10678_2.png) [@joker](https://community.unix.com/u/joker)\
**Post date:** [February 22, 2023, 11:56am UTC](https://community.unix.com/t/port-forwarding-server-vps/390160/2 "2023-02-22T11:56:03Z")

</div>

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:

```plaintext
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

---

<div class="post-metadata">

**Author:** ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)\
**Post date:** [March 8, 2023, 11:56am UTC](https://community.unix.com/t/port-forwarding-server-vps/390160/3 "2023-03-08T11:56:25Z")

</div>

Closed on March 8, 2023, 11:56am UTC

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