RackUp IT - View Cloud Hosting Plans

Get started now or speak directly with our engineering team for specialized assistance.

Logo
DevelopmentWEB & APPCalculatorTOOLServicesProductBlogOur TeamCareers
View Plans
Home>Blog>How to Open Ports on a VPS: UFW, iptables & firewalld
VPS Hosting

How to Open Ports on a VPS: UFW, iptables & firewalld

Alex Vance
Alex Vance
Published Oct 11, 2026· Updated Oct 19, 2026•✓ Verified Expert Reviewed•7 min read
How to open ports on a VPS with UFW, iptables and firewalld

Key Takeaways

  • ✓Check the port is actually listening with ss -tulpn before touching the firewall.
  • ✓UFW (Ubuntu/Debian) and firewalld (RHEL family) save rules for you; raw iptables needs iptables-persistent.
  • ✓Cloud providers add a second firewall (security groups) that must also allow the port.
  • ✓Test from outside the server: a timeout means a firewall, "refused" means nothing is listening.

Table of Contents

  • •How to Open Ports on a VPS: UFW, iptables & firewalld
  • •Before you start: is anything listening on the port?
  • •Open a port with UFW (Ubuntu and Debian)
  • •Open a port with firewalld (AlmaLinux, Rocky, RHEL, Fedora)
  • •Open a port with iptables
  • •Make iptables rules survive a reboot
  • •Open a port on a Windows VPS
  • •Docker ports bypass UFW
  • •Don't forget the cloud provider's firewall
  • •Test the port from outside the server
  • •How to close a port
  • •Only open what you need
  • •Frequently Asked Questions

How to Open Ports on a VPS: UFW, iptables & firewalld

A service on your VPS can be running perfectly and still be unreachable, because a firewall is dropping the traffic before it gets there. This guide shows you how to open a port with the three firewalls you'll meet on Linux servers (UFW, firewalld and plain iptables), how to make the rule survive a reboot, and how to test it from outside the server.

Quick answer: on Ubuntu or Debian run sudo ufw allow 443/tcp. On AlmaLinux, Rocky or RHEL run sudo firewall-cmd --permanent --add-port=443/tcp && sudo firewall-cmd --reload. Then check that your cloud provider's firewall (security group) allows the port as well.

Before you start: is anything listening on the port?

Opening a port only helps if a program is listening on it. Check first:

sudo ss -tulpn

Look for your port in the Local Address column:

  • 0.0.0.0:443 or [::]:443 means the service accepts connections from anywhere. This is what you want for a public service.
  • 127.0.0.1:3000 means it only listens on the server itself. No firewall rule will make it reachable; change the app's bind address, or put a reverse proxy such as Nginx in front of it.
  • If the port isn't in the list at all, the service isn't running. Start it before you touch the firewall.

Keep your SSH session safe. Before enabling or reloading a firewall, make sure SSH (port 22, or your custom port) is allowed. Locking yourself out of a VPS usually means a trip to the provider's web console.

Open a port with UFW (Ubuntu and Debian)

UFW ("Uncomplicated Firewall") is the default front end on Ubuntu. Check its state:

sudo ufw status verbose

Allow SSH first, then the ports you need, then enable the firewall:

sudo ufw allow OpenSSH          # or: sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Useful variations:

sudo ufw allow 8000:8100/tcp                         # a port range
sudo ufw allow from 203.0.113.10 to any port 5432    # one IP only (e.g. a database)
sudo ufw status numbered                             # list rules with numbers
sudo ufw delete 3                                    # remove rule number 3

UFW rules are saved automatically and survive a reboot.

Open a port with firewalld (AlmaLinux, Rocky, RHEL, Fedora)

firewalld groups rules into zones. Most servers use the public zone. Check what's open:

sudo firewall-cmd --get-active-zones
sudo firewall-cmd --list-all

Open a port permanently, then reload so it takes effect:

sudo firewall-cmd --permanent --add-port=443/tcp
sudo firewall-cmd --reload

For well-known services you can use the service name instead of the number:

sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload

Without --permanent the rule only lasts until the next reload or reboot. That's handy for a quick test, but easy to forget.

Open a port with iptables

If your server has no UFW or firewalld, or you manage rules by hand, use iptables directly. List the current rules with line numbers:

sudo iptables -L INPUT -n --line-numbers

Rule order matters: iptables stops at the first match. If there's a REJECT or DROP rule near the end of the chain, your new rule must go above it. Insert it at a position rather than appending it:

sudo iptables -I INPUT 5 -p tcp --dport 443 -m state --state NEW -j ACCEPT

