Port 5432 is the default port for PostgreSQL. Applications and tools such as psql connect to it. It should not be reachable from the public internet.
- Port
- 5432
- Protocol
- TCP
- Service
- PostgreSQL
- Expose to internet?
- No
- Also used by
- PostgreSQL, TimescaleDB, CockroachDB (26257 by default), PgBouncer (often 6432)
Is port 5432 safe to open?
PostgreSQL exposed to the internet attracts password guessing against the postgres user. With superuser access, COPY ... FROM PROGRAM lets an attacker run commands on the server, which is a known route for cryptominers. PostgreSQL listens on localhost by default, so exposure usually comes from listen_addresses = '*' with a permissive pg_hba.conf.
How to secure PostgreSQL
- Keep
listen_addresses = 'localhost'in postgresql.conf, or list only private addresses. - In pg_hba.conf, allow specific hosts and use
scram-sha-256; nevertrustfor remote hosts. - Do not let applications connect as the
postgressuperuser. - Require TLS for remote connections (
hostssllines in pg_hba.conf).
Check if port 5432 is open
Linux: what is listening on this port
sudo ss -tlpn | grep ':5432 'Windows (PowerShell): what is listening
Get-NetTCPConnection -LocalPort 5432 -State Listen | Select-Object LocalAddress, OwningProcess, @{n='Process';e={(Get-Process -Id $_.OwningProcess).Name}}From another machine: is it reachable
nc -zv HOST 5432
# or
nmap -p 5432 HOST
# Windows
Test-NetConnection HOST -Port 5432Test the PostgreSQL service itself
pg_isready -h HOST -p 5432Restrict port 5432 in the firewall
Replace 10.0.0.0/8 with the network or address that needs access. Docker publishes container ports through its own iptables rules, which bypass ufw; bind published ports to 127.0.0.1 (-p 127.0.0.1:5432:5432) instead of relying on the host firewall.
ufw: allow only your private network, deny everyone else
sudo ufw allow from 10.0.0.0/8 to any port 5432 proto tcp
sudo ufw deny 5432/tcpfirewalld: allow one source network only
sudo firewall-cmd --permanent --remove-port=5432/tcp
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.0/8" port port="5432" protocol="tcp" accept'
sudo firewall-cmd --reloadiptables
sudo iptables -A INPUT -p tcp --dport 5432 -s 10.0.0.0/8 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 5432 -j DROPWindows Firewall (PowerShell, as Administrator)
New-NetFirewallRule -DisplayName "Block 5432 from internet" -Direction Inbound -Protocol TCP -LocalPort 5432 -RemoteAddress Internet -Action BlockMonitor port 5432
Run a TCP port monitor against your public IP on port 5432: here, a failed connection is the healthy result, so you know the firewall is still doing its job. On Linux, the Statance agent also reports every listening port on the server. TCP port monitoring.
Related ports
| Port 3306 | MySQL / MariaDB | High risk |
| Port 6379 | Redis | Critical risk |
| Port 27017 | MongoDB | Critical risk |
FAQ
How do I check if PostgreSQL is listening on all interfaces?
Run sudo ss -ltnp 'sport = :5432'. If the local address is 0.0.0.0 or [::], it is listening on every interface; check your firewall and pg_hba.conf.
What is port 5432 used for?
Port 5432 is the default port for PostgreSQL. Applications and tools such as psql connect to it. It is also used by PostgreSQL, TimescaleDB, CockroachDB (26257 by default), PgBouncer (often 6432).
Is it safe to open port 5432?
Not to the public internet. PostgreSQL exposed to the internet attracts password guessing against the postgres user. With superuser access, COPY ... FROM PROGRAM lets an attacker run commands on the server, which is a known route for cryptominers. PostgreSQL listens on localhost by default, so exposure usually comes from listen_addresses = '*' with a permissive pg_hba.conf.
Is port 5432 TCP or UDP?
PostgreSQL uses TCP on port 5432.
How do I check if port 5432 is open?
On the server, run sudo ss -tulpn | grep ':5432 ' (Linux) or Get-NetTCPConnection -LocalPort 5432 (Windows) to see what is listening. From another machine, run nc -zv HOST 5432 or Test-NetConnection HOST -Port 5432.
Know the moment a port stops answering.
TCP, HTTP, DNS and SSL checks from six regions, plus server metrics from a one-line agent.