How to Start/Stop and Enable/Disable FirewallD and Iptables Firewall in Linux

[‘

n

Firewall is a software that acts as a shield between user’s system and external network allowing some packets to pass while discarding other’s. Firewall commonly operates on network layer i.e. on IP packets both Ipv4 and Ipv6.

n

Whether a packet will pass or will be bocked, depends on the rules against such type of packets in the firewall. These rules can be built-in or user-defined ones. Each packet which enters the network has to pass through this shield which verifies it against rules defined in it for such type of packets.

n

Each rule has a target action which is to be applied in case the packet fails to satisfy it. On Linux systems, firewall as a service is provided by many softwares, most common which are: firewalld and iptables.

n

In Linux there are many different types of firewalls used, but most standard ones are Iptables and Firewalld, which is going to discuss in this article.

n

What is FirewallD

n

FirewallD is the Dynamic Firewall Manager of Linux systems. This service is used to configure the network connections, thus deciding which external network or internal packets to allow traversing the network and which to block.

n

It allows two types of configurations, permanent and runtime. Runtime configurations will get lost ones the service is restarted while the permanent ones get retained across the system boot so that they are followed every time the service gets active.

n

Corresponding to these configurations, firewallD has two directories, default/fallback one (/usr/lib/firewall) which is lost ones system is updated and the system configuration (/etc/firewall) which remains permanent and overrides the default one if given. This is found as a default service in RHEL/CentOS 7 and Fedora 18.

n

What is Iptables

n

Iptables is another service which decides to allow, drop or return IP packets. Iptables service manages Ipv4 packets while Ip6tables manages Ipv6 packets. This service manages a list of tables where each table is maintained for different purpose like: ‘filter‘ table is for firewall rules, ‘nat‘ table is consulted in case of new connection, ‘mangle‘ in case of packet alterations and so on.

n

Each table further has chains which can be built-in or user-defined where a chain signifies a set of rules which are applies to a packet, thus deciding what the target action for that packet should be i.e. it must be ALLOWED, BLOCKED or RETURNED. This service is a default service on systems like: RHEL/CentOS 6/5 and Fedora, ArchLinux, Ubuntu etc.

n

To learn more about firewalls, follow the following links:

n

    n

  1. Understanding IPtables Firewall Basics and Tips
  2. n

  3. Configure Iptables Firewall in Linux
  4. n

  5. Configure FirewallD in Linux
  6. n

  7. Useful FirewallD Rules to Manage Firewall in Linux
  8. n

  9. How to Control Network Traffic Using FirewallD and Iptables
  10. n

n

In this article we will explain how to start, stop or restart Iptables and FirewallD services in Linux.

n

How to Start/Stop and Enable/Disable FirewallD Service

n

If you’re using CentOS/RHEL 7 or Fedora 18+ versions, you should follow below instructions to manage FirewallD service.

n

Start FirewallD Service

n

# systemctl start firewalld rn

n

Stop FirewallD Service

n

# systemctl stop firewalldrn

n

Check the Status of FirewallD

n

# systemctl status firewalldrn

n

Check the State of FirewallD

n

# firewall-cmd --statern

n

As an alternative, you can disable the firewalld service so that it doesn’t apply rules to packets and enable ones needed again.

n

Disable FirewallD Service

n

# systemctl disable firewalldrn

n

Enable FirewallD Service

n

# systemctl enable firewalldrn

n

Mask FirewallD Service

n

# systemctl mask firewalldrn

n

Also, you can mask the firewall service which creates a symbolic link of the firewall.service to /dev/null, thus disabling the service.

n

Unmask FirewallD Service

n

# systemctl unmask firewalldrn

n

This is reverse of masking the service. This removes the symlink of the service created during masking, thus re-enabling the service.

n

How to Start/Stop and Enable/Disable IPtables Service

n

On RHEL/CentOS 6/5/4 and Fedora 12-18 iptables firewall comes as pre and later, the iptables service can be installed via:

n

# yum install iptables-servicesrn

n

Then, the service can be started, stopped or restarted via following commands:

n

Start Iptables Service

n

# systemctl start iptablesrnORrn# service iptables startrn

n

Stop Iptables Service

n

# systemctl stop iptablesrnORrn# service iptables stoprn

n

Disable Iptables Service

n

# systemctl disable iptablesrnOrrn# service iptables savern# service iptables stoprn

n

Enable Iptables Service

n

# systemctl enable iptablesrnOrrn# service iptables startrn

n

Check Status of Iptables Service

n

# systemctl status iptablesrnORrn# service iptables statusrn

n

On Ubuntu and some other Linux distributions however, ufw is the command which is used to manage the iptables firewall service. Ufw provides an easy interface for the user to handle the iptables firewall service.

n

Enable Ufw Iptables Firewall

n

$ sudo ufw enablern

n

Disable Ufw Iptables Firewall

n

$ sudo ufw disablern

n

Check Status of Ufw Iptables Firewall

n

# sudo ufw status rn

n

However, if you want to list chains in iptables which contains all the rules following command can help you achieve the same:

n

# iptables -L -n -vrn

n

Conclusion

n

These are the techniques which can help you start, stop, disable and enable the packet management services in Linux Based Systems. Different Linux distros can have different services as default, like: Ubuntu can have iptables as the default and pre-installed service, while CentOS can have firewalld as the default configured service for managing incoming and outgoing of IP packets.

n

Presented in this article are the most common tricks to manage these services on almost all Linux Distros, however, if you find something and would like to add on to this article, your comments are always welcome.

n

‘]