One of the most important security tools for Linux is the firewall, which controls incoming and outgoing network traffic according to established security policies and prevents unauthorized users from accessing the system.
One popular open-source firewall tool for Linux is iptables, which lets users manage network traffic rules and define packet filtering. One must establish rules that govern the treatment of various packet types to enable packet filtering using iptables.
A default policy for chain traffic may be specified, rules can be added to allow or deny specific types of communication, and these settings can be saved to make sure they are retained even after reboots.
You need to know the syntax of iptables and the protocols that it controls to utilize it effectively.
What is a Linux Firewall?
What is Iptables? How does it work?
How Does Packet Filtering Work with Iptables?
Tables Overview
Blocking Attacks with IPtables:
Other Simple rules to Try
A Linux firewall is a device that inspects Network traffic ( Inbound /Outbound connections ) and decides to pass or filter out the traffic. Iptables is a CLI tool for managing firewall rules on a Linux machine.
Network Security evolved with different types of Linux firewalls in the era. Traditional packet-filtering firewalls deal with Routing and filtering packets ( OSI Layers 3 and 4 ), Where else NGFWs will work with additional functions as with OSI layers ( L4-L7 of OSI model ).
Iptables is a CLI ( Command-line interface ) application that allows the administrator to configure specific rules that will enforce the Linux kernel ( Netfilter framework) to act such as inspect, modify, or drop network packets. Enabling these Iptables in any Linux machine or device will be acting as a Network Firewall and/or a router.
Different kernel modules and programs are used for different protocols; IPtables apply to IPv4, IP6tables to IPv6, ARP tables to ARP, and ebtables to Ethernet frames.
Later Netfilter Project developed Nftables for performance and scalability. This is a packet filtering framework that does the same work as Iptables.
An iptables policy is built with an ordered set of rules, which describe to the kernel the actions that should be taken against certain types of packets.
Iptables functionality is classified into Four tables which are NAT table, packet filtering table, Mangle table, and Raw table.
NAT Table:
Packet Filtering Table:
Packet filtering is processed with the below chain rules.
Chains:
Mangle table
Raw table
Matches:
Every iptables rule has a set of matches that tells the iptables what to do with a packet.
–source (-s) source IP address or network
–destination (-d) Destination IP address or network
–protocol (-p) IP value
–in-interface (-i) Input interface (e.g., eth0)
–out-interface (-o) Output interface
–state connection states
–string sequence of application layer data bytes
Target:
ACCEPT – Allows a packet.( Accept the incoming/outgoing connection )
DROP – Drops a packet. ( Drop the connections )
LOG – Logs a packet to Syslog.( Log the connection status for network monitoring, TCP Built/teardown )
REJECT – Drops a packet sends an appropriate response packet (TCP Reset or an ICMP Port Unreachable message).
RETURN- Continues processing a packet within the calling chain.
NOTE: If you are a Pentester /Red team guy, Iptables Linux firewall can hide some systems in the network as ICMP probs are blocked. But this system can be enumerated and identified in-network with crafted ARP packets. Still, as a Defense guy, they can use Arp-tables to stop you. This is a totally HIDE and Seek GAME forever.
Application Layer Defense:
iptables -I FORWARD 1 -p tcp –dport 80 -m state –state ESTABLISHED -m string –string “/etc/shadow” –algo bm -j LOG –log-prefix “ETC SHADOW“
Malformed Packets Transport Layer:
iptables -A INPUT -p tcp –tcp-flags ALL NONE -j DROP
Blocking Outbound Emails:
iptables -A OUTPUT -p tcp –dport 25 -j REJECT
Open Source Linux firewalls can be used for small-scale businesses, VPS hosted on third-party clouds, and more. Enterprise firewalls also play a similar kind of technique. But it’s good to choose the right Firewalls ( Proprietary/OpenSource ) according to your business needs.
Happy Packet Dropping!
Also Read: What is the Different Between VPN and Proxy – A Complete Guide
Hackers are actively probing AI systems, turning exposed gateways and agent tools into routes for…
Hackers are making some phishing pages harder to track by changing the code delivered to…
A cyber incident reportedly forced a British power plant to halt operations for about four…
Russian hackers have used a new backdoor called HOOKEDGE to target defense manufacturers, government bodies,…
TITAN ransomware is pairing file encryption with an ambitious claim: artificial intelligence that can sort…
A fake student resume is being used to place a remote-access tool on researchers’ Windows…