While ganeshragav and Sotsir provide correct and directly applicable approaches, it is useful to note that you can add your own services to /etc/firewalld/services
. For inspiration, look at /usr/lib/firewalld/services/
, where firewalld's predefined services are located.
The advantage of this approach is that later you will know why these ports are open, as you've described it in the service file. Also, you can now apply it to any zone without the risk of typos. Furthermore, changes to the service will not need to be applied to all zones separately, but just to the service file.
For example, you can create /etc/firewalld/services/foobar.xml
:
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>FooBar</short>
<description>
This option allows you to create FooBar connections between
your computer and mobile device. You need to have FooBar
installed on both sides for this option to be useful.
</description>
<port protocol="tcp" port="2888"/>
<port protocol="tcp" port="3888"/>
</service>
(For information about the syntax, do man firewalld.service
.)
Once this file is created, you can firewall-cmd --reload
to have it become available and then permanently add it to some zone with
firewall-cmd --permanent --zone=<zone> --add-service=foobar
followed with firewall-cmd --reload
to make it active right away.