SlideShare a Scribd company logo
netfilter and iptables
netfilter and iptables
●
●
●
○
○
○
○
●
○
○
○
●
○
○
○
netfilter and iptables
…
netfilter and iptables
●
●
○
○
●
●
●
●
●
●
●
ip_rcv_finish()
ip_rcv()
ip_local_deliver_finish()
ip_local_deliver()
ip_forward()
ip_forward_finish()
ip_local_out()
dst_output()
ip_output()
ip_finish_output()
/*
* Main IP Receive routine.
*/
int ip_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig)
{
...
return NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING,
net, NULL, skb, dev, NULL, ip_rcv_finish);
}
/* Activate hook; either okfn or kfree_skb called, unless a hook
returns NF_STOLEN (in which case, it's up to the hook to deal with
the consequences).
Returns -ERRNO if packet dropped. Zero means queued, stolen or accepted.
*/
static inline int
NF_HOOK_THRESH(uint8_t pf, unsigned int hook, struct net *net,
struct sock *sk, struct sk_buff *skb,
struct net_device *in, struct net_device *out,
int (*okfn)(struct net *, struct sock *, struct sk_buff *),
int thresh)
{
int ret = nf_hook_thresh(pf, hook, net, sk, skb, in, out, okfn, thresh);
if (ret == 1)
ret = okfn(net, sk, skb);
return ret;
}
int nf_register_net_hook(struct net *net,
const struct nf_hook_ops *ops);
int nf_register_net_hooks(struct net *net,
const struct nf_hook_ops *reg,
unsigned int n);
int nf_register_hook(struct nf_hook_ops *reg);
int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n);
static struct nf_hook_ops ipv4_synproxy_ops[] = {
{
.hook = ipv4_synproxy_hook,
.pf = NFPROTO_IPV4,
.hooknum = NF_INET_LOCAL_IN,
.priority = NF_IP_PRI_CONNTRACK_CONFIRM - 1,
.priv = NULL,
},
{
.hook = ipv4_synproxy_hook,
.pf = NFPROTO_IPV4,
.hooknum = NF_INET_POST_ROUTING,
.priority = NF_IP_PRI_CONNTRACK_CONFIRM - 1,
.priv = NULL,
},
};
static unsigned int
ipv4_synproxy_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *nhs)
{
if (...)
return NF_ACCEPT;
...
if (...)
return NF_DROP;
return NF_ACCEPT;
}
●
●
●
●
●
enum {
NFPROTO_UNSPEC = 0,
NFPROTO_INET = 1,
NFPROTO_IPV4 = 2,
NFPROTO_ARP = 3,
NFPROTO_NETDEV = 5,
NFPROTO_BRIDGE = 7,
NFPROTO_IPV6 = 10,
NFPROTO_DECNET = 12,
NFPROTO_NUMPROTO,
};
netfilter and iptables
●
●
●
●
○
●
netfilter and iptables
●
●
netfilter and iptables
netfilter and iptables
# iptables -t filter -P INPUT DROP
# iptables -P OUTPUT ACCEPT
# iptables -A INPUT -i lo -j ACCEPT
# iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# iptables -A INPUT -s 40.5.6.7 -p tcp --dport 22 -j ACCEPT
# iptables -A INPUT -m mark --mark 0xE -j ACCEPT
# iptables -t mangle -A PREROUTING 
-p tcp --dport 22 -j MARK --set-mark 2
# iptables -t mangle -A POSTROUTING 
-p tcp --tcp-flags SYN,RST SYN -o eth0 
-j TCPMSS --set-mss 1420
# iptables -t mangle -A OUTPUT -p TCP --dport 22 
-j TOS --set-tos 0x10
# iptables -t nat -A POSTROUTING 
-o eth0 -s 192.168.1.0/24 
-j SNAT --to-source 2.55.4.8-2.55.4.9
192.168.1.10
192.168.1.11
192.168.1.12
192.168.1.13
2.55.4.8
2.55.4.9
# iptables -t nat -A POSTROUTING 
-o eth0 -s 192.168.1.0/24 -j MASQUERADE
192.168.1.10
192.168.1.11
192.168.1.12
192.168.1.13
2.55.4.9
# iptables -t nat -A PREROUTING -d 2.55.4.8 -p tcp --dport 80 
-j DNAT --to-destination 192.168.1.10
192.168.1.10
192.168.1.11
192.168.1.12
192.168.1.13
2.55.4.8 :80
2.55.4.9
netfilter and iptables
●
●
○
○
●
# iptables -t filter -P INPUT DROP
# iptables -P OUTPUT ACCEPT
# iptables -A INPUT -i lo -j ACCEPT
# iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED 
-j ACCEPT
# iptables -A INPUT -p tcp --dport 443 
-m conntrack --ctstate NEW -j ACCEPT
netfilter and iptables
●
# iptables -A PREROUTING -m addrtype --dst-type MULTICAST -j DROP
# iptables -A PREROUTING -m addrtype ! --dst-type LOCAL 
-j MARK --set-mark 2
●
# iptables -A FORWARD -m devgroup --src-group 27 -j ACCEPT
●
# iptables -A FORWARD -m mark --mark 0x3/0x7 -j ACCEPT
●
// match IP packets with total length >= 256
-m u32 --u32 "0 & 0xFFFF = 0x100:0xFFFF"
// TCP payload bytes 8-12 is any of 1, 2, 5 or 8
"6 & 0xFF = 6 && 0 >> 22 & 0x3C @ 12 >> 26 & 0x3C @ 8 = 1,2,5,8"
●
-m bpf --bytecode '4,48 0 0 9,21 0 1 6,6 0 0 1,6 0 0 0'
●
●
●
●
● …
●
●
●
●
●
●
●
● …
# iptables -t filter -N NO-PRIVATE
# iptables -A NO-PRIVATE -s 10.0.0.0/8 -j DROP
# iptables -A NO-PRIVATE -s 172.16.0.0/12 -j DROP
# iptables -A NO-PRIVATE -s 192.168.0.0/16 -j DROP
# iptables -A INPUT -i eth0 -j NO-PRIVATE
# iptables -A FORWARD -i eth0 -j NO-PRIVATE
// Calls the specified chain,
continue processing in current chain if no match
# iptables -A INPUT ... -j MY-CHAIN
// Continue processing in the specified chain.
return will not continue in current chain,
but in the previous calling chain
# iptables -A INPUT ... -g MY-CHAIN
// Stop traversing, resume at the next rule in the previous
calling chain
# iptables -A MY-CHAIN ... -j RETURN
●
●
●
netfilter and iptables
●
●
●
○
●
●
●
○
○
netfilter and iptables
●
●
●
●
●

More Related Content

PDF
The linux networking architecture
hugo lu
 
PDF
Fun with Network Interfaces
Kernel TLV
 
PDF
LinuxCon 2015 Linux Kernel Networking Walkthrough
Thomas Graf
 
PDF
Linux Networking Explained
Thomas Graf
 
PDF
Linux Linux Traffic Control
SUSE Labs Taipei
 
PDF
Faster packet processing in Linux: XDP
Daniel T. Lee
 
PDF
VLANs in the Linux Kernel
Kernel TLV
 
PPTX
Linux Network Stack
Adrien Mahieux
 
The linux networking architecture
hugo lu
 
Fun with Network Interfaces
Kernel TLV
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
Thomas Graf
 
Linux Networking Explained
Thomas Graf
 
Linux Linux Traffic Control
SUSE Labs Taipei
 
Faster packet processing in Linux: XDP
Daniel T. Lee
 
VLANs in the Linux Kernel
Kernel TLV
 
Linux Network Stack
Adrien Mahieux
 

What's hot (20)

PPTX
The TCP/IP Stack in the Linux Kernel
Divye Kapoor
 
PDF
DPDK in Containers Hands-on Lab
Michelle Holley
 
PDF
introduction to linux kernel tcp/ip ptocotol stack
monad bobo
 
PDF
Intel DPDK Step by Step instructions
Hisaki Ohara
 
PDF
Building Network Functions with eBPF & BCC
Kernel TLV
 
PDF
DevConf 2014 Kernel Networking Walkthrough
Thomas Graf
 
PDF
DPDK & Layer 4 Packet Processing
Michelle Holley
 
PDF
DPDK: Multi Architecture High Performance Packet Processing
Michelle Holley
 
PDF
nl80211 and libnl
awkman
 
ODP
Dpdk performance
Stephen Hemminger
 
PPTX
DPDK KNI interface
Denys Haryachyy
 
PDF
Tutorial WiFi driver code - Opening Nuts and Bolts of Linux WiFi Subsystem
Dheryta Jaisinghani
 
PPTX
The Basic Introduction of Open vSwitch
Te-Yen Liu
 
PDF
Network Programming: Data Plane Development Kit (DPDK)
Andriy Berestovskyy
 
PDF
Segment Routing
APNIC
 
PDF
Analysis of Open-Source Drivers for IEEE 802.11 WLANs
Danh Nguyen
 
PDF
Introduction to eBPF and XDP
lcplcp1
 
PDF
Deploying CloudStack and Ceph with flexible VXLAN and BGP networking
ShapeBlue
 
PDF
BPF Internals (eBPF)
Brendan Gregg
 
ODP
eBPF maps 101
SUSE Labs Taipei
 
The TCP/IP Stack in the Linux Kernel
Divye Kapoor
 
DPDK in Containers Hands-on Lab
Michelle Holley
 
introduction to linux kernel tcp/ip ptocotol stack
monad bobo
 
Intel DPDK Step by Step instructions
Hisaki Ohara
 
Building Network Functions with eBPF & BCC
Kernel TLV
 
DevConf 2014 Kernel Networking Walkthrough
Thomas Graf
 
DPDK & Layer 4 Packet Processing
Michelle Holley
 
DPDK: Multi Architecture High Performance Packet Processing
Michelle Holley
 
nl80211 and libnl
awkman
 
Dpdk performance
Stephen Hemminger
 
DPDK KNI interface
Denys Haryachyy
 
Tutorial WiFi driver code - Opening Nuts and Bolts of Linux WiFi Subsystem
Dheryta Jaisinghani
 
The Basic Introduction of Open vSwitch
Te-Yen Liu
 
Network Programming: Data Plane Development Kit (DPDK)
Andriy Berestovskyy
 
Segment Routing
APNIC
 
Analysis of Open-Source Drivers for IEEE 802.11 WLANs
Danh Nguyen
 
Introduction to eBPF and XDP
lcplcp1
 
Deploying CloudStack and Ceph with flexible VXLAN and BGP networking
ShapeBlue
 
BPF Internals (eBPF)
Brendan Gregg
 
eBPF maps 101
SUSE Labs Taipei
 
Ad

Similar to netfilter and iptables (20)

PDF
Chapter 6 firewall
newbie2019
 
PPT
IPTABLES
Tan Huynh Cong
 
PPT
Iptables
leminhvuong
 
PPT
Packet_Filteringfgasdgasdgsagdsgsagasg.ppt
VerdiFerdiansyah1
 
PDF
Specializing the Data Path - Hooking into the Linux Network Stack
Kernel TLV
 
ODP
nftables - the evolution of Linux Firewall
Marian Marinov
 
PDF
Introduction to firewalls through Iptables
Bud Siddhisena
 
PDF
Iptables presentation
Emin Abdul Azeez
 
PPTX
How to convert your Linux box into Security Gateway - Part 1
n|u - The Open Security Community
 
PDF
Iptables Configuration
stom123
 
PDF
IP Tables Getting Started - Part 2
n|u - The Open Security Community
 
PDF
IPTables Primer - Part 2
Nishanth Kumar Pathi
 
PDF
Packet Filtering Using Iptables
Ahmed Mekkawy
 
PDF
Firewall Facts
DAVID RAUDALES
 
DOCX
25 most frequently used linux ip tables rules examples
Teja Bheemanapally
 
DOCX
25 most frequently used linux ip tables rules examples
Teja Bheemanapally
 
PDF
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
Thomas Graf
 
PDF
Plan 9カーネルにおけるTCP/IP実装(未完)
Ryousei Takano
 
PDF
25 most frequently used linux ip tables rules examples
chinkshady
 
PDF
Linux firewall
chanmyaeag
 
Chapter 6 firewall
newbie2019
 
IPTABLES
Tan Huynh Cong
 
Iptables
leminhvuong
 
Packet_Filteringfgasdgasdgsagdsgsagasg.ppt
VerdiFerdiansyah1
 
Specializing the Data Path - Hooking into the Linux Network Stack
Kernel TLV
 
nftables - the evolution of Linux Firewall
Marian Marinov
 
Introduction to firewalls through Iptables
Bud Siddhisena
 
Iptables presentation
Emin Abdul Azeez
 
How to convert your Linux box into Security Gateway - Part 1
n|u - The Open Security Community
 
Iptables Configuration
stom123
 
IP Tables Getting Started - Part 2
n|u - The Open Security Community
 
IPTables Primer - Part 2
Nishanth Kumar Pathi
 
Packet Filtering Using Iptables
Ahmed Mekkawy
 
