When a service is retired, the change ticket usually gets closed as soon as someone stops the daemon and disables the unit. Verifying port closure after a service is retired is a separate job. Teams skip it more often than any other step in decommissioning, and it is how forgotten listeners stay reachable for months. This article covers how to confirm a port is really gone from the outside, what the scan results mean, and where the usual checks miss things.
Sysadmins and security engineers who handle retirements gain one main thing here: evidence. A closure you have checked from the outside is something you can show an auditor, hand over to a colleague and rely on six months from now. “I stopped it” is only a statement.
Why Stopping a Service Is Not the Same as Closing a Port
A port is reachable only when two things are true: something on the host is listening, and every network layer between the internet and that host lets the traffic through. Stopping the service removes one listener. It does nothing to the other layers, and it doesn’t stop a different process from taking over the socket.
Socket activation is a classic trap. On systemd hosts, stopping foo.service while foo.socket is still enabled leaves systemd holding the port open. The next incoming connection starts the service again. Since Ubuntu 22.10, OpenSSH runs through ssh.socket by default, so admins who move SSH to a new port and stop the old service are sometimes surprised to find the old port still answering. CUPS behaves the same way with cups.socket.
Containers cause a second gap. Docker writes its own iptables rules in the DOCKER chain, and those rules skip UFW’s filtering completely. If a container was published with -p 8080:8080 and the container was removed but the compose file still exists, the next docker compose up on that host puts the port back on the internet. UFW will still claim it is denied.
The Myth: “Filtered” Means the Job Is Done
Many people believe that once nmap stops reporting a port as open, it is closed. That is not quite true. The three states (open, closed and filtered) mean different things, and the difference matters when you sign off a retirement. If the distinctions are unclear, read the guide on open, closed and filtered port states before relying on scan output.
Closed means the host answered with a TCP RST, so nothing is listening but the packet reached the host. Filtered means no reply came back, usually because a firewall dropped the packet. A filtered result after retirement tells you that a firewall currently blocks the port. It tells you nothing about whether the service is still running behind that firewall. If someone loosens a security group rule next quarter, the listener you thought was gone is exposed again.
An experienced penetration tester treats “filtered” as half an answer. Both layers have to be checked.
Step-by-Step Port Closure Verification
A good verification takes 15-30 minutes per service and follows the same order every time:
1. Confirm on the host. Run ss -tulpn (or netstat -anob on Windows) and check that nothing is bound to the port on 0.0.0.0, on [::], or on any specific interface address. Then run systemctl list-sockets to find socket units, and docker ps -a together with docker network inspect to find published ports that are left over.
2. Remove the activation path. Disable and mask both the .service and .socket units. Delete the package if nothing depends on it. If the binary is still on disk, someone can start it again during a later troubleshooting session.
3. Scan from outside, over both protocols. From a network outside your perimeter, run nmap -sS -p <port> and, for UDP services such as SNMP on 161 or NTP on 123, nmap -sU. Without root privileges nmap falls back to a connect scan, which is fine for TCP. UDP results need patience, because “open|filtered” is the normal ambiguous answer.
4. Scan every address family and every path. Check the IPv4 address, the IPv6 address, any Elastic IP or floating IP, and any load balancer or NAT rule that forwards to the host. An AWS NLB listener that still points at an empty target group is harmless today. It is not harmless once a new instance joins that target group.
5. Record the result and rescan later. Save the scan output with a timestamp, then scan again 7 and 30 days later. Configuration management such as Ansible, Puppet or Chef often puts retired services back on the next run if the role was never updated.
The full lifecycle beyond a single port, including DNS records, certificates and IP release, is covered in the guide to decommissioning old servers without leaving ports open.
A Scenario That Plays Out Regularly
A team retires a self-hosted Grafana instance on port 3000 after moving to a managed service. The engineer stops the container, confirms the dashboard no longer loads in a browser, and closes the ticket. Three weeks later a routine external scan finds port 3000 open again, running an older Grafana build with known authentication issues.
The cause was simple. A nightly Ansible playbook still had the grafana role in the host’s inventory group, and it rebuilt the container from a pinned image tag. The browser test had worked because the engineer was on the corporate VPN, where split DNS sent the hostname to a different internal address. There were two separate mistakes, and an external scan from a neutral vantage point would have caught both on day one.
Common Mistakes When Confirming Port Closure
Testing from inside the network. A scan from a bastion host or office LAN goes through different firewall rules than internet traffic does. Internal results confirm internal reachability and nothing else. The method for checking perimeter rules from the outside is covered in validating firewall rules with external port scans.
Checking only IPv4. Plenty of hosts have a carefully maintained iptables ruleset and an empty ip6tables ruleset. If the service bound to [::], it stayed reachable over IPv6 the whole time, and nobody scanned that address.
Trusting the change record over the network. A closed ticket documents what someone meant to do. Only a scan shows what actually happened. Teams that link retirement tickets to an attached external scan result rarely find zombie services later.
Edge Cases Where the Standard Advice Changes
Air-gapped and strictly on-prem environments have no meaningful “external” view, so verification there means scanning from every network segment that could reach the host, such as OT, guest Wi-Fi and the management VLAN. In PCI DSS scope, retiring a service inside the cardholder data environment should also trigger an update to the network diagram and the documented list of allowed ports. Requirement 1 expects both to match reality.
Shared hosting and some managed platforms are the opposite case. You may not control the firewall at all, so an external scan is the only evidence you can produce. For small teams with fewer than 10 servers, a scheduled scan with stored history replaces most of the manual steps above without much extra work.
FAQ
How long after retiring a service should I keep scanning the old port?
At least 30 days, covering at least one full configuration management cycle and one patch window. After that, regular continuous monitoring of the host should pick up any regression.
Is a “closed” result better than “filtered” for a retired port?
Neither result is better by default. “Closed” proves nothing is listening, and “filtered” proves a firewall is blocking the port. The strongest result is no listener on the host plus a filtered or closed port seen from outside.
Do I need to verify UDP ports separately?
Yes. TCP scans never touch UDP listeners, and services such as SNMP, NTP, DNS and memcached run over UDP. Run a dedicated UDP scan against any UDP port the retired service used.
Summary
A retirement isn’t finished until the port has been checked from both the host and an external vantage point, over IPv4 and IPv6, and checked again weeks later. Stopping the process removes one listener. Socket units, container rules, forwarding paths and automation can each bring it back. Keep the timestamped scan output with the change ticket. That record lets a reviewer confirm the port is really closed.
