Linux Labs

Server security / Stage 1 of 10

Auditing listening services

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 7 · on a machine · 5 min

The server through an outsider's eyes

What you will learn

  • Take an inventory of the services listening on network addresses with sudo ss -tlnp and decide who needs each one.
  • Close a service to the network by binding it to 127.0.0.1 and check that from another machine.
  • Close ports with an nftables filter that denies everything not allowed, and keep it for the next boot.

The shop server goes on the internet soon. From outside it should show two entrances: SSH for the administrator and the site on port 80. Look at the server the way anyone on the network will see it.

The outside machine here is a network namespace, lab-outside, with the address 192.0.2.20; to it the server is 192.0.2.1. Its commands start with sudo ip netns exec lab-outside. The port scanner nmap tries to connect to the thousand most common ports and prints the open ones.

Exercise · look

Scan the server from outside

From the outside machine, scan the server 192.0.2.1, then request the page on its port 8080.

First, predict

Only SSH (22) and the site (80) should be visible from outside. Which open ports will the scanner find?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

The scanner found 5432 and 8080 open, and the admin panel gave its page to the outside machine. What do you know for sure from this?

  • nmap only tries to connect. On 5432 and 8080 the server answered, and on the other 996 ports it refused: closed.

  • There are no rules on the server: sudo nft list ruleset prints nothing. The ports are open because programs listen on them.

  • An open port means connections are accepted. Logging in to the database still goes through the password and pg_hba.conf, and the scanner only connected and left.

Programs listen on ports 5432 and 8080, and they accept connections from the network.

Ubuntu 24.04
Loading…