Language & currency
Currency

Site Web gratuit & Serveur Migration

Colonel Serveur
Linux Ports - Find Open Network Ports

Understanding Open Ports in Linux

Every network service running on a Serveur Linux communicates through ports. These ports act as communication endpoints that allow applications to send and receive network traffic.

Common services use well-known ports, tel que:

Port Service
22 SSH
80 HTTP
443 HTTPS
25 SMTP
53 DNS
3306 MySQL

Knowing which ports are open is essential for:

  • Troubleshooting connectivity issues
  • Verifying service availability
  • Auditing server security
  • Identifying unnecessary exposure
  • Confirming firewall configurations

Regular port checks help administrators maintain a secure and properly functioning Linux environment.

What Is an Open Port?

An open port is a port on which a service is actively listening for incoming or outgoing network connections.

When a service starts, it binds itself to one or more ports.

Wordpress Hosting

Hébergement Web WordPress

À partir de €2.99/Mensuel

Acheter maintenant

Par exemple:

SSH Server → Port 22
Apache/Nginx → Port 80 or 443
MySQL → Port 3306

If a port is listening, applications and users may be able to connect to it depending on firewall and network policies.

Open ports are not inherently dangerous, but every exposed service increases the attack surface of a server.

TCP vs UDP Ports

When checking ports in Linux, toi’ll usually encounter two protocol types.

TCP

Transmission Control Protocol (TCP) provides reliable, connection-oriented communication.

Les exemples courants incluent:

Cheap VPS

Serveur VPS pas cher

À partir de €8/Mensuel

Acheter maintenant
  • Web traffic
  • SSH
  • Services de messagerie
  • Connexions à la base de données

UDP

User Datagram Protocol (UDP) prioritizes speed over reliability.

Les exemples courants incluent:

  • DNS
  • Streaming services
  • VoIP applications
  • Gaming services

A service may listen on:

  • TCP only
  • UDP only
  • Both protocols

Understanding the protocol helps when troubleshooting connectivity problems.

Why Check Open Ports?

Open port analysis serves multiple purposes.

Security Auditing

Unexpected services may indicate:

Windows VPS

Hébergement VPS Windows

Accès à distance et administrateur complet

Acheter maintenant
  • Mauvaise configuration
  • Forgotten applications
  • Unauthorized software
  • Potential compromise

Dépannage

Port checks help determine whether:

  • Services are running
  • Applications are listening
  • Firewall rules are working

Service Validation

Administrators can verify that newly deployed services are correctly configured and accessible.

Compliance Requirements

Many organizations regularly audit exposed services to meet internal security standards and regulatory requirements.

Using ss to Check Open Ports

Le ss utility is the preferred tool on most modern Linux distributions.

It is fast, actively maintained, and available by default on many systems.

List All Listening Ports

ss -tuln

Explanation

Option Description
-t Show TCP ports
-u Show UDP ports
-l Show listening sockets
-n Display numeric ports

Show Processes and PIDs

sudo ss -tulnp

Additional output includes:

  • Process names
  • Process IDs
  • Listening services

This command is often the fastest way to identify which applications are actively listening on your server.

Using netstat to Check Open Ports

Although considered legacy software, netstat still exists on many Linux servers.

Show Listening Ports

sudo netstat -tuln

Show Listening Ports with Processes

sudo netstat -tulnp

Check a Specific Port

Par exemple, to verify HTTPS:

sudo netstat -tulnp | grep 443

While ss is generally recommended today, many administrators still use netstat due to familiarity and compatibility with older systems.

Using lsof to Identify Processes

Le lsof utility provides detailed information about open files and network sockets.

Show Network Connections

sudo lsof -i -P -n

Show Listening Ports Only

sudo lsof -i -P -n | grep LISTEN

Check a Specific Port

Exemple:

sudo lsof -i :443

Output typically includes:

  • Process name
  • PID
  • User account
  • Port number

This makes lsof extremely useful when investigating port ownership.

Using Nmap to Scan Ports

Unlike local inspection tools, Nmap performs active network scans.

This allows administrators to see what appears open from a network perspective.

Scan Localhost

nmap localhost

Scan All TCP Ports

sudo nmap -sT -p- localhost

Scan a Remote Server

nmap server-ip-address

Nmap is particularly valuable during:

  • Security assessments
  • Firewall validation
  • Exposure testing

