Report this

What is the reason for this report?

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

Posted on December 19, 2023

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;
       }
}


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!

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.

Hey,

To manage firewall settings on a DigitalOcean Droplet, especially when setting up specific ports for a VPN like WireGuard, you can use ufw. It’s a user-friendly interface for managing iptables firewall rules on Ubuntu and other Linux distributions.

Here’s a step-by-step guide on using ufw to achieve your objective:

  1. Install and Enable UFW: If ufw is not already installed, you can install it with:

    sudo apt-get install ufw
    

    Enable ufw with:

    sudo ufw enable
    
  2. Allow VPN Traffic: Assuming WireGuard is using its default port (51820), you can allow traffic on this port with:

    sudo ufw allow 51820/udp
    
  3. Configure UFW for Specific IP Addresses: To allow connections to a specific port from a specific IP address, use a command like:

    sudo ufw allow from [Your-VPN-Client-IP] to any port [Your-Port]
    

    Replace [Your-VPN-Client-IP] with the IP address of your VPN client and [Your-Port] with the port number you want to open for that IP.

  4. Allow Email Server Traffic: For your email server, you’ll typically need to open ports like 587 (for SMTP), 993 (for IMAP), and 995 (for POP3). You can do this with:

    sudo ufw allow 587
    sudo ufw allow 993
    sudo ufw allow 995
    

    Remember to replace these with the appropriate ports if you’re using non-standard ones.

  5. Restrict Traffic on Port 25: It’s important to note that DigitalOcean blocks outbound traffic on port 25 (SMTP) for new accounts to prevent abuse. This means you can’t use this port for email traffic unless DigitalOcean has lifted this restriction for your account.

  6. Check and Manage UFW Status: To check the status of your UFW rules, use:

    sudo ufw status
    

    This will list all active rules and their corresponding actions.

  7. Deleting or Modifying Rules: If you need to delete or modify a rule, you can do so with ufw delete followed by the rule specification, or ufw status numbered to list rules with numbers and then ufw delete [number] to remove a specific rule.

Always double-check your firewall rules to ensure they are correctly configured for your needs. Incorrect firewall settings can lead to security vulnerabilities or connectivity issues.

For more detailed information, you might want to check out the UFW documentation.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.