SlideShare a Scribd company logo
1 of 15
Download to read offline
1
CONFIGURATION FIREWALL-CMD ON CENTOS 8
Introduction
“firewalld” is firewall management software available for many Linux distributions, which acts as
a frontend for Linux’s in-kernel nftables or iptables packet filtering systems.
In this guide, we will show you how to set up a firewalld firewall for our CentOS 8 server, and cover the
basics of managing the firewall with the firewall-cmd administrative tool.
To complete this tutorial, we will need a server running CentOS 8.
 InstallingandEnablingfirewalld
firewalld is installed by default on some Linux distributions, including many images of CentOS 8.
However, it may be necessary for you to install firewalld yourself:
 sudo dnf install firewalld
After you install firewalld, you can enable the service and reboot your server. Keep in mind that
enabling firewalld will cause the service to start up at boot. It is best practice to create your firewall rules
and take the opportunity to test them before configuring this behavior in order to avoid potential issues.
 sudo systemctl enable firewalld
 sudo systemctl start firewalld
 sudo systemctl status firewalld
2
When the server restarts, your firewall should be brought up, your network interfaces should be
put into the zones you configured (or fall back to the configured default zone), and any rules associated
with the zone(s) will be applied to the associated interfaces.
We can verify that the service is running and reachable by typing:
 sudo firewall-cmd –state (Output  running)
This indicates that our firewall is up and running with the default configuration
 FirewallRules
ExploringtheDefaults
We can see which zone is currently selected as the default by typing:
 firewall-cmd --get-default-zone (Output  public)
Since we haven’t given firewalld any commands to deviate from the default zone, and none of our
interfaces are configured to bind to another zone, that zone will also be the only active zone (the zone
that is controlling the traffic for our interfaces). We can verify that by typing:
 firewall-cmd --get-active-zones (Output  public; interface:ens160)
Here, we can see that our example server has one network interface being controlled by the
firewall (ens160). It is currently being managed according to the rules defined for the public zone.
How do we know what rules are associated with the public zone though? We can print out the default
zone’s configuration by typing:
3
 sudo firewall-cmd --list-all (Output  public (active);[other parameters})
We can tell from the output that this zone is both the default and active, and that
the ens160 interface is associated with this zone (we already knew all of this from our previous inquiries).
However, we can also see that this zone allows traffic for a DHCP client (for IP address assignment), SSH
(for remote administration), and Cockpit (a web-based console).
ExploringAlternativeZones
Now we have a good idea about the configuration for the default and active zone. We can find
out information about other zones as well.
To get a list of the available zones, type:
 firewall-cmd --get-zones (Output  block dmz drop external home internal public trusted work)
4
We can see the specific configuration associated with a zone by including the --zone= parameter
in our --list-all command:
 firewall-cmd --zone=home --list-all (Output  home; other parameters)
Next we will learn about assiging zones to network interfaces.
 SelectingZones foryour Interfaces
Unless you have configured your network interfaces otherwise, each interface will be put in the
default zone when the firewall is started.
Changingthe Zoneof anInterface
You can move an interface between zones during a session by using the --zone= parameter in
combination with the --change-interface= parameter. As with all commands that modify the firewall, you
will need to use sudo. We can move our ens160 interface to the home zone by typing this:
 firewall-cmd --zone=home --change-interface=ens160 (Output  Success)
5
Note: Whenever you are moving an interface to a new zone, be aware that you are probably
modifying which services will be operational. For instance, here we are moving to the home zone, which
has SSH available. This means that our connection shouldn’t drop. Some other zones do not have SSH
enabled by default, and switching to these zones could cause your connection to drop, preventing you
from logging back into your server. We can verify that this was successful by asking for active zones again:
 firewall-cmd --get-active-zones (Output  home; interfaces:ens160)
 Adjustingthe Default Zone
If all of your interfaces can be handled well by a single zone, it’s probably easiest to just designate
the best zone as default and then use that for your configuration.
You can change the default zone with the --set-default-zone= parameter. This will immediately
change any interface using the default zone:
 firewall-cmd --set-default-zone=home (Output  Success)
 SettingRules for Your Applications
Let’s run through the basic way of defining firewall exceptions for the services you wish to make
available.
Adding a Servicetoyour Zones
The most straight forward method is to add the services or ports you need to the zones you are
using. You can get a list of the available service definitions with the --get-services option:
 firewall-cmd --get-services
6
Output
RH-Satellite-6 amanda-client amanda-k5-client amqp amqps apcupsd audit bacula bacula-client
bb bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc bittorrent-lsd ceph ceph-mon cfengine
cockpit condor-collector ctdb dhcp dhcpv6 dhcpv6-client distcc dns dns-over-tls docker-registry docker-
swarm dropbox-lansync elasticsearch etcd-client etcd-server finger freeipa-4 freeipa-ldap freeipa-ldaps
freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git grafana gre high-availability http
https imap imaps ipp ipp-client ipsec irc ircs iscsi-target isns jenkins kadmin kdeconnect kerberos kibana
klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls lightning-network llmnr managesieve matrix mdns
memcache minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nfs nfs3 nmea-
0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy
pmwebapi pmwebapis pop3 pop3s postgresql privoxy prometheus proxy-dhcp ptp pulseaudio
puppetmaster quassel radius rdp redis redis-sentinel rpc-bind rsh rsyncd rtsp salt-master samba samba-
client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptrap spideroak-lansync spotify-
sync squid ssdp ssh steam-streaming svdrp svn syncthing syncthing-gui synergy syslog syslog-tls telnet
tentacle tftp tftp-client tile38 tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-http
wbem-https wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-
server
Note: You can get more details about each of these services by looking at their associated .xml file
within the /usr/lib/firewalld/services directory. For instance, the SSH service is defined like this:
 cat /usr/lib/firewalld/services/ssh.xml
