Linux Firewall Tools
Linux Firewall Tools
Linux provides several tools to configure and manage firewalls.
A firewall in Linux is a security system that controls the incoming and outgoing network traffic based on predefined rules. It acts as a barrier between your computer and the outside world, helping to block unauthorized access while allowing legitimate communication.
A firewall acts like a security guard for your Linux system. It monitors and controls incoming and outgoing network traffic based on predefined rules. This helps protect your system from unauthorized access, malware, or attacks while allowing legitimate communication.
Common Linux firewall tools include iptables
, nftables
, and firewalld
. These tools can be used to define rules for filtering packets, forwarding traffic, and NAT (Network Address Translation)
- iptables: Traditional firewall tool
- nftables: Modern replacement for iptables
- firewalld: User-friendly firewall manager
iptables
iptables
is a user-space utility program that allows administrators to configure the Linux kernel firewall. It uses tables to manage rules for handling network traffic.
A command-line tool that uses tables and chains to filter network traffic. Example to allow SSH access (port 22):
Examples:
$ sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
This rule allows incoming TCP connections on port 22 (SSH).
nftables
nftables
is the successor to iptables
, offering a simpler and more consistent syntax. It uses a single framework to handle IPv4, IPv6, ARP. A newer, more efficient firewall framework replacing iptables. Example to allow HTTP/HTTPS traffic:
Examples:
$ sudo nft add table inet filter
$ sudo nft add chain inet filter input { type filter hook input priority 0 \; }
$ sudo nft add rule inet filter input tcp dport {80, 443} accept
$ sudo nft add rule ip filter input tcp dport 22 accept
This rule allows incoming TCP connections on port 22 using the nftables syntax.
firewalld
firewalld
is a front-end management tool for iptables
and nftables
. It uses zones and services to simplify firewall configuration, and supports dynamic rule changes without restarting the firewall. A dynamic firewall manager with zones and services. Example to enable HTTP service:
Examples:
$ sudo firewall-cmd --zone=public --add-service=http --permanent
$ sudo firewall-cmd --zone=public --add-port=22/tcp --permanent
This command permanently allows TCP traffic on port 22 in the “public” zone.
Why Use These Tools?
- Control network access to your system
- Block suspicious traffic
- Create security zones for different networks
- Log network activity for monitoring