SlideShare a Scribd company logo
2
Most read
5
Most read
6
Most read
Understanding iptables
Linux firewall basics
Netfilter hooks stages
Socket
App
NIC
INPUT
PRE_ROUTING POST_ROUTING
OUTPUT
FORWARD
Stateless firewall
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
Stateful firewall
iptables -A INPUT -p tcp -m conntrack --ctstate ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT
Logging
iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW -j LOG --log-prefix “In
Http:”
Tables overview
Filter is a default table.
So, if you don’t define
you own table, you’ll
be using filter table.
Each table has a number
of predefined chains
inside.
You can create your own
chain.
Filter
Input
Forward
Output
Nat
Output
Prerouting
Postrouting
Mangle
Input
Prerouting
Postrouting
Output
Forward
Raw
Output
Prerouting
Tables in shell
iptables -t mangle -A POSTROUTING -o $NETCARD -p tcp -m connbytes --connbytes
10000000: --connbytes-mode bytes --connbytes-dir both -j CONNMARK --set-mark 999
iptables -t mangle -A INPUT -i eth0 -p tcp --dport 80 -m string --string ”get /admin http/”
--icase --algo bm -m conntrack --ctstate ESTABLISHED -j DROP
iptables -t filter -A input -p tcp --dport 22 -m time --datestart “” --datestop “” --utc --j
DROP
Custom chains
Create a new chain
iptables -N LOGDROP
Add chain rules
iptables -A LOGDROP -j LOG --log-level 4 --log-prefix 'SourceDrop '
iptables -A LOGDROP -j DROP
Add chain rules to iptables rules
iptables -A INPUT -s 10.0.0.0/8 -j LOGDROP
Netfilter in user land
libnetfilter_queue is used to divert traffic to user application
Packets are not duplicated
User application has to inject a packet back
Useful for debugging rules
ip sets
Constant time hash lookup
modprobe ip_set
ipset -N droplist nethash
ipset -add droplist 192.168.1.0/24
iptables -A INPUT -m set --set droplistsrc -j DROP
Useful commands
Drop all rules
iptables -F
Quickly restore rules
iptables-restore <rules list file>
References
Designing and Implementing Linux Firewalls with QoS using netfilter, iproute2, NAT
and L7-filter
Netfilter & Iptables Elements
Linux Firewall Tutorial: IPTables Tables, Chains, Rules Fundamentals
Understanding Linux Network Internals
iptables book
Iptables targets and jumps
Security in Linux
My blog
Learning Network Programming

More Related Content

PDF
LinuxCon 2015 Linux Kernel Networking Walkthrough
PDF
Container Performance Analysis
PDF
netfilter and iptables
PPTX
Linux Network Stack
PDF
Linux Networking Explained
PDF
CCNA CheatSheet
PDF
IntelON 2021 Processor Benchmarking
PDF
Uboot startup sequence
LinuxCon 2015 Linux Kernel Networking Walkthrough
Container Performance Analysis
netfilter and iptables
Linux Network Stack
Linux Networking Explained
CCNA CheatSheet
IntelON 2021 Processor Benchmarking
Uboot startup sequence

What's hot (20)

PDF
QEMU Disk IO Which performs Better: Native or threads?
ODP
nftables - the evolution of Linux Firewall
PDF
Linux Kernel vs DPDK: HTTP Performance Showdown
PDF
OVS and DPDK - T.F. Herbert, K. Traynor, M. Gray
PDF
Velocity 2015 linux perf tools
PDF
The linux networking architecture
PPTX
The TCP/IP Stack in the Linux Kernel
PDF
Linux Performance Analysis: New Tools and Old Secrets
PDF
Linux Linux Traffic Control
PDF
Linux Performance Analysis and Tools
PPTX
Présentation NAC-NAP PPT HARIFI Madiha
PDF
LCU14 302- How to port OP-TEE to another platform
PPTX
JUNOS - Monitoring and Troubleshooting
PDF
DevConf 2014 Kernel Networking Walkthrough
PDF
YOW2020 Linux Systems Performance
PPTX
Broken Linux Performance Tools 2016
PPTX
用Raspberry Pi 學Linux I2C Driver
PDF
LISA2019 Linux Systems Performance
PDF
Using eBPF for High-Performance Networking in Cilium
QEMU Disk IO Which performs Better: Native or threads?
nftables - the evolution of Linux Firewall
Linux Kernel vs DPDK: HTTP Performance Showdown
OVS and DPDK - T.F. Herbert, K. Traynor, M. Gray
Velocity 2015 linux perf tools
The linux networking architecture
The TCP/IP Stack in the Linux Kernel
Linux Performance Analysis: New Tools and Old Secrets
Linux Linux Traffic Control
Linux Performance Analysis and Tools
Présentation NAC-NAP PPT HARIFI Madiha
LCU14 302- How to port OP-TEE to another platform
JUNOS - Monitoring and Troubleshooting
DevConf 2014 Kernel Networking Walkthrough
YOW2020 Linux Systems Performance
Broken Linux Performance Tools 2016
用Raspberry Pi 學Linux I2C Driver
LISA2019 Linux Systems Performance
Using eBPF for High-Performance Networking in Cilium
Ad

Viewers also liked (19)