Output
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>SSH</short>
<description>Secure Shell (SSH) is a protocol for logging into and executing commands on remote
machines. It provides secure encrypted communications. If you plan on accessing your machine remotely
via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for
this option to be useful.</description>
<port protocol="tcp" port="22"/>
</service>
7
You can enable a service for a zone using the --add-service= parameter. The operation will target
the default zone or whatever zone is specified by the --zone= parameter. By default, this will only adjust
the current firewall session. You can adjust the permanent firewall configuration by including the --
permanent flag.
For instance, if we are running a web server serving conventional HTTP traffic, we can temporarily
allow this traffic for interfaces in our public zone by typing:
 firewall-cmd --zone=public --add-service=http (Output  Success)
You can leave out the --zone= flag if you wish to modify the default zone. We can verify the
operation was successful by using the --list-all or --list-services operations:
 firewall-cmd --zone=public --list-services (Output  cockpit dhcpv6-client http ssh)
Once you have tested that everything is working as it should, you will probably want to modify
the permanent firewall rules so that your service will still be available after a reboot. We can make our
previous change permanent by retyping it and adding the --permanent flag:
 firewall-cmd --zone=public --add-service=http –permenant (Output  Success)
Whichever method you chose, you can verify that it was successful by adding the --
permanent flag to the --list-services operation. You need to use sudo for any --permanent operations:
 sudo firewall-cmd --zone=public --list-services –permanent (Output  cockpit dhcpv6-client http ssh)
8
Your public zone will now allow HTTP web traffic on port 80. If your web server is configured to
use SSL/TLS, you’ll also want to add the https service. We can add that to the current session and the
permanent rule-set by typing:
 sudo firewall-cmd --zone=public --add-service=https –permanent (Output  Success)
 What If No Appropriate Service Is Available?
The services that are included with the firewalld installation represent many of the most common
applications that you may wish to allow access to. However, there will likely be scenarios where these
services do not fit your requirements.
In this situation, you have two options.
Opening aPort for your Zones
The easiest way to add support for your specific application is to open up the ports that it uses in
the appropriate zone(s). This is done by specifying the port or port range, and the associated protocol
(TCP or UDP) for the ports.
For instance, if our application runs on port 5000 and uses TCP, we could temporarily add this to
the public zone using the --add-port= parameter. Protocols can be designated as either tcp or udp:
 firewall-cmd --zone=public --add-port=5000/tcp (Output  Success)
We can verify that this was successful using the --list-ports operation:
 firewall-cmd --zone=public --list-ports (Output  5000/tcp)
It is also possible to specify a sequential range of ports by separating the beginning and ending
port in the range with a dash. For instance, if our application uses UDP ports 4990 to 4999, we could open
these up on public by typing:
 firewall-cmd --zone=public --add-port=4990-4999/udp (Output  Success)
9
After testing, we would likely want to add these to the permanent firewall.
 sudo firewall-cmd --zone=public --add-port=5000/tcp --permanent (Output  Success)
 sudo firewall-cmd --zone=public --add-port=4990-4999/udp --permanent (Output  Success)
 sudo firewall-cmd --zone=public --list-ports --permanent (Output  5000/tcp 4990-4999/udp)
Defining a Service
Opening ports for your zones is a straightforward solution, but it can be difficult to keep track of
what each one is for. If you ever decommission a service on your server, you may have a hard time
remembering which ports that have been opened are still required. To avoid this situation, it is possible
to define a new service.
Services are collections of ports with an associated name and description. Using services is easier
to administer than ports, but requires a bit of up-front work. The easiest way to start is to copy an existing
script (found in /usr/lib/firewalld/services) to the /etc/firewalld/services directory where the firewall
looks for non-standard definitions. We could copy the SSH service definition to use for
our kaantest service definition like this. The filename minus the .xml suffix will dictate the name of the
service within the firewall services list:
 sudo cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/kaantest.xml
To start, the file will contain the SSH definition that you copied:
/etc/firewalld/services/kaantest.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>SSH</short>
<description>Secure Shell (SSH) is a protocol for logging into and executing commands on remote
machines. It provides secure encrypted communications. If you plan on accessing your machine remotely
via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for
this option to be useful.</description>
<port protocol="tcp" port="22"/>
</service>
10
The majority of this definition is actually metadata. You will want to change the short name for
the service within the <short> tags. This is a human-readable name for your service. You should also add
a description so that you have more information if you ever need to audit the service. The only
configuration you need to make that actually affects the functionality of the service will likely be the port
definition where you identify the port number and protocol you wish to open. Multiple <port/> tags can
be specified.
For our kaantest service, imagine that we need to open up port 5000 for TCP and 4500 for UDP.
We can modify the existing definition with something like this:
/etc/firewalld/services/kaantest.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>SSHKaanTest</short>
<description>This is just an example service. It probably shouldn't be used on a real
system.</description>
<port protocol="tcp" port="5000"/>
<port protocol="udp" port="4500"/>
</service>
- Save and close the file.
- Reload your firewall to get access to your new service:
 sudo firewall-cmd –reload (Output  Success)
11
You can see that it is now among the list of available services:
 firewall-cmd --get-services (Output  Services | kaantest)
Output
RH-Satellite-6 amanda-client amanda-k5-client amqp amqps apcupsd audit bacula bacula-client bb bgp
bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc bittorrent-lsd ceph ceph-mon cfengine cockpit
condor-collector ctdb dhcp dhcpv6 dhcpv6-client distcc dns dns-over-tls docker-registry docker-swarm
dropbox-lansync elasticsearch etcd-client etcd-server finger freeipa-4 freeipa-ldap freeipa-ldaps freeipa-
replication freeipa-trust ftp ganglia-client ganglia-master git grafana gre high-availability http https imap
imaps ipp ipp-client ipsec irc ircs iscsi-target isns Jenkins kaantest kadmin kdeconnect kerberos kibana
klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls lightning-network llmnr managesieve matrix mdns
memcache minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nfs nfs3 nmea-
0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy
pmwebapi pmwebapis pop3 pop3s postgresql privoxy prometheus proxy-dhcp ptp pulseaudio
puppetmaster quassel radius rdp redis redis-sentinel rpc-bind rsh rsyncd rtsp salt-master samba samba-
client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptrap spideroak-lansync spotify-
sync squid ssdp ssh steam-streaming svdrp svn syncthing syncthing-gui synergy syslog syslog-tls telnet
tentacle tftp tftp-client tile38 tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-http
wbem-https wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-
server
You can now use this service in your zones as you normally would.
12
 CreatingYour OwnZones
While the predefined zones will probably be more than enough for most users, it can be helpful to
define your own zones that are more descriptive of their function.
For instance, you might want to create a zone for your web server, called “publickaan”. However, you
might want to have another zone configured for the DNS service you provide on your private network.
You might want a zone called “privatekaan” for that.
When adding a zone, you must add it to the permanent firewall configuration. You can then reload to
bring the configuration into your running session. For instance, we could create the two zones we
discussed above by typing:
 sudo firewall-cmd --permanent --new-zone=publickaan (Output  Success)
 sudo firewall-cmd --permanent --new-zone=privatekaan (Output  Success)
You can verify that these are present in your permanent configuration by typing:
 sudo firewall-cmd --permanent --get-zones (Output  Zones | privatekaan & publickaan)
As stated before, these won’t be available in the runtime firewall yet:
 firewall-cmd --get-zones (Output  Zones without privatekaan & publickaan)
Reload the firewall to bring these new zones into the active runtime configuration:
 sudo firewall-cmd –reload
 firewall-cmd --get-zones
13
Now, you can begin assigning the appropriate services and ports to your zones. It’s usually a good
idea to adjust the runtime firewall and then save those changes to the permanent configuration after
testing. For instance, for the publickaan zone, you might want to add the SSH, HTTP, and HTTPS services:
 sudo firewall-cmd --zone= publickaan --add-service=ssh
 sudo firewall-cmd --zone= publickaan --add-service=http
 sudo firewall-cmd --zone= publickaan --add-service=https
 sudo firewall-cmd --zone= publickaan --list-all
Likewise, we can add the DNS service to our privatekaan zone:
 sudo firewall-cmd --zone= privatekaan --add-service=dns
 sudo firewall-cmd --zone= privatekaan --list-all
14
We could then change our interfaces over to these new zones to test them out:
 sudo firewall-cmd --zone=publickaan --change-interface=virbr0
 sudo firewall-cmd --zone=privatekaan --change-interface=ens160
At this point, you have the opportunity to test your configuration. If these values work for you,
you will want to add these rules to the permanent configuration. You could do that by running all the
commands again with the --permanent flag appended, but in this case we’ll use the --runtime-to-
permanent flag to save our entire runtime configuration permanently:
 sudo firewall-cmd --runtime-to-permanent (Output  Success)
After permanently applying these rules, reload the firewall to test that the changes remain:
 sudo firewall-cmd –reload (Output  Success)
Validate that the correct zones were assigned:
 firewall-cmd --get-active-zones (Output  Success; Success)
15
And validate that the appropriate services are available for both of the zones:
 sudo firewall-cmd --zone=publickaan --list-services (Output  http, https, ssh)
 sudo firewall-cmd --zone=privatekaan --list-services (Output  dns)
You have successfully set up your own zones! If you want to make one of these zones the default
for other interfaces, remember to configure that behavior with the --set-default-zone= parameter:
 sudo firewall-cmd --set-default-zone=privatekaan (Output  Success)
1/18/2022
X
Kaan Aslandag
Signed by: www.kaan1.com

More Related Content

What's hot

Basic security &amp; info
Basic security &amp; infoBasic security &amp; info
Basic security &amp; infoTola LENG
 
How To Configure VNC Server on CentOS 7
How To Configure VNC Server on CentOS 7How To Configure VNC Server on CentOS 7
How To Configure VNC Server on CentOS 7VCP Muthukrishna
 
TFTP Installation Configuration Guide
TFTP Installation Configuration GuideTFTP Installation Configuration Guide
TFTP Installation Configuration GuideVCP Muthukrishna
 
