Skip to main content

iptables, firewalld

iptables

iptables is a Linux Firewall utility that's used to configure rules on the kernel netfilter firewall. iptables processes packets based on chains of rules, deciding whether to allow, drop, or manipulate them.

DISADVANTAGE - RELOAD CONNECTION DROP

Tables & Chains

What are tables?

iptables has various different tables that perform different functions. Notable tables and their functions;

TablePurposeExample
FilterThe default table for allowing/blocking traffic.Accept SSH, block pings, etc
NATUsed to implement  Network Address Translation rules.Port forwarding, IP masking
MangleUsed for modifying packet headers.Changing TTL,
RawUsed to configure exceptions for packets involved in connection tracking.
SecurityUsed to mark packets with SELinux context.

If you don't specify a specific table when running iptables commands, you'll be using the filter table by default - which is the most commonly used anyway.

What are chains?

Chains are lists of rules that belong to a table. Each chain represents a rule that a packet must have imposed against it during its journey through the system.

ChainFunction
INPUTFor incoming packets.
OUTPUTFor outgoing packets.
FORWARDFor packets passing through the system.
PREROUTING & POSTROUTINGUsed in NAT/Mangle tables for altering packets before or after routing decisions. 

Basic Commands & syntaxSyntax

iptables [options] [-t table] [commands] {chain/rule specification}

Saving & Persisting Rules 


firewalld

firewalld at its core is essentially a wrapper for iptables, but it does include some extra features and improved functionality.

  • With iptables, when you reload a rule, connections can drop. This is a big problem on production servers. Firewalld uses in-place rule updates to prevent this.

 

 

 

firewall-cmd --get-zones

 

 

firewall-cmd --zone=dmz --list-all