How to Configure Lsof -i Port

Published
Length
3 min read

Luis Felipe Dias

All posts

An lsof i port check finds which running apps use specific network sockets on your machine. You set it up safely by granting read rights only to trusted host roles. Linux and Unix systems treat almost everything as a file. This includes network sockets, pipes, and hardware devices. When a server app fails to start, another process often holds its network port. System admins run open file checks to link a network port to a process ID. This guide explains how port checks work and how to manage ho

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

An lsof i port check finds which running apps use specific network sockets on your machine. You set it up safely by granting read rights only to trusted host roles.

Linux and Unix systems treat almost everything as a file. This includes network sockets, pipes, and hardware devices. When a server app fails to start, another process often holds its network port. System admins run open file checks to link a network port to a process ID. This guide explains how port checks work and how to manage host access safely.

How an lsof i port setup works

The list open files tool reads kernel memory to find active network tasks. When you run an lsof i port check, the tool filters results by network address. You can look up all open sockets or name one port number. You can also filter by protocol, like TCP or UDP.

This setup affects both human users and automated scripts on the host. A standard user account only sees processes that the same user owns. If a web server runs under a system role, a regular user gets blank output. This happens because the kernel hides socket details owned by other accounts.

To see every socket on the machine, the user needs elevated root rights. Many teams set up sudo rules so operators can run socket checks safely. A safe default grants the user permission to run only the socket check tool. You should never grant full root shell rights just to inspect network ports.

How to narrow down network socket results

Busy servers often hold thousands of open files and active network sockets at once. Running a broad check on these hosts can slow down the terminal output. It can also trigger reverse DNS lookups for every remote IP address in the list. Those network lookups add delay when a server has a broken DNS setup.

Operators tell the tool to skip host name and port name lookups. Showing raw numbers makes the output load much faster during an outage. You can also filter the list by connection state, such as listening or established. Checking only listening ports helps you find which local services wait for incoming traffic.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Once you find the process ID holding a port, check its parent service. Stopping a process by hand often fails if a service manager restarts it right away. Instead, use the system service tool to stop or restart the app cleanly.

Checking logs and host security limits

Giving engineers host login rights to check ports creates real security risks. Static sudo rules let users see command line text for other running apps. Sometimes those process records show sensitive data or internal network paths. Host logs might record that a user ran a port check on a server. Still, standard system logs rarely capture the terminal output shown to that user.

Once an engineer logs in over SSH, static host rules leave wide gaps. A user who can stop a stuck port might also touch live database processes. Teams must audit who logs in, what commands they run, and when access ends. Relying on shared SSH keys makes it hard to tie actions to one person. Teams need clear audit trails and tight role checks for every server session.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Why does my port check return no output?

You likely ran the check as a standard user without root rights. The system hides network sockets owned by other users unless you manage your role.

How can I speed up a slow network port check?

Tell the tool to skip reverse DNS and service name lookups. Printing raw IP addresses and port numbers stops the tool from waiting on network queries.

Does checking an open port interrupt running traffic?

No, listing open files and network sockets is a read-only kernel check. It reads current process states without dropping packets or stopping active network sessions.

The query runs. The emails stay hidden.