How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7VCP Muthukrishna
 
How to shutdown the Netapp SAN 8.3 and 9.2 version
How to shutdown the Netapp SAN 8.3 and 9.2 versionHow to shutdown the Netapp SAN 8.3 and 9.2 version
How to shutdown the Netapp SAN 8.3 and 9.2 versionSaroj Sahu
 
Free radius billing server with practical vpn exmaple
Free radius billing server with practical vpn exmapleFree radius billing server with practical vpn exmaple
Free radius billing server with practical vpn exmapleChanaka Lasantha
 
Cisco vs. huawei CLI Commands
Cisco vs. huawei CLI CommandsCisco vs. huawei CLI Commands
Cisco vs. huawei CLI CommandsBootcamp SCL
 
Building a moat bastion server
Building a moat   bastion serverBuilding a moat   bastion server
Building a moat bastion servernseemiller
 
How to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS ShareHow to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS ShareVCP Muthukrishna
 
Ftp configuration in rhel7
Ftp configuration in rhel7Ftp configuration in rhel7
Ftp configuration in rhel7Balamurugan M
 
How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7VCP Muthukrishna
 
Stacki: Automate with Spreadsheets (Tutorial)
Stacki: Automate with Spreadsheets (Tutorial)Stacki: Automate with Spreadsheets (Tutorial)
Stacki: Automate with Spreadsheets (Tutorial)StackIQ
 
Ubuntu server wireless access point (eng)
Ubuntu server wireless access point (eng)Ubuntu server wireless access point (eng)
Ubuntu server wireless access point (eng)Anatoliy Okhotnikov
 
How To Install and Configure Salt Master on Ubuntu
How To Install and Configure Salt Master on UbuntuHow To Install and Configure Salt Master on Ubuntu
How To Install and Configure Salt Master on UbuntuVCP Muthukrishna
 
Configuration of Smtp Server On CentOS 8
Configuration of Smtp Server On CentOS 8Configuration of Smtp Server On CentOS 8
Configuration of Smtp Server On CentOS 8Kaan Aslandağ
 
LSOF Command Usage on RHEL 7
LSOF Command Usage on RHEL 7LSOF Command Usage on RHEL 7
LSOF Command Usage on RHEL 7VCP Muthukrishna
 
Comandos cisco x huawei
Comandos cisco x huaweiComandos cisco x huawei
Comandos cisco x huaweiandre gomes
 

What's hot (20)

Basic security &amp; info
Basic security &amp; infoBasic security &amp; info
Basic security &amp; info
 
How To Configure VNC Server on CentOS 7
How To Configure VNC Server on CentOS 7How To Configure VNC Server on CentOS 7
How To Configure VNC Server on CentOS 7
 
Dhcp
DhcpDhcp
Dhcp
 
Kickstart
KickstartKickstart
Kickstart
 
TFTP Installation Configuration Guide
TFTP Installation Configuration GuideTFTP Installation Configuration Guide
TFTP Installation Configuration Guide
 
How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7
 
How to shutdown the Netapp SAN 8.3 and 9.2 version
How to shutdown the Netapp SAN 8.3 and 9.2 versionHow to shutdown the Netapp SAN 8.3 and 9.2 version
How to shutdown the Netapp SAN 8.3 and 9.2 version
 
Free radius billing server with practical vpn exmaple
Free radius billing server with practical vpn exmapleFree radius billing server with practical vpn exmaple
Free radius billing server with practical vpn exmaple
 
Cisco vs. huawei CLI Commands
Cisco vs. huawei CLI CommandsCisco vs. huawei CLI Commands
Cisco vs. huawei CLI Commands
 
Building a moat bastion server
Building a moat   bastion serverBuilding a moat   bastion server
Building a moat bastion server
 
How to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS ShareHow to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS Share
 
Ftp configuration in rhel7
Ftp configuration in rhel7Ftp configuration in rhel7
Ftp configuration in rhel7
 
How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7
 
mail server
mail servermail server
mail server
 
Stacki: Automate with Spreadsheets (Tutorial)
Stacki: Automate with Spreadsheets (Tutorial)Stacki: Automate with Spreadsheets (Tutorial)
Stacki: Automate with Spreadsheets (Tutorial)
 
Ubuntu server wireless access point (eng)
Ubuntu server wireless access point (eng)Ubuntu server wireless access point (eng)
Ubuntu server wireless access point (eng)
 
How To Install and Configure Salt Master on Ubuntu
How To Install and Configure Salt Master on UbuntuHow To Install and Configure Salt Master on Ubuntu
How To Install and Configure Salt Master on Ubuntu
 
Configuration of Smtp Server On CentOS 8
Configuration of Smtp Server On CentOS 8Configuration of Smtp Server On CentOS 8
Configuration of Smtp Server On CentOS 8
 
LSOF Command Usage on RHEL 7
LSOF Command Usage on RHEL 7LSOF Command Usage on RHEL 7
LSOF Command Usage on RHEL 7
 
Comandos cisco x huawei
Comandos cisco x huaweiComandos cisco x huawei
Comandos cisco x huawei
 

Similar to Configuration Firewalld On CentOS 8

Nat mikrotik
Nat mikrotikNat mikrotik
Nat mikrotiklouisraj
 
