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.

ONET 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, ONET 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

Hướng dẫn cấu hình nhận Real-IP từ người dùng truy cập vào trang web thông qua Nginx

Trong bài trước, mình đã hướng dẫn các bạn cách cài đặt sử dụng Nginx làm reverse proxy cho WordPress...
30/12/2020

Install Anaconda Python on Ubuntu

Anaconda is a distribution of the Python programming language, which is used by data scientists all over the world. Anaconda...
12/02/2020

How to Install and Configure OpenSUSE JeOS

OpenSUSE JeOS is an extremely slimmed-down version of normal openSUSE Tumbleweed/Leap. It’s available as images for multiple...
29/12/2020
Bài Viết

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

Huớng dẫn dùng proxy cho ios, iphone 2023
23/09/2023

Cách gắn set proxy cho điện thoại android, oppo, giả lập android, Ldplayer Bằng Proxydroid
20/09/2023

Mua Proxy Socks5 VN Chơi Game Gia Lập Tăng Cường Trải Nghiệm Chơi Game
22/06/2023

Mua Proxy Mỹ, Us Nuôi Tài Khoản Etsy, eBay Tìm Hiểu Về Mua Proxy Mỹ tại Onet.com.vn
22/06/2023

Mua Proxy Game – Giải pháp tuyệt vời cho việc chơi game trên mạng mà không bị giới hạn về vị trí địa lý
03/06/2023