How can we replace iptables with firewalld in ubuntu 16.04?

To switch do the following:

  1. Stop iptables if in use:

    sudo systemctl stop iptables
    
  2. Make sure iptables are not used by your system anymore:

    sudo systemctl mask iptables
    
  3. Check its status:

    sudo systemctl status iptables
    
  4. Remove UFW if installed:

    sudo apt-get remove ufw
    

Firewalld - Dynamic Firewall Manager

This replaces iptable as the preferred way to manage your firewall. Commands to use with firewalld includes:

  1. Install firewalld:

    sudo apt install firewalld
    
  2. Check its status:

    sudo systemctl status firewalld
    
  3. Enable or disable firewalld:

    sudo systemctl [enable | disable ] firewalld
    
  4. Starting and stoping it:

    sudo systemctl [ start | stop ] firewalld
    

So to use it is simply to enable it as in steps 2, then use the man pages to get more information.

See here for more information on how to use firewalld