Firewalld : A New Interface to Your Netfilter Stack
Firewalld : A New Interface to Your Netfilter StackFirewalld : A New Interface to Your Netfilter Stack
Firewalld : A New Interface to Your Netfilter StackMahmoud Shiri Varamini
 
INFA 620Laboratory 4 Configuring a FirewallIn this exercise.docx
INFA 620Laboratory 4 Configuring a FirewallIn this exercise.docxINFA 620Laboratory 4 Configuring a FirewallIn this exercise.docx
INFA 620Laboratory 4 Configuring a FirewallIn this exercise.docxcarliotwaycave
 
Important cisco-chow-commands
Important cisco-chow-commandsImportant cisco-chow-commands
Important cisco-chow-commandsssusere31b5c
 
Linux internet server security and configuration tutorial
Linux internet server security and configuration tutorialLinux internet server security and configuration tutorial
Linux internet server security and configuration tutorialannik147
 
Lamp Server With Drupal Installation
Lamp Server With Drupal InstallationLamp Server With Drupal Installation
Lamp Server With Drupal Installationfranbow
 
Ansible automation tool with modules
Ansible automation tool with modulesAnsible automation tool with modules
Ansible automation tool with modulesmohamedmoharam
 
FreeBSD, ipfw and OpenVPN 2.1 server
FreeBSD, ipfw and OpenVPN 2.1 serverFreeBSD, ipfw and OpenVPN 2.1 server
FreeBSD, ipfw and OpenVPN 2.1 serverTomaz Muraus
 
Router Commands Overview
Router Commands OverviewRouter Commands Overview
Router Commands OverviewMuhammed Niyas
 
Basic Cisco ASA 5506-x Configuration (Firepower)
Basic Cisco ASA 5506-x Configuration (Firepower)Basic Cisco ASA 5506-x Configuration (Firepower)
Basic Cisco ASA 5506-x Configuration (Firepower)NetProtocol Xpert
 
How To Install and Configure SNMP on RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7How To Install and Configure SNMP on RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7VCP Muthukrishna
 
Installation And Configuration Of DNS, Web And FTP Servers On Virtual Machine...
Installation And Configuration Of DNS, Web And FTP Servers On Virtual Machine...Installation And Configuration Of DNS, Web And FTP Servers On Virtual Machine...
Installation And Configuration Of DNS, Web And FTP Servers On Virtual Machine...JohnWilson47710
 
PandoraFMS: Free Monitoring System
PandoraFMS: Free Monitoring SystemPandoraFMS: Free Monitoring System
PandoraFMS: Free Monitoring SystemEnrique Verdes
 
Install websphere message broker 8 RHEL 6 64 bits
Install websphere message broker 8 RHEL 6 64 bitsInstall websphere message broker 8 RHEL 6 64 bits
Install websphere message broker 8 RHEL 6 64 bitsManuel Vega
 
Creating a firewall in UBUNTU
Creating a firewall in UBUNTUCreating a firewall in UBUNTU
Creating a firewall in UBUNTUMumbai University
 

Similar to Configuration Firewalld On CentOS 8 (20)

Firewalld
FirewalldFirewalld
Firewalld
 
Nat mikrotik
Nat mikrotikNat mikrotik
Nat mikrotik
 
Firewalld : A New Interface to Your Netfilter Stack
Firewalld : A New Interface to Your Netfilter StackFirewalld : A New Interface to Your Netfilter Stack
Firewalld : A New Interface to Your Netfilter Stack
 
INFA 620Laboratory 4 Configuring a FirewallIn this exercise.docx
INFA 620Laboratory 4 Configuring a FirewallIn this exercise.docxINFA 620Laboratory 4 Configuring a FirewallIn this exercise.docx
INFA 620Laboratory 4 Configuring a FirewallIn this exercise.docx
 
Important cisco-chow-commands
Important cisco-chow-commandsImportant cisco-chow-commands
Important cisco-chow-commands
 
Linux internet server security and configuration tutorial
Linux internet server security and configuration tutorialLinux internet server security and configuration tutorial
Linux internet server security and configuration tutorial
 
Lamp Server With Drupal Installation
Lamp Server With Drupal InstallationLamp Server With Drupal Installation
Lamp Server With Drupal Installation
 
Aruba OS 7.3 Command Line Interface Reference Guide
Aruba OS 7.3 Command Line Interface Reference GuideAruba OS 7.3 Command Line Interface Reference Guide
Aruba OS 7.3 Command Line Interface Reference Guide
 
Ansible automation tool with modules
Ansible automation tool with modulesAnsible automation tool with modules
Ansible automation tool with modules
 
FreeBSD, ipfw and OpenVPN 2.1 server
FreeBSD, ipfw and OpenVPN 2.1 serverFreeBSD, ipfw and OpenVPN 2.1 server
FreeBSD, ipfw and OpenVPN 2.1 server
 
Linux
LinuxLinux
Linux
 
Router Commands Overview
Router Commands OverviewRouter Commands Overview
Router Commands Overview
 
Basic Cisco ASA 5506-x Configuration (Firepower)
Basic Cisco ASA 5506-x Configuration (Firepower)Basic Cisco ASA 5506-x Configuration (Firepower)
Basic Cisco ASA 5506-x Configuration (Firepower)
 
How To Install and Configure SNMP on RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7How To Install and Configure SNMP on RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7
 
