Firewalld

Short information about firewalld

Firewalld

By default available on RHEL:

  • All incoming TCP and UDP connections will be blocked (except the ones allowed)
  • A few services are enabled by default:
    • ssh (port 22)
    • dhcpv6-client (udp port 546)
    • IPv6 is enabled by default
    • Certain ICMP requests are blocked to prevent common network attacks
  • We can have a look at the current configuration of firewalld:
    • firewall-cmd –state
    • firewall-cmd –list-all

Ubuntu: How to install firewalld

  • First we should ensure that ufw (“uncomplicated firewall”) is disabled:
    • ufw disable
  • We need to install firewalld:
    • apt update
    • apt install firewalld
  • After this, we should enable the firewalld:
    • systemctl enable –now firewalld
    • systemctl status firewalld
  • We can confirm this with the following command:
    • firewall-cmd –state
    • firewall-cmd –list-all

Services in firewalld:

  • Instead of specifying the port (or multiple ports) manually, we can just enable a service
  • This allows us to more easily understand what our firewall is doing
  • List all available services:
    • firewall-cmd –get-services
  • Get info for a service:
    • firewall-cmd –info-service=http
    • also all services are defined as .xml files shipped as part of firewalld:
    • we can have a look into the following folders:
      • /usr/lib/firewalld/services
      • /etc/firewalld/services
    • But we should not edit those .xml files directly. Use help for more details:
      • firewall-cmd –help
      • firewall-cmd –service=http –add-port=8080/tcp –permanent

Open the firewall

  • Temporarily (until next reboot):
    • firewall-cmd –add-service=[service-name]
    • firewall-cmd –add-port[port]/[protocol]
    • Example:
      • firewall-cmd –add-service http
      • firewall-cmd –add-port 80/tcp
  • Permanentl change:
    • firewall-cmd –permanent –add-service=[service-name]
    • firewall-cmd –permanent –add-port=[port]/[protocol]
    • Follow up with a reload to updat the running configuration:
      • firewall-cmd –reload

Closing ports for a service:

  • Temporarily (until reboot):
    • firewall-cmd –remove-service=[service-name]
    • firewall-cmd –remove-port=[port]/[protocol]
    • Example
      • firewall-cmd –remove-service=http
      • firewall-cmd –remove-port=80/tcp
  • Permanently:
    • firewall-cmd –permanent –remove-service=[service-name]
    • firewall-cmd –permanent –remove-port=[port]/[protocol]

What are zones in firewalld?

  • A zone defines the level of trust for network connections o interfaces
  • Network interfaces are assigned to a specific zone
  • Through those zones, we can give them a certain level of trust
  • An interface can only be in one zone at a time
  • But a zone could be used by multiple interfaces
  • Examples:
    • We are on a laptop, and want to have different firewall rules for Ethernet and WiFi
    • We are a sever with 2 network cards, one public, and one for our internal network. We might want to have different firewall rules then

Build-in zones in firewalld

  • Zone Levels:
    • forewalld provides several predefined zones, ranging from the most trusted (trusted) to the least trusted (drop)
    • Examples are: trusted, home, work, public, drop
    • We can list the zones with the following command:
      • firewall-cmd –get-zones
    • To list the rules of a zone, we can just add –zone:
      • firewall-cmd –zone=work –list-all
    • The zones are configured through the following folders:
      • /usr/lib/firewalld/zones/
      • /etc/firewalld/zones
  • By default, we are usually in the public zone:
    • firewall-cmd –get-default-zone
    • But we can change it:
      • firewall-cmd –set-default-zone=work

Changing the rules for a specific zone

  • All the ways to enable / disable a port / service can also specify the zone
    • If we do not specify the zone parameter, it will use the default zone
    • Temporarily (until next reboot):
      • firewall-cmd –zone=[zone] –add-service=[service-name]
      • firewall-cmd –zone=[zone] –add-port=[port]/[protocol]
    • Permanently:
      • firewall-cmd –zone=[zone] –permanent –add-service=[service-name]
      • firewall-cmd –zone=[zone] –permanent –add-port=[port]/[protocol]
      • Follow up with a reload to updat the running configuration:
        • firewall-cmd –reload
  • Assign an interface to a zone:
    • Temporarily (until next reboot):
      • firewall-cmd –zone=zone_name –change-interfce=[interface]
      • Example:
        • firewall-cmd –zone=public –change-interface=enp0s5
    • Permanently:
      • firewall-cmd –permanent –zone=zone_name –change-interfce=[interface]
      • We might need to reload the current configuration after:
        • firewall-cmd –reload

Outlook: firewalld

  • We only had a quick look at firewalld
  • Firewalld could do way more:
    • We can block outgoing connections and filter those as well (with additional rules)
    • Masquerading and NAT support:
      • We can use firewalld to create our own router and define NAT forwarding rules
    • We can forward a port to another port (even on another machine)
    • We can assign IP ranges to rules and allow access to a specified port only to certain IPs /IP ranges
    • for more details study commandL
      • firewall-cmd –help