PPTX
PPTX
Git basics
PPTX
Understanding DPDK algorithmics
PPTX
History of the personal computer
PPTX
PPTX
Secure communication
PPTX
Understanding DPDK
PPTX
Network sockets
PPTX
DPDK KNI interface
PDF
Iptables presentation
PPT
Iptables in linux
PDF
netfilter programming
PPT
IPTABLES
PDF
Iptables Configuration
PDF
DPDK Summit - 08 Sept 2014 - Intel - Networking Workloads on Intel Architecture
PDF
DPDK Summit 2015 - Intel - Keith Wiles
PDF
Intel DPDK Step by Step instructions
KEY
Fosscon 2012 firewall workshop
PDF
How to Become a Thought Leader in Your Niche
Git basics
Understanding DPDK algorithmics
History of the personal computer
Secure communication
Understanding DPDK
Network sockets
DPDK KNI interface
Iptables presentation
Iptables in linux
netfilter programming
IPTABLES
Iptables Configuration
DPDK Summit - 08 Sept 2014 - Intel - Networking Workloads on Intel Architecture
DPDK Summit 2015 - Intel - Keith Wiles
Intel DPDK Step by Step instructions
Fosscon 2012 firewall workshop
How to Become a Thought Leader in Your Niche
Ad

Similar to Understanding iptables (20)

PDF
[2019.01.12] hst iptables 101 to 301
PDF
Iptables fundamentals
PPTX
PPTX
Linux Firewall (Netfilter )and tools .pptx
PDF
Firewall Facts
PPT
I ptable
PPT
Iptables
PPTX
Firewalls rules using iptables in linux
PDF
Linux iptables Pocket Reference 1st Edition Gregor N. Purdy download pdf
PPTX
Iptables the Linux Firewall
PDF
Chapter 6 firewall
PDF
Linux firewall
DOCX
Creating a firewall in UBUNTU
PDF
IP Tables Primer - Part 1
PDF
IPTables Primer - Part 1
PPTX
IP Tables And Filtering
PDF
Packet Filtering Using Iptables
PPT
Linux Firewall - NullCon Chennai Presentation
PDF
iptable casestudy by sans.pdf
ODP
Firewalld : A New Interface to Your Netfilter Stack
[2019.01.12] hst iptables 101 to 301
Iptables fundamentals
Linux Firewall (Netfilter )and tools .pptx
Firewall Facts
I ptable
Iptables
Firewalls rules using iptables in linux
Linux iptables Pocket Reference 1st Edition Gregor N. Purdy download pdf
Iptables the Linux Firewall
Chapter 6 firewall
Linux firewall
Creating a firewall in UBUNTU
IP Tables Primer - Part 1
IPTables Primer - Part 1
IP Tables And Filtering
Packet Filtering Using Iptables
Linux Firewall - NullCon Chennai Presentation
iptable casestudy by sans.pdf
Firewalld : A New Interface to Your Netfilter Stack

Recently uploaded (20)

PPT
Introduction Database Management System for Course Database
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
history of c programming in notes for students .pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
ai tools demonstartion for schools and inter college
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Introduction Database Management System for Course Database
Design an Analysis of Algorithms II-SECS-1021-03
Odoo Companies in India – Driving Business Transformation.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Which alternative to Crystal Reports is best for small or large businesses.pdf
Online Work Permit System for Fast Permit Processing
Navsoft: AI-Powered Business Solutions & Custom Software Development
history of c programming in notes for students .pptx
Design an Analysis of Algorithms I-SECS-1021-03
ISO 45001 Occupational Health and Safety Management System
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
ai tools demonstartion for schools and inter college
ManageIQ - Sprint 268 Review - Slide Deck
PTS Company Brochure 2025 (1).pdf.......
Softaken Excel to vCard Converter Software.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
How to Migrate SBCGlobal Email to Yahoo Easily
Wondershare Filmora 15 Crack With Activation Key [2025
Operating system designcfffgfgggggggvggggggggg
Lecture 3: Operating Systems Introduction to Computer Hardware Systems

Understanding iptables

  • 3. Stateless firewall iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  • 4. Stateful firewall iptables -A INPUT -p tcp -m conntrack --ctstate ESTABLISHED -j ACCEPT iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT
  • 5. Logging iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW -j LOG --log-prefix “In Http:”
  • 6. Tables overview Filter is a default table. So, if you don’t define you own table, you’ll be using filter table. Each table has a number of predefined chains inside. You can create your own chain. Filter Input Forward Output Nat Output Prerouting Postrouting Mangle Input Prerouting Postrouting Output Forward Raw Output Prerouting
  • 7. Tables in shell iptables -t mangle -A POSTROUTING -o $NETCARD -p tcp -m connbytes --connbytes 10000000: --connbytes-mode bytes --connbytes-dir both -j CONNMARK --set-mark 999 iptables -t mangle -A INPUT -i eth0 -p tcp --dport 80 -m string --string ”get /admin http/” --icase --algo bm -m conntrack --ctstate ESTABLISHED -j DROP iptables -t filter -A input -p tcp --dport 22 -m time --datestart “” --datestop “” --utc --j DROP
  • 8. Custom chains Create a new chain iptables -N LOGDROP Add chain rules iptables -A LOGDROP -j LOG --log-level 4 --log-prefix 'SourceDrop ' iptables -A LOGDROP -j DROP Add chain rules to iptables rules iptables -A INPUT -s 10.0.0.0/8 -j LOGDROP
  • 9. Netfilter in user land libnetfilter_queue is used to divert traffic to user application Packets are not duplicated User application has to inject a packet back Useful for debugging rules
  • 10. ip sets Constant time hash lookup modprobe ip_set ipset -N droplist nethash ipset -add droplist 192.168.1.0/24 iptables -A INPUT -m set --set droplistsrc -j DROP
  • 11. Useful commands Drop all rules iptables -F Quickly restore rules iptables-restore <rules list file>
  • 12. References Designing and Implementing Linux Firewalls with QoS using netfilter, iproute2, NAT and L7-filter Netfilter & Iptables Elements Linux Firewall Tutorial: IPTables Tables, Chains, Rules Fundamentals Understanding Linux Network Internals iptables book Iptables targets and jumps Security in Linux