Replace 5 with the line number of the first REJECT/DROP rule. On a server without one, -A INPUT (append) is fine.

Make iptables rules survive a reboot

iptables rules live in memory and disappear on reboot unless you save them. On Ubuntu or Debian:

sudo apt install iptables-persistent
sudo netfilter-persistent save

This writes the rules to /etc/iptables/rules.v4 (and rules.v6 for IPv6), which are loaded at boot. Run sudo netfilter-persistent save again after every change.

Don't mix tools. UFW and firewalld both write iptables/nftables rules for you. If one of them is active, add rules through it, not with raw iptables, or your changes may be overwritten on the next reload.

Open a port on a Windows VPS

On Windows Server, open PowerShell as Administrator and add an inbound rule to Windows Defender Firewall:

New-NetFirewallRule -DisplayName "Allow HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow

Check it with Get-NetFirewallRule -DisplayName "Allow HTTPS", and remove it later with Remove-NetFirewallRule -DisplayName "Allow HTTPS". The cloud provider’s firewall (below) still applies on Windows too.

Docker ports bypass UFW

If you run Docker on Ubuntu, a port you publish with -p 8080:80 (or ports: in Docker Compose) is reachable from the internet even if UFW doesn’t allow it. Docker adds its own iptables rules, and published traffic is routed before UFW’s rules are checked, so ufw status can look closed while the port is open.

The simplest fix is to publish container ports on localhost only and put a reverse proxy such as Nginx in front:

# docker run
docker run -p 127.0.0.1:8080:80 my-app

# docker-compose.yml
ports:
  - "127.0.0.1:8080:80"

If a container really must be public but only to certain addresses, add your rules to the DOCKER-USER iptables chain, which Docker checks before its own rules. Always test from outside the server (next sections) after changing Docker ports.

Don't forget the cloud provider's firewall

Many providers put a second firewall in front of your server: security groups on AWS, firewall rules on Google Cloud, security lists on Oracle Cloud, and cloud firewalls on DigitalOcean and Hetzner. Traffic has to pass both that firewall and the one on the server. If the port is open on the server but still unreachable from outside, this is almost always the reason. Add an inbound rule for the port in the provider's control panel.

On Oracle Cloud you also need to deal with the iptables rules Oracle ships in its images. That's covered step by step in How to open ports 80 and 443 on an Oracle Cloud VPS.

Test the port from outside the server

Testing from the server itself proves nothing about the firewall, because local traffic usually bypasses it. Run these from your own computer or another server:

nc -zv your.server.ip 443
curl -I https://your.server.ip --insecure

To check several ports at once, scan from another machine with nmap:

nmap -p 22,80,443 your.server.ip

nmap reports each port as open (reachable and listening), closed (reachable, nothing listening) or filtered (a firewall is dropping the traffic).

How to read the result:

ResultWhat it usually means
succeeded / openThe port is open and something is listening.
Connection refusedThe firewall let the traffic through, but nothing is listening on that port (or it's bound to 127.0.0.1).
Times outA firewall is dropping the traffic, either on the server or at the cloud provider.

If the port is open but your website returns an error, the problem has moved from the firewall to the web server. See how to fix Nginx 403 Forbidden and Nginx 502 Bad Gateway.

How to close a port

Close ports you no longer need with the same tool you used to open them:

# UFW
sudo ufw delete allow 8080/tcp

# firewalld
sudo firewall-cmd --permanent --remove-port=8080/tcp
sudo firewall-cmd --reload

# iptables (then save, as above)
sudo iptables -D INPUT -p tcp --dport 8080 -j ACCEPT
sudo netfilter-persistent save

It’s also worth stopping the service that was listening if you no longer use it, so nothing is exposed if a rule is opened by mistake later.

Only open what you need

Every open port is something an attacker can probe. A typical web server needs only 22 (SSH), 80 and 443. Keep databases (3306, 5432, 27017) and admin panels closed to the internet, or limit them to your own IP with a rule like the UFW from … to any port example above.

Would you rather not manage a server at all? With RackUp's managed WordPress and cloud app hosting we look after the server side for you, firewall included. If you want full control, our Developer VPS plans give you root access to set your own rules with the commands above.

Frequently Asked Questions

How do I check which ports are open on my VPS?
On the server, sudo ss -tulpn lists the ports programs are listening on, and sudo ufw status or sudo firewall-cmd --list-all shows what the firewall allows. To see what's reachable from the internet, test from another machine with nc -zv your.server.ip PORT.

Why is my port still closed after I opened it in UFW?
Usually for one of three reasons: the cloud provider's firewall (security group) is still blocking it, the service is listening on 127.0.0.1 instead of 0.0.0.0, or the service isn't running. Check each one in that order.

Do iptables rules survive a reboot?
No, not by default. Save them with iptables-persistent (sudo netfilter-persistent save) on Debian/Ubuntu. UFW and firewalld rules added with --permanent are saved automatically.

Should I use UFW, firewalld or iptables?
Use whatever your distribution ships with: UFW on Ubuntu/Debian, firewalld on RHEL-based systems. Both are front ends that manage the underlying iptables/nftables rules for you. Use raw iptables only if neither is installed.

Is it safe to open port 22 to the whole internet?
It's common, but you should use SSH keys, disable password login, and consider tools like fail2ban. For extra protection, allow port 22 only from your own IP address.

← Previous ArticleCommon Nginx Errors and How to Fix Them (400 to 504)Next Article →docker exec: How to Run Commands and Open a Shell Inside a Container
Interactive 60-Second Tool

Unsure Which Cloud Hosting Plan Fits Your Site?

Answer 4 quick diagnostic questions to estimate the server CPU, RAM and storage you need with transparent pricing.

Free Migration 99.9% Uptime Target
Calculate My Hosting Build
Alex Vance
Written ByAlex Vance

Cloud Infrastructure Engineer.

99.9% Uptime Target

RackUp IT - View Cloud Hosting Plans

View Hosting Plans

View Hosting Plans

CONTENTS

  • How to Open Ports on a VPS: UFW, iptables & firewalld
  • Before you start: is anything listening on the port?
  • Open a port with UFW (Ubuntu and Debian)
  • Open a port with firewalld (AlmaLinux, Rocky, RHEL, Fedora)
  • Open a port with iptables
  • Make iptables rules survive a reboot
  • Open a port on a Windows VPS
  • Docker ports bypass UFW
  • Don't forget the cloud provider's firewall
  • Test the port from outside the server
  • How to close a port
  • Only open what you need
  • Frequently Asked Questions

Categories

  • VPS Hosting
  • DevOps & Tutorials
  • WordPress Hosting
  • Cloud Hosting
  • Server Stack
  • Networking & Security
  • Web Hosting / Managed Cloud
  • E-Commerce
  • Hosting & SEO
  • Hosting Benchmarks
  • Cloud Backup & DevOps
  • Managed VPS

Recent Posts

  • Vultr Alternatives in 2026: VPS Hosting for Developers Compared
  • Docker Port Mapping Explained: -p, EXPOSE and Compose ports
  • Bluehost Alternatives (2026): WordPress Hosting Without the Renewal Price Jump

Tags

VPSFirewallUFWiptablesfirewalldLinux

Related Posts

Vultr alternatives coverVPS Hosting
Nov 27, 2026

Vultr Alternatives in 2026: VPS Hosting for Developers Compared

Vultr's Regular Performance prices compared with DigitalOcean, Linode, Hetzner and a fixed-plan VPS at the 8 GB size, plus when container hosting fits better.

Read Article →
What is a VPS? Virtual private servers explainedVPS Hosting
Nov 20, 2026

What Is a VPS? Virtual Private Servers Explained

A VPS (virtual private server) is a virtual machine with its own operating system, resources and root access. How it works, uses, and when you need one.

Read Article →
Linode alternatives coverVPS Hosting
Nov 19, 2026

Linode (Akamai) Alternatives in 2026: VPS Hosting Compared

Linode's shared CPU prices from Akamai's own API, compared with DigitalOcean, Vultr and a fixed-plan VPS, plus when container hosting makes more sense.

Read Article →
Logo

Expert Web & App Development, UI/UX Design, Branding, and Consulting to scale your business.

Company

  • About Us
  • Blog
  • Contact
  • Our Team
  • Careers

Services

  • Web Development
  • App Development
  • UI/UX Design
  • Consulting
  • Managed WordPress VPS
  • Website Speed Test

Subscribe to our newsletter

We accept
  • bKash
  • Nagad
  • Rocket
  • Upay
  • CellFin
  • Meghna Pay
  • OK Wallet
  • Tap
  • mCash
  • DBBL Nexus
  • Visa
  • Mastercard
  • American Express
  • Crypto
Pay with Visa, Mastercard, American Express, DBBL Nexus, CellFin, Rocket, bKash, Tap, Meghna Pay, Nagad, mCash, Upay and OK Wallet. Verified by EPS

© 2026 Rackup IT Solution. All rights reserved.

Privacy PolicyTerms of Service