Aruba OS 6.4 Command Line Interface Reference Guide
Aruba OS 6.4 Command Line Interface Reference GuideAruba OS 6.4 Command Line Interface Reference Guide
Aruba OS 6.4 Command Line Interface Reference Guide
 
Linuxserver harden
Linuxserver hardenLinuxserver harden
Linuxserver harden
 
Installation And Configuration Of DNS, Web And FTP Servers On Virtual Machine...
Installation And Configuration Of DNS, Web And FTP Servers On Virtual Machine...Installation And Configuration Of DNS, Web And FTP Servers On Virtual Machine...
Installation And Configuration Of DNS, Web And FTP Servers On Virtual Machine...
 
PandoraFMS: Free Monitoring System
PandoraFMS: Free Monitoring SystemPandoraFMS: Free Monitoring System
PandoraFMS: Free Monitoring System
 
Install websphere message broker 8 RHEL 6 64 bits
Install websphere message broker 8 RHEL 6 64 bitsInstall websphere message broker 8 RHEL 6 64 bits
Install websphere message broker 8 RHEL 6 64 bits
 
Creating a firewall in UBUNTU
Creating a firewall in UBUNTUCreating a firewall in UBUNTU
Creating a firewall in UBUNTU
 

Recently uploaded

Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 

Recently uploaded (20)

Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 

