Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
nc -zv db1.example.com 5432
Connection to db1.example.com 5432 port [tcp/postgresql] succeeded!
timeout 3 bash -c '</dev/tcp/db1.example.com/5432' && echo open || echo closed
curl -v telnet://db1.example.com:5432
nmap -p 22,80,443,5432 db1.example.comnc comes from nmap-ncat (RHEL) or netcat-openbsd (Ubuntu); the bash line needs no extra tool at all.
Step by step
- Test from the machine that has the problem (the app server), not from your laptop — firewalls are different for each source.
- Read the answer — there are only three:
| Answer | Meaning | Look at |
|---|---|---|
succeeded / open | Network and firewall are fine; something listens. | The app's config, credentials, TLS. |
Connection refused | The host answered "nothing listens on this port". | The service on the target: running? right port? bound to 127.0.0.1 only? |
timed out / filtered | Packets are dropped on the way. | Firewalls (target host, cloud security group, network), routing, VPN. |
- Check the name resolves to the right IP first:
getent hosts db1.example.com
10.0.2.21 db1.example.com- More detail with nmap (also shows several ports at once):
nmap -Pn -p 5432 db1.example.com
PORT STATE SERVICE
5432/tcp filtered postgresql- TLS ports — check the certificate and the handshake, not only the port:
openssl s_client -connect shop.example.com:443 -servername shop.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -enddate
curl -vI https://shop.example.com 2>&1 | grep -E 'Connected|SSL connection|HTTP/'- UDP (DNS, NTP, WireGuard) has no handshake — a "no answer" can mean open or filtered:
The best UDP test is a real request (dig for DNS, chronyc for NTP).
- From inside Kubernetes — start a throwaway Pod in the same namespace:
kubectl run nettest -n shop --rm -it --image=docker.io/library/busybox:1.37 --restart=Never -- nc -zv -w 3 postgres 5432Check that it worked
After a fix (firewall rule, service started), the same test turns from timed out/refused to succeeded — then test the real client (for example psql -h db1 -U app -c 'select 1').
Common problems
| Problem | Cause | Fix |
|---|---|---|
nc: command not found | Not installed. | dnf install nmap-ncat / apt install netcat-openbsd, or use the bash /dev/tcp line. |
refused although the service runs | It listens on 127.0.0.1 only, or on another port. | On the target: ss -ltnp; change the bind address. |
timed out | A firewall drops the traffic. | Open the port on the host and in the cloud firewall (only for the client network). |
| Works by IP, not by name | DNS points to another IP. | getent hosts NAME; fix DNS or /etc/hosts. |
| Port open, app still fails | TLS, credentials or app-level rules (for example pg_hba.conf). | Read the client error; test with the real client. |
| Different results from different servers | Rules allow only some sources. | Test from the real client host. |
Go further
- Command pages: nmap, curl, openssl, ss.
- Next how-tos: Open a port in the firewall, Find which process uses a port, Check the DNS records of a domain, Check when a TLS certificate expires, Trace the network path, Capture traffic with tcpdump, Find open ports on your servers with Nmap.
- Full guide: Install and use Nmap. Learn the basics: RH124 — Test the connection.
1What is the difference between "connection refused" and "timed out"?
Refused = the host answered but nothing listens; timed out = a firewall or the network dropped the packets.
2How can you test a TCP port without installing any tool?
timeout 3 bash -c '</dev/tcp/HOST/PORT' && echo open.