How do I create a new service for firewalld from the commandline programmatically?

I cannot find an option to firewall-cmd that allows me to do this. Am I just missing it or does it actually not exist? In case of the latter, is there another option? I know that you can create a .xml service file, but I am looking for a cleaner (less error prone) way to create a service file.


According to this FedoraForum thread, it can't be done at the moment.

However, in the very same thread, this post explain a possible workaround using a python script importing firewalld bindings.

In short:

python -c "import firewall.core.io.service as ios
s=ios.Service() #Creates a service object
s.short = 'My Matlab Service' #A short description
s.name = 'matlab' #this defines the name of the xml file
s.ports = [('1234', 'tcp'), ('12345', 'udp')] #A list of ports
ios.service_writer(s, '/etc/firewalld/services')"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.