From ops, db's port 5432 is refused, yet PostgreSQL is running. Look from inside db.
ss -tln
Lists the TCP ports this machine listens on: -t TCP, -l listening, -n numbers, not names.
learner@db:~$ ss -tln
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 200 127.0.0.1:5432 0.0.0.0:* ← only from db itself
LISTEN 0 4096 0.0.0.0:22 0.0.0.0:* ← from anywhere
…Local Address says where a program takes connections:
0.0.0.0: on every address the machine has, so from anywhere.127.0.0.1: only on the loopback, so only from the machine itself.
[::] and [::1] are the same two for IPv6.
PostgreSQL listens where listen_addresses in its config says. The # makes the line a comment, so PostgreSQL uses its default, localhost:
learner@db:~$ grep listen_addresses /etc/postgresql/16/main/postgresql.conf
#listen_addresses = 'localhost' # what IP address(es) to listen on;To take connections from other machines, delete the # and set it to '*', every address:
listen_addresses = '*'Edit the file as root with sudo nano, then restart PostgreSQL. (To log in from web, a real database also needs web in pg_hba.conf, its list of who may connect. This lab only checks the port.)
Objectives
- Where does PostgreSQL listen?
- Let web connect to the database.