Question

How to open port for specific IP (Droplet with VPN)

I have a Wireguard VPN on my droplet and want to open ports for my email server which is connected via VPN. As i have seen the firewall only supports opening ports for specific IP’s from the outside? So is it possible or should i route it? I already tried it to route with nginx with this but it did not work

# nginx wireguard config
server {
       listen 51820;

       location / {
               proxy_pass http://wireguard:51820;
               proxy_set_header Host $host;
               proxy_set_header X-Real-IP $remote_addr;
       }
}

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
December 20, 2023

Heya @craftycodes,

In order to open a port there is something that needs to listen to it. Opening a port essentially means allowing network traffic to flow in and out of a specific communication endpoint on a Droplet. However, for that port to be useful, there needs to be a program or service on the computer that is actively listening to that port.

Think of a port as a door, and the service as the thing behind the door. Opening the door (port) doesn’t do much if there’s nothing on the other side to interact with. When a service is set to listen on a specific port, it means that it’s waiting for incoming connections or data on that port.

Anyway, in order open a port on your Droplet you need to use your firewall service, I would asume UFW.

First check the status

sudo ufw status

Then you can allow a port like so

sudo ufw allow 22/tcp

Where 22 is your port and tcp is the time of connection.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel