PortScan › Port guide › Port 5432
Port 5432 (PostgreSQL): Checking listen_addresses and pg_hba.conf
Port 5432 is the PostgreSQL default. Exposed with a weak password, COPY ... FROM PROGRAM runs OS commands and miners get installed. Secure settings inside.
What is port 5432?
Port 5432 is PostgreSQL's default port. The default setting (listen_addresses = 'localhost') does not accept remote connections, but it is common to change it to '*' for remote access and allow 0.0.0.0/0 in pg_hba.conf.
When it is normally open
- Application servers connect to a dedicated database server
Risks if it is open
Superuser takeover, then OS command execution
Log in as a superuser such as postgres and you can run shell commands with COPY ... FROM PROGRAM. Attacks that plant miners on exposed PostgreSQL servers with weak passwords have been reported repeatedly.
trust authentication
If pg_hba.conf contains trust, connections succeed without a password. It sometimes gets added for testing and then forgotten.
Security checklist
- If no remote access is needed, use
listen_addresses = 'localhost'. - In
pg_hba.conf, allow only the IPs you need and usescram-sha-256authentication:host appdb app 10.0.0.5/32 scram-sha-256. - Application accounts must not be superusers.
- Do remote administration through an SSH tunnel:
ssh -L 5432:127.0.0.1:5432 user@server.
How to check whether port 5432 is open
From outside (is it exposed to the internet?)
Whether your server or home router accepts port 5432 from the internet can only be confirmed by connecting from outside. A check from inside the same network bypasses the router's firewall and gives a different answer.
PortScan opens a real TCP connection from the Cloudflare edge and reports Open, Closed or Filtered. Members can scan every port on their own IP for free and other targets free once a day.
Check port 5432On the server (what is listening?)
Windows (PowerShell):
netstat -ano | findstr ":5432 "
Get-NetTCPConnection -LocalPort 5432 -State Listen | Select LocalAddress,OwningProcess
Linux:
sudo ss -tlnp | grep ':5432 '
If it listens on 0.0.0.0 or [::] it is open on every network; 127.0.0.1 means only that machine can connect. To test port 5432 on a server from another computer, use Test-NetConnection server-address -Port 5432 on Windows or nc -vz server-address 5432 on Linux and macOS.
How to close or restrict port 5432
The best fix is to turn the service off or make it listen only on 127.0.0.1 (see the checklist above). If you need the service but must keep it off the internet, use a firewall.
Windows Firewall
# Administrator PowerShell
New-NetFirewallRule -DisplayName "Block TCP 5432" -Direction Inbound -Protocol TCP -LocalPort 5432 -Action Block
# To allow a single IP instead (block rules take precedence, so use this instead of the rule above)
New-NetFirewallRule -DisplayName "Allow TCP 5432 from office" -Direction Inbound -Protocol TCP -LocalPort 5432 -RemoteAddress 203.0.113.10 -Action Allow
Linux (ufw)
sudo ufw deny 5432/tcp
# Allow a single IP only
sudo ufw allow from 203.0.113.10 to any port 5432 proto tcp
On a cloud server, also check port 5432 in the security group (inbound rules), which is separate from the OS firewall. For services running in Docker, the rules Docker creates can bypass ufw, so binding the port to localhost with -p 127.0.0.1:5432:5432 is the reliable option.
Router
At home or in a small office, open the router's admin page and check whether port 5432 is in the port forwarding list, whether DMZ is enabled, and whether any program opened ports by itself through UPnP. If any of the three applies, port 5432 on your PC is directly visible from the internet.
How to read the scan result
- Open — something accepted a connection on port 5432. Work through the risks above.
- Closed — the packet reached the device, but nothing is listening on that port, so it was refused immediately (RST). The service is off.
- Filtered — no response. A firewall or the ISP is dropping packets, or the device is off. From an exposure point of view this is the safest state.
The verdict can depend on where you connect from. Many ISPs (including most Korean ISPs) block some ports such as 135, 139 and 445 on their network, so the same server can look Filtered from inside that network and Closed from abroad.
FAQ
- I changed the settings, but the port is still open
- Changes to
listen_addressesrequire a restart (a reload is enough forpg_hba.conf). If you run it in Docker,-p 5432:5432exposes it on every interface — change it to-p 127.0.0.1:5432:5432.
Related ports
Last updated 2026-11-04 · Use this guide to check systems you manage. Scanning systems without permission may carry legal liability.