Firewall Facts
DAVID RAUDALES
 
25 most frequently used linux ip tables rules examples
Teja Bheemanapally
 
25 most frequently used linux ip tables rules examples
Teja Bheemanapally
 
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
Thomas Graf
 
Plan 9カーネルにおけるTCP/IP実装(未完)
Ryousei Takano
 
25 most frequently used linux ip tables rules examples
chinkshady
 
Linux firewall
chanmyaeag
 
Ad

More from Kernel TLV (20)

PDF
DPDK In Depth
Kernel TLV
 
PDF
SGX Trusted Execution Environment
Kernel TLV
 
PDF
Fun with FUSE
Kernel TLV
 
PPTX
Kernel Proc Connector and Containers
Kernel TLV
 
PPTX
Bypassing ASLR Exploiting CVE 2015-7545
Kernel TLV
 
PDF
Present Absence of Linux Filesystem Security
Kernel TLV
 
PDF
OpenWrt From Top to Bottom
Kernel TLV
 
PDF
Make Your Containers Faster: Linux Container Performance Tools
Kernel TLV
 
PDF
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Kernel TLV
 
PDF
File Systems: Why, How and Where
Kernel TLV
 
PDF
KernelTLV Speaker Guidelines
Kernel TLV
 
PDF
Userfaultfd: Current Features, Limitations and Future Development
Kernel TLV
 
PDF
The Linux Block Layer - Built for Fast Storage
Kernel TLV
 
PDF
Linux Kernel Cryptographic API and Use Cases
Kernel TLV
 
PPTX
DMA Survival Guide
Kernel TLV
 
PPSX
FD.IO Vector Packet Processing
Kernel TLV
 
PPTX
WiFi and the Beast
Kernel TLV
 
PPTX
Introduction to DPDK
Kernel TLV
 
PDF
FreeBSD and Drivers
Kernel TLV
 
PPTX
Linux Interrupts
Kernel TLV
 
DPDK In Depth
Kernel TLV
 
SGX Trusted Execution Environment
Kernel TLV
 
Fun with FUSE
Kernel TLV
 
Kernel Proc Connector and Containers
Kernel TLV
 
Bypassing ASLR Exploiting CVE 2015-7545
Kernel TLV
 
Present Absence of Linux Filesystem Security
Kernel TLV
 
OpenWrt From Top to Bottom
Kernel TLV
 
Make Your Containers Faster: Linux Container Performance Tools
Kernel TLV
 
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Kernel TLV
 
File Systems: Why, How and Where
Kernel TLV
 
KernelTLV Speaker Guidelines
Kernel TLV
 
Userfaultfd: Current Features, Limitations and Future Development
Kernel TLV
 
The Linux Block Layer - Built for Fast Storage
Kernel TLV
 
Linux Kernel Cryptographic API and Use Cases
Kernel TLV
 
DMA Survival Guide
Kernel TLV
 
FD.IO Vector Packet Processing
Kernel TLV
 
WiFi and the Beast
Kernel TLV
 
Introduction to DPDK
Kernel TLV
 
FreeBSD and Drivers
Kernel TLV
 
Linux Interrupts
Kernel TLV
 

Recently uploaded (20)

PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PDF
Immersive experiences: what Pharo users do!
ESUG
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PDF
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
DOCX
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
Immersive experiences: what Pharo users do!
ESUG
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
Presentation about variables and constant.pptx
kr2589474
 
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Bandai Playdia The Book - David Glotz
BluePanther6
 

