Day 04-Firewall & Iptables
Day 04-Firewall & Iptables
NETFILTER
The Linux kernel includes a powerful network filtering subsystem called
net-filter, which allows kernel modules to inspect every packet traversing the
system. This means any incoming or outgoing or forwarded network packet cab
be inspected ,modified, dropped or rejected in a programmatic way before
reaching components in user space. The programs used to interact with net-filter
are IPTABLES (service) and FIREWALLD (daemon).
Firewall
A firewall is a way to protect machines from any unwanted traffic from
outside. It enables users to control incoming network traffic on host machines
by defining a set of firewall rules. These rules are used to sort the incoming
traffic and either block it or allow through.
firewalld
firewalld is a firewall service daemon that provides a dynamic
customizable host-based firewall with a D-Bus interface. Being dynamic, it
enables creating, changing, and deleting the rules without the necessity to restart
the firewall daemon each time the rules are changed.
firewalld zones
firewalld uses the concepts of zones and services, that simplify the traffic
management. Zones are predefined sets of rules. Network interfaces and sources
can be assigned to a zone. The traffic allowed depends on the network your
computer is connected to and the security level this network is assigned.
Firewall services are predefined rules that cover all necessary settings to allow
incoming traffic for a specific service and they apply within a zone.
firewalld can be used to separate networks into different zones according
to the level of trust that the user has decided to place on the interfaces and
traffic within that network. A connection can only be part of one zone, but a
zone can be used for many network connections.
The predefined zones are stored in the /usr/lib/firewalld/zones/ directory
and can be instantly applied to any available network interface. These files are
copied to the /etc/firewalld/zones/ directory only after they are modified.
The following table describes the default settings of the predefined zones:
home: - For use at home when you mostly trust the other computers on the network.
Only selected incoming connections are accepted.
internal: - For use on internal networks when you mostly trust the other computers on the
network. Only selected incoming connections are accepted.
work: - For use at work where you mostly trust the other computers on the network.
Only selected incoming connections are accepted.
public: - For use in public areas where you do not trust other computers on the network.
Only selected incoming connections are accepted.
external: - For use on external networks with masquerading enabled, especially for
routers. You do not trust the other computers on the network to not harm your
computer. Only selected incoming connections are accepted.
dmz: - For computers in your demilitarized zone that are publicly-accessible with
limited access to your internal network. Only selected incoming connections
are accepted.
drop: - Any incoming network packets are dropped without any notification. Only
outgoing network connections are possible.
One of these zones is set as the default zone. When interface connections are
added to NetworkManager, they are assigned to the default zone. On
installation, the default zone in firewalld is set to be the public zone. The
default zone can be changed.
FirewallD configuration
To view the manual page of firewall
# man firewalld.richlanguage
To start and enable the firewalld process
# systemctl start firewalld
# systemctl enable firewalld
To modify the firewall setting in the --permanent mode, use the - -permanent
option with the firewall-cmd command.
# firewall-cmd --permanent<other option>
Options Explanations
Add a rule to the specified zone. If zone is not
– – add-rich-rule='<RULE>’
specified, the rule is set to default zone.
(OR)
(OR)
# firewall-cmd --permanent --zone=public --add-rich-rule 'rule family="ipv4"
source address="x.x.x.x" reject type=”icmp-admin-prohibited”'
# firewall-cmd –reload
# firewall-cmd –reload
(OR)
# firewall-cmd --permanent --zone=public --add-rich-rule 'rule family="ipv4"
source address="x.x.x.x" port port=22 protocol=tcp reject'
# firewall-cmd –reload