Security

Is your MySQL port really open? Checking from the outside

A database listening on 0.0.0.0 isn't necessarily exposed, and a firewalled-looking one sometimes is. Why only an outside check gives a real answer.

Run ss -tlnp on a typical web server and you'll often see MySQL, Redis or PostgreSQL listening on 0.0.0.0, meaning every network interface, public ones included. Is that a problem? It depends on something the server itself often can't see.

Listening isn't the same as exposed

$ sudo ss -tlnp | grep -E '3306|6379|5432'
LISTEN 0 151  0.0.0.0:3306  0.0.0.0:*  users:(("mysqld",pid=812,fd=23))

This says MySQL will accept connections on any address. Whether anyone on the internet can actually reach it depends on every layer between the server and the outside world:

  • The host firewall, such as ufw or nftables rules on the server.
  • Cloud firewalls and security groups, such as AWS security groups, DigitalOcean cloud firewalls or Hetzner firewalls. These live outside the server, and the server has no way to read them.
  • Network design: NAT, private networks and load balancers.

So a server-side check can only guess. A database on 0.0.0.0 behind a strict security group is safe. One behind a missing or misconfigured rule is open to the whole internet, and looks identical from the inside.

Why it's so common

Many control panels and install guides bind databases to all addresses so that other servers in the same project can connect. That's convenient, and fine when a firewall restricts who can reach the port. The risk appears when a rule is removed during debugging, a new server is created without the cloud firewall attached, or a security group is copied with the wrong source range.

There's also a well-known trap with Docker: ports published with -p 3306:3306 are inserted into iptables by Docker itself and can bypass ufw rules entirely. The host firewall says “denied”, and the port is open anyway.

How to check properly

The only reliable test is to try connecting from outside, from a machine that isn't inside your private network:

$ nc -vz -w 3 203.0.113.10 3306
Connection to 203.0.113.10 3306 port [tcp/mysql] succeeded!

If that succeeds, the port is exposed, whatever the server's firewall config says. If it times out or is refused, something in between is blocking it.

When you find an exposed database, the fix depends on the setup:

  • If nothing outside the server needs it, bind it to localhost. For MySQL, set bind-address = 127.0.0.1 in /etc/mysql/mysql.conf.d/mysqld.cnf and restart.
  • If other servers need it, restrict the port to their addresses in the cloud firewall, or use a private network.
  • As an immediate stop-gap with ufw: sudo ufw deny 3306. Remember the Docker caveat above.

How Uptavio checks it

Uptavio's agent reports which ports are listening on public addresses. Then, every 15 minutes, Uptavio's own servers try a plain connection to each one from outside, send nothing, and close the connection.

  • Only a port that really accepts connections raises a critical alert, with the command to close it.
  • A firewalled port raises nothing, so a database bound to 0.0.0.0 behind a correct security group stays quiet.
  • A port that couldn't be checked says so. It's never silently reported as fine.

The ports covered are MySQL, PostgreSQL, Redis, Memcached, MongoDB, Elasticsearch, CouchDB, Meilisearch and the Docker API. Checks only ever go to public addresses your server has shown are its own, so Uptavio can't be used to probe anyone else's machine.

The takeaway

Don't judge exposure from inside the server. A database listening on every address can be perfectly safe, and a host firewall that says “deny” can be bypassed. Test from the outside, regularly, and only worry about the ports that actually answer.


Uptavio checks this for you. Ubuntu-aware vulnerability scanning, outside-in exposure checks, patch and reboot tracking, and a To do list with the exact command for every fix. Free for 2 servers and 5 websites. Start free →

Know what to fix by lunchtime.

Two servers and five websites are free, forever. Every new organization also gets 14 days of Agency. No credit card, no inbound ports, and no keys handed over.