Site AI Auditby Internet Solutions

Open Ports on Your Web Server: Which Ones to Close

13 tháng 10, 20268 phút đọcBảo mật & SSL
Open Ports on Your Web Server: Which Ones to Close

Short answer: A typical website needs only two ports open to the whole internet: 80 for HTTP, which should redirect, and 443 for HTTPS. Mail servers add their mail ports. Administrative services such as SSH, control panels and remote desktop should be limited to known IP addresses or a VPN, and databases, caches and internal APIs should never be reachable from the internet. Check from outside with a port scanner, compare the result with what you expect, and close the rest with a firewall.

What an open port is

A server can run many network services at the same time: a web server, a database, an SSH server for administration, a mail server, a cache. Each service listens on a port number. If the firewall allows connections to that port from the internet, the port is “open”, and anyone in the world can try to talk to the service behind it.

Automated scanners do exactly that, all day, across the whole internet. Search engines for internet-connected devices index open services and their versions, so an exposed database or admin interface can be found within hours of going online. Every open port is a service that must be patched, configured and protected. Fewer open ports means fewer things that can go wrong.

Ports a website actually needs

PortServiceWho should reach it
443HTTPSEveryone
80HTTP, redirecting to HTTPS and used for some certificate checksEveryone
22SSH or SFTP administrationYour team’s IP addresses or VPN only
25SMTP between mail serversEveryone, only if this server receives mail
587, 465Mail submission from email clientsYour users, only if this server hosts mailboxes
993, 995IMAP and POP3 over TLSYour users, only if this server hosts mailboxes
2083, 2087, 8443 and similarHosting control panelsYour team only, where possible
3306, 5432MySQL, PostgreSQLNobody from outside; local or private network only
6379, 11211Redis, MemcachedNobody from outside

Port 80 is worth keeping open even on an HTTPS-only site, so that visitors typing the address without https are redirected. Our guide to the HTTP to HTTPS redirect explains how to set that up correctly. For mail ports, see SMTP ports 25, 587 and 465.

The most dangerous exposed services

How to check your server from outside

What matters is what the internet sees, not what you think is configured. Check from a network outside your server:

  1. Run a port scan of your own server’s public IP address. The open-source tool Nmap is the standard: nmap -Pn your.server.ip checks common ports, and nmap -Pn -p- your.server.ip checks all 65,535 TCP ports. Only scan servers you own or have permission to test.
  2. List what listens locally. On Linux, ss -tulpn shows every service and the address it listens on. A service bound to 127.0.0.1 is only reachable from the server itself; one bound to 0.0.0.0 or :: listens on all interfaces and relies on the firewall.
  3. Compare the two lists. Every port that is open from outside should be on your “needed” list. Anything else is a finding.
  4. Check IPv6 too. Firewall rules are sometimes written only for IPv4, leaving the same services open on the server’s IPv6 address.

If you are on shared hosting, the provider manages the firewall and you usually cannot change it. Port questions then become questions for your host, while you focus on the parts you control, such as the application and its file permissions.

How to close or restrict ports

There are three levels, and the strongest setups use all of them:

Remove services you do not use at all. A service that is not installed cannot be attacked.

Traps that leave ports open by accident

Make it a regular check

Ports change whenever someone installs software, changes hosting or deploys a new container. A light routine catches problems early:

Open ports on shared hosting, VPS and cloud servers

Who is responsible for ports depends on the kind of hosting you use:

Whatever the setup, write down who owns the firewall. Many exposed databases are not the result of an attack, but of each party assuming the other had closed the port.

How Site AI Audit helps

Site AI Audit checks your website through the web, the way visitors and search engines see it, and does not scan other ports. It checks the parts of the web service that face everyone: whether the site works over HTTPS, whether HTTP redirects to HTTPS, whether the SSL certificate is valid, trusted, matches the domain and when it expires, whether HSTS and other basic security headers are set, and whether the server or WordPress reveals its version. Use it next to a port scan of your own server. You can run a free check; plans with monitoring are on the pricing page.

Related reading

The bottom line

Expose only what your website and mail need: 443 and 80 for everyone, mail ports only where mail is hosted, admin services only for your team, and databases and caches for nobody outside. Bind internal services to local addresses, use a default-deny firewall, watch out for Docker and temporary rules, and scan your server from outside regularly.

FAQ

Which ports should be open on a web server?

Usually only 443 for HTTPS and 80 for the redirect to HTTPS. Add mail ports if the server handles email, and allow SSH or control panels only from trusted addresses.

Is it dangerous to have port 22 open?

An SSH port open to everyone attracts constant password guessing. It is much safer to allow it only from known IP addresses or a VPN, use key-based login and disable password login.

How do I check which ports are open on my server?

Scan the server’s public IP address from another network with a tool such as Nmap, and list listening services on the server with ss -tulpn. Compare both with the ports you expect.

Should MySQL port 3306 be open to the internet?

No. Databases should listen only on the local or private network. If a remote application needs access, use a private network, a VPN or an SSH tunnel instead.

Why is a Docker port open when my firewall blocks it?

On Linux, Docker inserts its own firewall rules for published ports, which can bypass host firewall tools such as ufw. Publish internal ports on 127.0.0.1 only, or not at all.

#Checklists#Web hosting#Website security
Hãy kiểm tra website của chính bạn — miễn phí.Website của bạn cần sửa gì — và nên bắt đầu từ đâu.
Bắt đầu miễn phí
Internet Solutions

Sản phẩm khác từ đội ngũ chúng tôi

Do Internet Solutions phát triển. Hãy thử các sản phẩm khác của chúng tôi — mỗi sản phẩm giúp bạn tiết kiệm thời gian theo một cách riêng.

internet-solutions.net ↗
01Tự động đăng mạng xã hội
PostRSS

Bài mới từ nguồn cấp RSS của bạn được tự động đăng lên Facebook, X, LinkedIn, Telegram và hơn 60 mạng khác.

Gói miễn phí · từ 2014Truy cập →
02Chat trực tuyến AI cho website
Talkmio

Website của bạn trả lời khách truy cập 24/7 từ chính nội dung của bạn, bằng ngôn ngữ của họ.

Gói miễn phí · không cần thẻTruy cập →
03Trợ lý AI
Ask Mio

Trò chuyện, viết code, thiết kế, viết bài và nghiên cứu. Mio chọn mô hình tốt nhất cho từng việc.

Gói miễn phíTruy cập →
04Lái tự động AI cho blog và mạng xã hội
AI Blog Autopilot

AI viết bài SEO dài 2.000–3.000 từ và chia sẻ từng bài lên hơn 60 mạng xã hội.

3 bài đầu tiên miễn phíTruy cập →
05Thu thập SEO chuyên sâu
Site SEO AI Audit

Thu thập SEO toàn diện trên 7 lĩnh vực, gồm cả khả năng hiển thị trong tìm kiếm AI, với cách sửa xếp theo mức tác động.

Lần kiểm tra đầu tiên miễn phíTruy cập →
06Nguồn cấp RSS và sản phẩm
RSS Feed Creator

Tạo RSS từ bất kỳ trang web nào, cùng nguồn cấp sản phẩm cho Google và Meta tự động cập nhật.

Gói miễn phíTruy cập →
07Phát triển website và SEO
Internet Solutions

Website, cửa hàng trực tuyến và hệ thống theo yêu cầu, do đội ngũ của chúng tôi thiết kế, xây dựng và vận hành.

Từ 2011Truy cập →