netfilter and iptables

  • 6.
  • 11. /* * Main IP Receive routine. */ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig) { ... return NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, net, NULL, skb, dev, NULL, ip_rcv_finish); }
  • 12. /* Activate hook; either okfn or kfree_skb called, unless a hook returns NF_STOLEN (in which case, it's up to the hook to deal with the consequences). Returns -ERRNO if packet dropped. Zero means queued, stolen or accepted. */ static inline int NF_HOOK_THRESH(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk, struct sk_buff *skb, struct net_device *in, struct net_device *out, int (*okfn)(struct net *, struct sock *, struct sk_buff *), int thresh) { int ret = nf_hook_thresh(pf, hook, net, sk, skb, in, out, okfn, thresh); if (ret == 1) ret = okfn(net, sk, skb); return ret; }
  • 13. int nf_register_net_hook(struct net *net, const struct nf_hook_ops *ops); int nf_register_net_hooks(struct net *net, const struct nf_hook_ops *reg, unsigned int n); int nf_register_hook(struct nf_hook_ops *reg); int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n);
  • 14. static struct nf_hook_ops ipv4_synproxy_ops[] = { { .hook = ipv4_synproxy_hook, .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_IN, .priority = NF_IP_PRI_CONNTRACK_CONFIRM - 1, .priv = NULL, }, { .hook = ipv4_synproxy_hook, .pf = NFPROTO_IPV4, .hooknum = NF_INET_POST_ROUTING, .priority = NF_IP_PRI_CONNTRACK_CONFIRM - 1, .priv = NULL, }, };
  • 15. static unsigned int ipv4_synproxy_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *nhs) { if (...) return NF_ACCEPT; ... if (...) return NF_DROP; return NF_ACCEPT; }
  • 17. enum { NFPROTO_UNSPEC = 0, NFPROTO_INET = 1, NFPROTO_IPV4 = 2, NFPROTO_ARP = 3, NFPROTO_NETDEV = 5, NFPROTO_BRIDGE = 7, NFPROTO_IPV6 = 10, NFPROTO_DECNET = 12, NFPROTO_NUMPROTO, };
  • 24. # iptables -t filter -P INPUT DROP # iptables -P OUTPUT ACCEPT # iptables -A INPUT -i lo -j ACCEPT # iptables -A INPUT -p tcp --dport 443 -j ACCEPT # iptables -A INPUT -s 40.5.6.7 -p tcp --dport 22 -j ACCEPT # iptables -A INPUT -m mark --mark 0xE -j ACCEPT
  • 25. # iptables -t mangle -A PREROUTING -p tcp --dport 22 -j MARK --set-mark 2 # iptables -t mangle -A POSTROUTING -p tcp --tcp-flags SYN,RST SYN -o eth0 -j TCPMSS --set-mss 1420 # iptables -t mangle -A OUTPUT -p TCP --dport 22 -j TOS --set-tos 0x10
  • 26. # iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j SNAT --to-source 2.55.4.8-2.55.4.9 192.168.1.10 192.168.1.11 192.168.1.12 192.168.1.13 2.55.4.8 2.55.4.9
  • 27. # iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j MASQUERADE 192.168.1.10 192.168.1.11 192.168.1.12 192.168.1.13 2.55.4.9
  • 28. # iptables -t nat -A PREROUTING -d 2.55.4.8 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.10 192.168.1.10 192.168.1.11 192.168.1.12 192.168.1.13 2.55.4.8 :80 2.55.4.9
  • 31. # iptables -t filter -P INPUT DROP # iptables -P OUTPUT ACCEPT # iptables -A INPUT -i lo -j ACCEPT # iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # iptables -A INPUT -p tcp --dport 443 -m conntrack --ctstate NEW -j ACCEPT
  • 33. ● # iptables -A PREROUTING -m addrtype --dst-type MULTICAST -j DROP # iptables -A PREROUTING -m addrtype ! --dst-type LOCAL -j MARK --set-mark 2 ● # iptables -A FORWARD -m devgroup --src-group 27 -j ACCEPT ● # iptables -A FORWARD -m mark --mark 0x3/0x7 -j ACCEPT
  • 34. ● // match IP packets with total length >= 256 -m u32 --u32 "0 & 0xFFFF = 0x100:0xFFFF" // TCP payload bytes 8-12 is any of 1, 2, 5 or 8 "6 & 0xFF = 6 && 0 >> 22 & 0x3C @ 12 >> 26 & 0x3C @ 8 = 1,2,5,8" ● -m bpf --bytecode '4,48 0 0 9,21 0 1 6,6 0 0 1,6 0 0 0'
  • 38. # iptables -t filter -N NO-PRIVATE # iptables -A NO-PRIVATE -s 10.0.0.0/8 -j DROP # iptables -A NO-PRIVATE -s 172.16.0.0/12 -j DROP # iptables -A NO-PRIVATE -s 192.168.0.0/16 -j DROP # iptables -A INPUT -i eth0 -j NO-PRIVATE # iptables -A FORWARD -i eth0 -j NO-PRIVATE
  • 39. // Calls the specified chain, continue processing in current chain if no match # iptables -A INPUT ... -j MY-CHAIN // Continue processing in the specified chain. return will not continue in current chain, but in the previous calling chain # iptables -A INPUT ... -g MY-CHAIN // Stop traversing, resume at the next rule in the previous calling chain # iptables -A MY-CHAIN ... -j RETURN