How to List Open Ports in Firewalld

28/12/2020
Chưa phân loại
Firewalld is the default firewall program on CentOS 7, Red Hat Enterprise Linux 7 (RHEL 7), Fedora 18+ and some other popular Linux distributions. It is very powerful for managing IPv4 and IPv6 networks. It has easy to use command line interface (CLI) and a great alternative to iptables.

In this article, I am going to show you how to list open ports in Firewalld. I am going to use CentOS 7.4 for the demonstration, but the same commands should work on any Linux distribution with Firewalld installed. Let’s get started.

What is an Open Port?

First let’s discuss what an open port is. It is clearly a networking term.

You can install many server software packagess on a single computer such as HTTP server, DNS server, Database Server and so on. But it may have a limited number of network interfaces on it. Let’s say it has one physical network interface available and its configured to have an IP address 10.0.1.11 and you have HTTP and MySQL database server installed on it. So when you connect to 10.0.1.11 from another computer, how does your server computer know what service you want to use? The HTTP service or the MySQL database service.

Well to differentiate between the HTTP service and MySQL database service, the IP address also has another property called port. Port is a 16-bit integer, which means it can be a number from 0 to 65536. So your server computer runs different services or server softwares on different ports. For example, the HTTP server runs on port 80, the MySQL database server runs on port 3306 and so on.

To talk to specific service on your server computer, let’s say the HTTP server, the client computer has to pass the port 80 along with the IP address 10.0.1.11. So port 80 is an open port because a client computer can talk to it.

When you have firewall program configured, by default, it blocks all the port. So even when the service is running on a specific port on your server computer, a client computer won’t be able to connect to it.

So how do I know what ports are open and I can connect to on my server computer? Well, that’s the topic of this article.

Finding Open Ports with Firewalld:

First check whether firewalld service is running with the following command:

$ sudo systemctl status firewalld

As you can see from the marked section of the screenshot below, the firewalld service is running. So we are good to go.

If your firewalld service is not running, you can start firewalld service with the following command:

$ sudo systemctl start firewalld

Now you can use the firewall-cmd command configure and get information about Firewalld.

You can print the whole Firewalld configuration with the following command:

$ sudo firewall-cmd –list-all

The open ports and services are listed in the services: and ports: line as marked in the screenshot below.

In the services: line, ssh and dhcpv6-client services are enabled. It means the ports corresponding to these services are also open.

You can find out what ports these services open with the following command:

$ grep ong>SERVICE_NAME /etc/services

NOTE: Here, SERVICE_NAME is the service you want to see the ports of.

For example, to see the ports the ssh service opened, run the following command:

$ grep ssh /etc/services

As you can see from the marked section of the screenshot below, the ssh service opens the TCP port 22 and UDP port 22.

The command sudo firewall-cmd –list-all, shows you the whole Firewalld configuration.

If you just want to see what services are allowed to have open ports, run the following command:

$ sudo firewall-cmd –list-services

The services allowed to have open ports are listed as you can see from the screenshot below.

If you want to see only the ports that are open, run the following command:

$ sudo firewall-cmd –list-ports

The open ports are listed as you can see from the screenshot below.

If you want to open other ports or services using Firewalld, then check out my other article How To Open Port 80 on CentOS7(https://linuxhint.com/open-port-80-centos7/)

That’s how you list open ports in Firewalld. Thanks for reading this article.

Sandclock IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, Sandclock IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Best Skype Alternatives for Linux

Best Skype Alternatives for Linux When it comes to VoIP (voice over IP) calling, Skype is a popular choice. But Skype for...
28/12/2020

Blind SQL Injection Techniques Tutorial

What is SQL Injection? SQL Injection is a type of database attack in which an attacker tries to steal information from...
29/12/2020

[Graylog] [LAB] [Phần 11] Cấu hình Graylog server tích hợp cảnh báo qua Slack

Chắc là mọi người đã biết đến Slack nơi tạo ra một room chat để mọi người có thể chia sẻ...
30/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Hướng dẫn chuyển đổi windows server windows evaluation to standard và active windows server 2008 + 2012 + 2016 + 2019
26/10/2021

How to Update Ubuntu Linux
24/10/2021

Squid Proxy Manager cài đặt và quản lý Proxy Squid tự động trên ubuntu
20/10/2021

Hướng dẫn cài đặt Apache CloudStack 4.15.2.0
19/10/2021

Hướng dẫn ký file PDF bằng chữ ký số (chữ ký điện tử) và sửa lỗi mới nhất 2021 foxit reader
19/10/2021