Because it behaves like an external client, it provides visibility into what is actually reachable.

Using Netcat (nc) for Quick Testing

Netcat provides a quick method to test individual ports.

Test a Specific Port

nc -zv localhost 443

Example Output

Connection to localhost 443 port [tcp/https] succeeded!

This approach is useful when you simply need a quick yes-or-no answer regarding connectivity.

Quick Command Reference

Goal Commande
Show listening ports ss -tuln
Show listening ports with processes sudo ss -tulnp
Legacy port listing sudo netstat -tuln
Identify process on a port sudo lsof -i :PORT
Scan localhost nmap localhost
Scan all TCP ports sudo nmap -sT -p- localhost
Test one port nc -zv localhost PORT

These commands cover most daily Linux administration tasks involving ports.

How to View All Open Ports

To see all listening TCP and UDP ports:

ss -tuln

To include process information:

sudo ss -tulnp

Alternative methods include:

sudo netstat -tulnp

et:

sudo lsof -i -P -n | grep LISTEN

Each tool presents slightly different information, but all help identify active listening services.

Understanding the Results

Finding a listening port does not automatically mean it is accessible externally.

Several factors influence reachability.

Local Listening vs External Access

A service may listen locally while remaining inaccessible from outside due to:

  • Règles de pare-feu
  • Security groups
  • Routing issues
  • Interface bindings

Localhost Bindings

Some applications listen only on:

127.0.0.1

ou:

::1

Dans ces cas, remote systems cannot connect.

IPv4 and IPv6

Services may listen on:

  • IPv4 only
  • IPv6 only
  • Both

Connectivity issues sometimes result from protocol mismatches.

Checking Firewall Rules

Open ports and firewall rules must always be evaluated together.

UFW

Check firewall status:

sudo ufw status

Firewalld

Display active firewall configuration:

sudo firewall-cmd --list-all

Firewall policies may block access even when a service is actively listening.

Dans les environnements cloud, additional controls may exist through:

  • Security groups
  • Cloud firewalls
  • Network ACLs

How to Close Unnecessary Ports

If a service is no longer required, administrators should reduce exposure.

Stop the Service

Exemple:

sudo systemctl stop service-name

Disable Automatic Startup

sudo systemctl disable service-name

Block Access Using Firewall Rules

Example with UFW:

sudo ufw deny 3306

Restrict Access to Specific IP Addresses

Instead of exposing a service publicly, allow only trusted sources.

Les exemples courants incluent:

  • Accès SSH
  • Database access
  • Administrative services

Après avoir apporté des modifications, always verify results with:

ss -tulnp

ou:

nmap

to ensure the intended policy is in effect.

Common Port Troubleshooting Scenarios

Service Is Running but Connections Fail

Possible causes:

  • Firewall blocking traffic
  • Incorrect bind address
  • Routing issues
  • Security group restrictions

Port Already in Use

Identify the process:

sudo lsof -i :PORT

ou:

sudo ss -tulnp

Application Bound Only to Localhost

Review service configuration and listen addresses.

IPv4 vs IPv6 Issues

Verify which protocol stack the service uses and whether clients match that protocol.

Best Practices for Port Management

Perform Regular Audits

Review listening services regularly.

Follow the Principle of Least Exposure

Only expose services that are necessary.

Restrict Administrative Services

Limit:

  • SSH
  • RDP
  • Bases de données
  • Panneaux de contrôle

to trusted IP addresses or VPN networks.

Review Firewall Rules Frequently

Verify that firewall policies match business requirements.

Monitor Unexpected Changes

New listening ports may indicate:

  • Installations de logiciels
  • Misconfigurations
  • Incidents de sécurité

Routine surveillance helps identify issues before they become serious problems.

Keeping Linux Servers Secure Through Port Visibility

Open ports provide valuable insight into the services running on a Linux server. Regularly reviewing listening ports helps administrators validate deployments, troubleshoot connectivity issues, identify unnecessary exposure, and strengthen overall security posture. Tools such as ss, lsof, netstat, nmap, et nc each provide different perspectives on network activity, making them valuable additions to any administrator’s toolkit.

By combining port monitoring with proper firewall management and service hardening, organizations can significantly reduce risk while maintaining reliable access to the services that matter most.

Partager cette publication

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *