How do you list all open ports in CentOS?
Learn how to list all open ports in CentOS using various commands such as netstat, ss, and nmap in this comprehensive guide.
To list all open ports in CentOS, you can use the `firewall-cmd` command if you're using firewalld, or you can use `iptables` commands if you're managing the firewall rules directly. Here are the steps for both methods:
### Using `firewall-cmd`
1. **List all open ports**:
sudo firewall-cmd --list-ports
This command will display a list of all currently open ports.
2. **List all open services (which might include port information)**:
sudo firewall-cmd --list-services
This command will show all services that are allowed through the firewall, which can indirectly indicate open ports.
3. **Get detailed information about a specific zone**:
sudo firewall-cmd --zone=public --list-all
Replace `public` with the appropriate zone name if you have multiple zones configured.
### Using `iptables`
If you're using iptables directly instead of firewalld, you can list the open ports with the following command:
1. **List all rules and find open ports**:
sudo iptables -L -n -v
This command will display detailed information about all iptables rules, including open ports.
### Using `ss` or `netstat`
You can also use `ss` or `netstat` to list open ports and their associated services:
1. **Using `ss`**:
sudo ss -tuln
This command shows all listening TCP and UDP ports.
2. **Using `netstat`**:
sudo netstat -tuln
Similar to `ss`, this command lists all listening ports.
These commands will help you determine which ports are open and actively listening for connections on your CentOS system.
What's Your Reaction?