# How to correctly port forward through a vpn? (student dorm)

**URL:** <https://forum.storj.io/t/how-to-correctly-port-forward-through-a-vpn-student-dorm/14817>\
**Category:** Node Operators\
**Tags:** docker, vpn\
**Created:** [August 4, 2021, 12:54pm UTC](https://forum.storj.io/t/how-to-correctly-port-forward-through-a-vpn-student-dorm/14817 "2021-08-04T12:54:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FeKgr](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/fekgr/32/1122_2.png) [@FeKgr](https://forum.storj.io/u/FeKgr)\
**Post date:** [August 4, 2021, 12:54pm UTC](https://forum.storj.io/t/how-to-correctly-port-forward-through-a-vpn-student-dorm/14817/1 "2021-08-04T12:54:54Z")

</div>

I am trying to get a node up and running while not being able to port forward through the local router because it is not mine. Thus, I am using Private Internet Access VPN which allows me to get a public open port (e.g. 50254). I use the gluetun docker image for this purpose and want to connect my storj docker to it using the " --net=container:gluetun" variable, which works fine.

The problem is the following: I am starting up my VPN container and then get assigned a random port. But because the storagenode container is using the network of the vpn container, I cannot use the “-p 50254:28967” variable which makes total sense. Is there an alternative way to route the random public port into the storj container that allows for port “remapping” in between?

Hope you can understand my problem 🙂

---

<div class="post-metadata">

**Author:** ![peem](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/peem/32/6323_2.png) [@peem](https://forum.storj.io/u/peem)\
**Post date:** [August 4, 2021, 1:06pm UTC](https://forum.storj.io/t/how-to-correctly-port-forward-through-a-vpn-student-dorm/14817/2 "2021-08-04T13:06:30Z")

</div>

How is that?

[![](https://img.youtube.com/vi/vUyHGF1HMsw/maxresdefault.jpg "Force Docker containers to use a VPN for web connections with confidence! Open Source & Self Hosted") ](https://www.youtube.com/watch?v=vUyHGF1HMsw)

---

<div class="post-metadata">

**Author:** ![FeKgr](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/fekgr/32/1122_2.png) [@FeKgr](https://forum.storj.io/u/FeKgr)\
**Post date:** [August 4, 2021, 1:48pm UTC](https://forum.storj.io/t/how-to-correctly-port-forward-through-a-vpn-student-dorm/14817/3 "2021-08-04T13:48:57Z")

</div>

Well no, not really. I want to use PIAs random port for storj. So i need to assign storj the random port. This tutorial is about accessing some services HTTP server, although the main traffic is using the VPN. I am already doing this to look at the localhost:14002 status page. This is different though. I am talking about the port thats usually 28967 and needs to be routed into the random port to reach the internet.

---

<div class="post-metadata">

**Author:** ![FeKgr](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/fekgr/32/1122_2.png) [@FeKgr](https://forum.storj.io/u/FeKgr)\
**Post date:** [August 4, 2021, 3:03pm UTC](https://forum.storj.io/t/how-to-correctly-port-forward-through-a-vpn-student-dorm/14817/4 "2021-08-04T15:03:11Z")

</div>

I kind of wanna use PIA and port forwarding like a reverse proxy. Similar to this: [https://support.storj.io/hc/en-us/articles/360026892971-Running-a-V3-Storage-Node-with-PIA-VPN-](https://support.storj.io/hc/en-us/articles/360026892971-Running-a-V3-Storage-Node-with-PIA-VPN-)  
but using docker and not a system wide VPN.

---

<div class="post-metadata">

**Author:** ![Alexey](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alexey/32/41_2.png) [@Alexey](https://forum.storj.io/u/Alexey)\
**Post date:** [August 4, 2021, 9:31pm UTC](https://forum.storj.io/t/how-to-correctly-port-forward-through-a-vpn-student-dorm/14817/5 "2021-08-04T21:31:44Z")

</div>

> **[Port forwarding · qdm12/gluetun Wiki](https://github.com/qdm12/gluetun/wiki/Port-forwarding#private-internet-access)**
>
> VPN client in a thin Docker container for multiple VPN providers, written in Go, and using OpenVPN, DNS over TLS, with a few proxy servers built-in. - Port forwarding · qdm12/gluetun Wiki

But you need to add some scripting to configure your ADDRESS environment variable with that port.  
But it’s not a main problem. The main problem that you cannot use `-p` option to forward that port to the storagenode container, at least it would be useless.  
You need to bind the storagenode to the 0.0.0.0:\<PIA\_PORT\>. You can do that in the `config.yaml` in the `server.address:` parameter or with the `--server.address` option, i.e.

```auto
storagenode run --identity-dir identity --config-dir config --server.address 0.0.0.0:$(cat /tmp/gluetun/forwarded_PIA_port)

```

But you need to use a volume in the gluetun container and share it with the storagenode container and mount it to the /tmp/gluetun/forwarded\_PIA\_port.

It could work only if you inject storagenode to the gluetun container.  
So, you need to build your own image.

There is not exactly working setup, just an idea:  
**Dockerfile** :

```auto
FROM storjlabs/storagenode as addon
FROM qmcgaw/gluetun
COPY --from=addon /app/ /app/
COPY --from=addon /entrypoint /app/entrypoint
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
WORKDIR /app
ENTRYPOINT ["/entrypoint.sh"]

```

**entrypoint.sh**

```auto
#!/bin/sh
/entrypoint &
if [-f ${PUBLICIP_FILE}] && [-f ${PORT_FORWARDING_STATUS_FILE}]; then
    export ADDRESS=$(cat ${PUBLICIP_FILE}):$(cat ${PORT_FORWARDING_STATUS_FILE})
    /app/entrypoint --server.address=0.0.0.0:$(cat ${PORT_FORWARDING_STATUS_FILE}) "$@"
elif [[-z "`jobs`"]]; then
    echo "gluetun died" 1>&2
    exit 1
else
    sleep 10
fi

```

**docker-compose.yaml** :

```auto
version: '3'
services:
  storagenode:
    image: gluetun-storagenode
    build: .
    container_name: storagenode
    cap_add:
      - NET_ADMIN
    environment:
      - OPENVPN_USER=js89ds7
      - OPENVPN_PASSWORD=8fd9s239G
      - REGION=AU Melbourne
      - PORT_FORWARDING=on
      - WALLET=0x....
      - EMAIL=a@bc.com
      - STORAGE=20TB
    ports:
      - "14002:14002"
    volumes:
      - type: bind
        source: /mnt/storj/storagenode/identity
        destination: /app/identity
      - type: bind
        source: /mnt/storj/storagenode/
        destination: /app/config

```

Unfortunately the watchtower cannot update the custom build image.  
To update you would need to do:

```auto
docker-compose build --pull
docker-compose up -d

```
