Other Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\nBasic Operation of Firewalld in Linux<\/h2>\n\n\n\n
In Linux, firewalling is implemented using a kernel subsystem called netfilter<\/strong> which allows kernel modules to inspect network traffic and allow or block them based on set rules.<\/p>\n\n\n\nFirewall daemon, firewalld<\/strong>, as well as iptables<\/strong> service are used to configure netfilter although firewalld<\/strong> is the default service in the latest versions of RHEL\/CentOS while iptables<\/strong> was default for the earlier versions.<\/p>\n\n\n\nHowever, it is not a good practise to use them both at the same time. As such;<\/p>\n\n\n\n
\n- To use firewalld, disable iptables service using either of the following commands;<\/li>\n<\/ul>\n\n\n\n
systemctl mask iptables<\/code><\/pre>\n\n\n\nsystemctl stop iptables<\/code><\/pre>\n\n\n\nfor i in iptables ip6tables ebtables; do systemctl mask $i; done<\/code><\/pre>\n\n\n\n\n- To use iptables instead, disable firewalld service;<\/li>\n<\/ul>\n\n\n\n
systemctl mask firewalld;systemctl stop firewalld<\/code><\/pre>\n\n\n\n\n- The major difference between the two services is that firewalld<\/strong> is dynamic i.e changes made to its configuration file are implemented immediately and only differences are applied to the file without recreating rules. Firewalld also applies the changes without interrupting the existing connections. iptables service<\/strong> on the other hand flushes the old rules and creates new ones in case changes are made to the configuration file thus interrupting the existing network connections.<\/li>\n\n\n\n
- Firewalld has default<\/strong> configuration files in \/usr\/lib\/firewalld<\/strong> directory and user\/system<\/strong> configuration files in \/etc\/firewalld<\/strong> directory. Default configuration files should not be changed and in case there is a need to make some changes, it is advisable to copy the respective file from respective directory in the default configuration directory to corresponding directory in the system configuration directory and make appropriate changes.<\/li>\n\n\n\n
- Firewalld uses zones<\/strong> (collections of rules applied to incoming network traffic that matches specific source address or network interface)<\/em> to define a level of trust on a network connection. It supports IPsets, Ethernet bridges, IPv4, IPv6 firewall settings.<\/li>\n\n\n\n
- Firewalld also uses DBus<\/strong> interface to allow applications to requests certain ports be opened enabling them to directly create or remove firewall rules without intervention of an Administrator.<\/li>\n<\/ul>\n\n\n\n
Firewalld Zones<\/h3>\n\n\n\n
Some of the firewalld zones are described below.<\/p>\n\n\n\n
\n- trusted<\/strong> \u2013 a zone in which all network connections are accepted.<\/li>\n\n\n\n
- home<\/strong> \u2013 Used in home networks where computers on the same network are trusted. Only selected incoming connections are accepted.<\/li>\n\n\n\n
- work<\/strong> \u2013 used on work networks where most computers on the same networks are trusted.. Only selected incoming connections are accepted.<\/li>\n\n\n\n
- dmz<\/strong> \u2013 This is a demilitarized zone<\/em>, computers in this zone are publicly-accessible but they have limited access to your internal network. Only selected incoming connections are accepted.<\/li>\n\n\n\n
- drop<\/strong> \u2013 In this zone, any incoming network packets are dropped and no reply is sent to the source. Only outgoing network connections are allowed.<\/li>\n\n\n\n
- external<\/strong> \u2013 used mostly in external networks for routers where other computers on the network are not trusted. Only selected incoming connections are accepted.<\/li>\n\n\n\n
- internal<\/strong> \u2013 Used in internal networks. Most computers in the same network are trusted and only selected incoming connections are accepted.<\/li>\n\n\n\n
- public<\/strong> \u2013 Used in public networks. Other computers in the network are not trusted. Only selected connections are accepted. This is the default zone for all newly created network interfaces.<\/li>\n\n\n\n
- block<\/strong> \u2013 rejects incoming connection with an icmp-host-prohibited<\/em> message for IPv4 and\/or icmp6-adm-prohibited<\/em> for IPv6. Only connections initiated within the system are allowed.<\/li>\n<\/ul>\n\n\n\n
When configuring firewall features, two configuration tools can be used:<\/p>\n\n\n\n
\n- Command-line tool; firewall-cmd<\/strong><\/li>\n\n\n\n
- Graphical tool; firewall-config<\/strong><\/li>\n<\/ul>\n\n\n\n
Commonly used firewall-cmd options;<\/h3>\n\n\n\n\n- General Options\n
\n--help, --h<\/code><\/strong> \u2013 display help text<\/li>\n\n\n\n--version, --V<\/code><\/strong> \u2013 Get version information<\/li>\n<\/ul>\n<\/li>\n\n\n\n- Status Options\n
\n--state<\/code><\/strong> \u2013 check the status of the firewalld<\/li>\n\n\n\n--reload<\/code><\/strong> \u2013 To reload on-disk configuration without interrupting user connections<\/li>\n\n\n\n--complete-reload<\/code><\/strong> \u2013 Reload firewall and interrupt user connections<\/li>\n\n\n\n--runtime-to-permanent<\/code><\/strong> \u2013 Create permanent configuration from runtime configuration<\/li>\n<\/ul>\n<\/li>\n\n\n\n- Permanent Options\n
\n--permanent<\/code><\/strong> \u2013 Set an option permanently.<\/li>\n<\/ul>\n<\/li>\n\n\n\n- Zone Options\n
\n--get-default-zone<\/code><\/strong> \u2013 Print default zone for connections and interfaces<\/li>\n\n\n\n--set-default-zone=<\/strong><zone<\/strong>><\/code> \u2013 Set default zone<\/li>\n\n\n\n--get-active-zones<\/code><\/strong> \u2013 list currently active zones<\/li>\n\n\n\n--get-zones<\/code><\/strong> \u2013 Lists all available zones<\/li>\n\n\n\n--get-services<\/code><\/strong> \u2013Show all available services.<\/li>\n\n\n\n--add-service=<\/strong><service-name<\/strong>> [--zone=<<\/strong>zone>]<\/strong><\/code> \u2013 Adds a service to the current default zone or the specified zone.<\/li>\n\n\n\n--get-icmptypes<\/code><\/strong> \u2013 list predefined icmptypes<\/li>\n\n\n\n--get-zone-of-interface=<\/strong><interface<\/strong>><\/code> \u2013Display the name of the zone the interface is bound to<\/li>\n\n\n\n--get-zone-of-source=<\/strong><source<\/strong>>[\/<mask<\/strong>>] | <MAC<\/strong>> | ipset<\/strong>:<ipset<\/strong>><\/code> \u2013 displays the name of the zone the source is bound to<\/li>\n\n\n\n--list-all [\u2013zone=<\/strong><ZONE<\/strong>>]<\/code> \u2013 Lists all configurations in a zone.<\/li>\n\n\n\n--list-all-zones<\/strong> <\/code>\u2013 List everything added for or enabled in all zones<\/li>\n\n\n\n--new-zone=<zone><\/code><\/strong> Add a new zone<\/li>\n\n\n\n--new-zone-from-file=<\/strong><filename<\/strong>> [--name=<\/strong><zone<\/strong>>]<\/code> \u2013 Add a new zone from file with an optional name<\/li>\n\n\n\n--delete-zone=<\/strong><zone<\/strong>><\/code> Delete an existing zone<\/li>\n<\/ul>\n<\/li>\n\n\n\n- Service Options\n
\n--new-service=<\/strong><service<\/strong>><\/code> \u2013 Add a new service<\/li>\n\n\n\n--new-service-from-file=<\/strong><filename<\/strong>> [--name=<\/strong><service<\/strong>>]<\/code> \u2013 Add a new service from file with optional name<\/li>\n\n\n\n--delete-service=<\/strong><service<\/strong>><\/code> \u2013 Delete an existing service<\/li>\n\n\n\n--load-service-defaults=<\/strong><service<\/strong>><\/code> \u2013 load icmptype default settings<\/li>\n<\/ul>\n<\/li>\n\n\n\n- IcmpType Options\n
\n--new-icmptype=<\/strong><icmptype<\/strong>><\/code> \u2013 Add a new icmptype<\/li>\n\n\n\n--new-icmptype-from-file=<\/strong><filename<\/strong>> [--name=<\/strong><icmptype<\/strong>>]<\/code> \u2013 Add a new icmptype from file with optional name<\/li>\n\n\n\n--delete-icmptype=<\/strong><icmptype<\/strong>><\/code> \u2013 Delete an existing icmptype<\/li>\n<\/ul>\n<\/li>\n\n\n\n- Interfaces Options\n
\n--list-interfaces<\/code><\/strong> \u2013 list interfaces that are bound to a zone<\/li>\n\n\n\n--add-interface=<\/strong><interface<\/strong>><\/code> \u2013 binds the interface to a zone<\/li>\n\n\n\n--change-interface=<\/strong><interface<\/strong>><\/code> \u2013 Change zone the interface is bound to<\/li>\n\n\n\n--remove-interface=<\/strong><interface<\/strong>><\/code> \u2013 Removes an interface from a zone<\/li>\n<\/ul>\n<\/li>\n\n\n\n- Sources Options\n
\n--list-sources<\/code><\/strong> \u2013 list sources bound to a zone<\/li>\n\n\n\n--add-source=<\/strong><source<\/strong>>[\/<mask<\/strong>>] | <MAC<\/strong>> | ipset:<\/strong><ipset<\/strong>><\/code> \u2013 binds a source to a zone<\/li>\n\n\n\n--remove-source=<\/strong><source<\/strong>>[\/<mask<\/strong>>] | <MAC<\/strong>> | ipset:<\/strong><ipset<\/strong>><\/code> \u2013 removes a source from a zone<\/li>\n<\/ul>\n<\/li>\n\n\n\n- Port options\n