Management of Port in Firewalld


This page is about the management of port within firewalld


Ports can be named:

If the service is not known, you can add the port manually.

Example of service definition:

cat /usr/lib/firewalld/services/http.xml
<?xml version="1.0" encoding="utf-8"?>
  <short>WWW (HTTP)</short>
  <description>HTTP is the protocol used to serve Web pages. If you plan to make your Web server publicly available, enable this option. This option is not required for viewing pages locally or developing Web pages.</description>
  <port protocol="tcp" port="80"/>

How to

Add a port

With the Shell firewall cmd

firewall-cmd --zone=public --add-port=5000/tcp --permanent
firewall-cmd --reload

With Ansible - Ansible command line

- name: "Open the web console port"
  become: yes
    port: 8443/tcp
    permanent: yes
    state: enabled
  notify: firewalld reload
  • Handler to restart ie firewall-cmd –reload
- name: "firewalld reload"
    state: restarted
    name: firewalld

List Port

firewall-cmd --zone=public --list-ports

Remove Port

firewall-cmd --zone=public --remove-port=22/tcp --permanent

then reload

Discover More

Cheatsheet on the usage of Firewalld
Firewalld - Policy

A policy applies a set of rules to traffic flowing between zones. The policy affects traffic in a stateful unidirectional manner, e.g. from: an ingress zone: zoneA to an egress zone: zoneB. ...
Firewalld - Zone

A zone is a grouping of rule configurations known as zone option. A firewall zone is defined for: a connection, an interface or source address binding (range of source addresses) This is a one-to-many...
What are Firewalld Services?

Services are pre-configured firewall properties for known services. It's a naming functionality where you can use them in place of a port (ie number and protocol, udp-tcp) In the conf directory...
What are Rich Rules or Rules in Firewalld?

Rich rule is a line of text that: begins with rule defines a list of options and terminates by an action: accept reject drop mark If a packet matches the options of the rich rule, the...

Share this page:
Follow us:
Task Runner