Configuration Firewalld On CentOS 8

  • 1. 1 CONFIGURATION FIREWALL-CMD ON CENTOS 8 Introduction “firewalld” is firewall management software available for many Linux distributions, which acts as a frontend for Linux’s in-kernel nftables or iptables packet filtering systems. In this guide, we will show you how to set up a firewalld firewall for our CentOS 8 server, and cover the basics of managing the firewall with the firewall-cmd administrative tool. To complete this tutorial, we will need a server running CentOS 8.  InstallingandEnablingfirewalld firewalld is installed by default on some Linux distributions, including many images of CentOS 8. However, it may be necessary for you to install firewalld yourself:  sudo dnf install firewalld After you install firewalld, you can enable the service and reboot your server. Keep in mind that enabling firewalld will cause the service to start up at boot. It is best practice to create your firewall rules and take the opportunity to test them before configuring this behavior in order to avoid potential issues.  sudo systemctl enable firewalld  sudo systemctl start firewalld  sudo systemctl status firewalld
  • 2. 2 When the server restarts, your firewall should be brought up, your network interfaces should be put into the zones you configured (or fall back to the configured default zone), and any rules associated with the zone(s) will be applied to the associated interfaces. We can verify that the service is running and reachable by typing:  sudo firewall-cmd –state (Output  running) This indicates that our firewall is up and running with the default configuration  FirewallRules ExploringtheDefaults We can see which zone is currently selected as the default by typing:  firewall-cmd --get-default-zone (Output  public) Since we haven’t given firewalld any commands to deviate from the default zone, and none of our interfaces are configured to bind to another zone, that zone will also be the only active zone (the zone that is controlling the traffic for our interfaces). We can verify that by typing:  firewall-cmd --get-active-zones (Output  public; interface:ens160) Here, we can see that our example server has one network interface being controlled by the firewall (ens160). It is currently being managed according to the rules defined for the public zone. How do we know what rules are associated with the public zone though? We can print out the default zone’s configuration by typing:
  • 3. 3  sudo firewall-cmd --list-all (Output  public (active);[other parameters}) We can tell from the output that this zone is both the default and active, and that the ens160 interface is associated with this zone (we already knew all of this from our previous inquiries). However, we can also see that this zone allows traffic for a DHCP client (for IP address assignment), SSH (for remote administration), and Cockpit (a web-based console). ExploringAlternativeZones Now we have a good idea about the configuration for the default and active zone. We can find out information about other zones as well. To get a list of the available zones, type:  firewall-cmd --get-zones (Output  block dmz drop external home internal public trusted work)
  • 4. 4 We can see the specific configuration associated with a zone by including the --zone= parameter in our --list-all command:  firewall-cmd --zone=home --list-all (Output  home; other parameters) Next we will learn about assiging zones to network interfaces.  SelectingZones foryour Interfaces Unless you have configured your network interfaces otherwise, each interface will be put in the default zone when the firewall is started. Changingthe Zoneof anInterface You can move an interface between zones during a session by using the --zone= parameter in combination with the --change-interface= parameter. As with all commands that modify the firewall, you will need to use sudo. We can move our ens160 interface to the home zone by typing this:  firewall-cmd --zone=home --change-interface=ens160 (Output  Success)
  • 5. 5 Note: Whenever you are moving an interface to a new zone, be aware that you are probably modifying which services will be operational. For instance, here we are moving to the home zone, which has SSH available. This means that our connection shouldn’t drop. Some other zones do not have SSH enabled by default, and switching to these zones could cause your connection to drop, preventing you from logging back into your server. We can verify that this was successful by asking for active zones again:  firewall-cmd --get-active-zones (Output  home; interfaces:ens160)  Adjustingthe Default Zone If all of your interfaces can be handled well by a single zone, it’s probably easiest to just designate the best zone as default and then use that for your configuration. You can change the default zone with the --set-default-zone= parameter. This will immediately change any interface using the default zone:  firewall-cmd --set-default-zone=home (Output  Success)  SettingRules for Your Applications Let’s run through the basic way of defining firewall exceptions for the services you wish to make available. Adding a Servicetoyour Zones The most straight forward method is to add the services or ports you need to the zones you are using. You can get a list of the available service definitions with the --get-services option:  firewall-cmd --get-services
  • 6. 6 Output RH-Satellite-6 amanda-client amanda-k5-client amqp amqps apcupsd audit bacula bacula-client bb bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc bittorrent-lsd ceph ceph-mon cfengine cockpit condor-collector ctdb dhcp dhcpv6 dhcpv6-client distcc dns dns-over-tls docker-registry docker- swarm dropbox-lansync elasticsearch etcd-client etcd-server finger freeipa-4 freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git grafana gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target isns jenkins kadmin kdeconnect kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls lightning-network llmnr managesieve matrix mdns memcache minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nfs nfs3 nmea- 0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy prometheus proxy-dhcp ptp pulseaudio puppetmaster quassel radius rdp redis redis-sentinel rpc-bind rsh rsyncd rtsp salt-master samba samba- client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptrap spideroak-lansync spotify- sync squid ssdp ssh steam-streaming svdrp svn syncthing syncthing-gui synergy syslog syslog-tls telnet tentacle tftp tftp-client tile38 tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-http wbem-https wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix- server Note: You can get more details about each of these services by looking at their associated .xml file within the /usr/lib/firewalld/services directory. For instance, the SSH service is defined like this:  cat /usr/lib/firewalld/services/ssh.xml Output <?xml version="1.0" encoding="utf-8"?> <service> <short>SSH</short> <description>Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful.</description> <port protocol="tcp" port="22"/> </service>
  • 7. 7 You can enable a service for a zone using the --add-service= parameter. The operation will target the default zone or whatever zone is specified by the --zone= parameter. By default, this will only adjust the current firewall session. You can adjust the permanent firewall configuration by including the -- permanent flag. For instance, if we are running a web server serving conventional HTTP traffic, we can temporarily allow this traffic for interfaces in our public zone by typing:  firewall-cmd --zone=public --add-service=http (Output  Success) You can leave out the --zone= flag if you wish to modify the default zone. We can verify the operation was successful by using the --list-all or --list-services operations:  firewall-cmd --zone=public --list-services (Output  cockpit dhcpv6-client http ssh) Once you have tested that everything is working as it should, you will probably want to modify the permanent firewall rules so that your service will still be available after a reboot. We can make our previous change permanent by retyping it and adding the --permanent flag:  firewall-cmd --zone=public --add-service=http –permenant (Output  Success) Whichever method you chose, you can verify that it was successful by adding the -- permanent flag to the --list-services operation. You need to use sudo for any --permanent operations:  sudo firewall-cmd --zone=public --list-services –permanent (Output  cockpit dhcpv6-client http ssh)
  • 8. 8 Your public zone will now allow HTTP web traffic on port 80. If your web server is configured to use SSL/TLS, you’ll also want to add the https service. We can add that to the current session and the permanent rule-set by typing:  sudo firewall-cmd --zone=public --add-service=https –permanent (Output  Success)  What If No Appropriate Service Is Available? The services that are included with the firewalld installation represent many of the most common applications that you may wish to allow access to. However, there will likely be scenarios where these services do not fit your requirements. In this situation, you have two options. Opening aPort for your Zones The easiest way to add support for your specific application is to open up the ports that it uses in the appropriate zone(s). This is done by specifying the port or port range, and the associated protocol (TCP or UDP) for the ports. For instance, if our application runs on port 5000 and uses TCP, we could temporarily add this to the public zone using the --add-port= parameter. Protocols can be designated as either tcp or udp:  firewall-cmd --zone=public --add-port=5000/tcp (Output  Success) We can verify that this was successful using the --list-ports operation:  firewall-cmd --zone=public --list-ports (Output  5000/tcp) It is also possible to specify a sequential range of ports by separating the beginning and ending port in the range with a dash. For instance, if our application uses UDP ports 4990 to 4999, we could open these up on public by typing:  firewall-cmd --zone=public --add-port=4990-4999/udp (Output  Success)
  • 9. 9 After testing, we would likely want to add these to the permanent firewall.  sudo firewall-cmd --zone=public --add-port=5000/tcp --permanent (Output  Success)  sudo firewall-cmd --zone=public --add-port=4990-4999/udp --permanent (Output  Success)  sudo firewall-cmd --zone=public --list-ports --permanent (Output  5000/tcp 4990-4999/udp) Defining a Service Opening ports for your zones is a straightforward solution, but it can be difficult to keep track of what each one is for. If you ever decommission a service on your server, you may have a hard time remembering which ports that have been opened are still required. To avoid this situation, it is possible to define a new service. Services are collections of ports with an associated name and description. Using services is easier to administer than ports, but requires a bit of up-front work. The easiest way to start is to copy an existing script (found in /usr/lib/firewalld/services) to the /etc/firewalld/services directory where the firewall looks for non-standard definitions. We could copy the SSH service definition to use for our kaantest service definition like this. The filename minus the .xml suffix will dictate the name of the service within the firewall services list:  sudo cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/kaantest.xml To start, the file will contain the SSH definition that you copied: /etc/firewalld/services/kaantest.xml <?xml version="1.0" encoding="utf-8"?> <service> <short>SSH</short> <description>Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful.</description> <port protocol="tcp" port="22"/> </service>
  • 10. 10 The majority of this definition is actually metadata. You will want to change the short name for the service within the <short> tags. This is a human-readable name for your service. You should also add a description so that you have more information if you ever need to audit the service. The only configuration you need to make that actually affects the functionality of the service will likely be the port definition where you identify the port number and protocol you wish to open. Multiple <port/> tags can be specified. For our kaantest service, imagine that we need to open up port 5000 for TCP and 4500 for UDP. We can modify the existing definition with something like this: /etc/firewalld/services/kaantest.xml <?xml version="1.0" encoding="utf-8"?> <service> <short>SSHKaanTest</short> <description>This is just an example service. It probably shouldn't be used on a real system.</description> <port protocol="tcp" port="5000"/> <port protocol="udp" port="4500"/> </service> - Save and close the file. - Reload your firewall to get access to your new service:  sudo firewall-cmd –reload (Output  Success)
  • 11. 11 You can see that it is now among the list of available services:  firewall-cmd --get-services (Output  Services | kaantest) Output RH-Satellite-6 amanda-client amanda-k5-client amqp amqps apcupsd audit bacula bacula-client bb bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc bittorrent-lsd ceph ceph-mon cfengine cockpit condor-collector ctdb dhcp dhcpv6 dhcpv6-client distcc dns dns-over-tls docker-registry docker-swarm dropbox-lansync elasticsearch etcd-client etcd-server finger freeipa-4 freeipa-ldap freeipa-ldaps freeipa- replication freeipa-trust ftp ganglia-client ganglia-master git grafana gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target isns Jenkins kaantest kadmin kdeconnect kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls lightning-network llmnr managesieve matrix mdns memcache minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nfs nfs3 nmea- 0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy prometheus proxy-dhcp ptp pulseaudio puppetmaster quassel radius rdp redis redis-sentinel rpc-bind rsh rsyncd rtsp salt-master samba samba- client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptrap spideroak-lansync spotify- sync squid ssdp ssh steam-streaming svdrp svn syncthing syncthing-gui synergy syslog syslog-tls telnet tentacle tftp tftp-client tile38 tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-http wbem-https wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix- server You can now use this service in your zones as you normally would.
  • 12. 12  CreatingYour OwnZones While the predefined zones will probably be more than enough for most users, it can be helpful to define your own zones that are more descriptive of their function. For instance, you might want to create a zone for your web server, called “publickaan”. However, you might want to have another zone configured for the DNS service you provide on your private network. You might want a zone called “privatekaan” for that. When adding a zone, you must add it to the permanent firewall configuration. You can then reload to bring the configuration into your running session. For instance, we could create the two zones we discussed above by typing:  sudo firewall-cmd --permanent --new-zone=publickaan (Output  Success)  sudo firewall-cmd --permanent --new-zone=privatekaan (Output  Success) You can verify that these are present in your permanent configuration by typing:  sudo firewall-cmd --permanent --get-zones (Output  Zones | privatekaan & publickaan) As stated before, these won’t be available in the runtime firewall yet:  firewall-cmd --get-zones (Output  Zones without privatekaan & publickaan) Reload the firewall to bring these new zones into the active runtime configuration:  sudo firewall-cmd –reload  firewall-cmd --get-zones
  • 13. 13 Now, you can begin assigning the appropriate services and ports to your zones. It’s usually a good idea to adjust the runtime firewall and then save those changes to the permanent configuration after testing. For instance, for the publickaan zone, you might want to add the SSH, HTTP, and HTTPS services:  sudo firewall-cmd --zone= publickaan --add-service=ssh  sudo firewall-cmd --zone= publickaan --add-service=http  sudo firewall-cmd --zone= publickaan --add-service=https  sudo firewall-cmd --zone= publickaan --list-all Likewise, we can add the DNS service to our privatekaan zone:  sudo firewall-cmd --zone= privatekaan --add-service=dns  sudo firewall-cmd --zone= privatekaan --list-all
  • 14. 14 We could then change our interfaces over to these new zones to test them out:  sudo firewall-cmd --zone=publickaan --change-interface=virbr0  sudo firewall-cmd --zone=privatekaan --change-interface=ens160 At this point, you have the opportunity to test your configuration. If these values work for you, you will want to add these rules to the permanent configuration. You could do that by running all the commands again with the --permanent flag appended, but in this case we’ll use the --runtime-to- permanent flag to save our entire runtime configuration permanently:  sudo firewall-cmd --runtime-to-permanent (Output  Success) After permanently applying these rules, reload the firewall to test that the changes remain:  sudo firewall-cmd –reload (Output  Success) Validate that the correct zones were assigned:  firewall-cmd --get-active-zones (Output  Success; Success)
  • 15. 15 And validate that the appropriate services are available for both of the zones:  sudo firewall-cmd --zone=publickaan --list-services (Output  http, https, ssh)  sudo firewall-cmd --zone=privatekaan --list-services (Output  dns) You have successfully set up your own zones! If you want to make one of these zones the default for other interfaces, remember to configure that behavior with the --set-default-zone= parameter:  sudo firewall-cmd --set-default-zone=privatekaan (Output  Success) 1/18/2022 X Kaan Aslandag Signed by: www.kaan1.com