Netfilter Tutorial
Netfilter Tutorial
Lu-chuan (Luke) Kung [email protected] This presentation is based on the following material: 1. Rusty Russells presentation at Linux World 2000 Tutorial, http://www.netfilter.org/documentation/tutorials/lw2000/ 2. Oskar Andreassons presentation at CERT Conference 2002 Proceedings,
http://www.certconf.org/presentations/2002/Track s2002Expert_files/TE-1&2.pdf
IP Filter rule
Insertion point Match Target
Requires extra modules called "conntrack helpers" Examples are FTP, IRC (DCC), AH/ESP and ntalk
All new connections Includes Non SYN TCP packets ESTABLISHED All connections that has seen traffic in both directions RELATED All connections/packets related to other connections Examples: ICMP errors, FTP-Data, DCC INVALID Certain invalid packets depending on states E.g. FIN/ACK when no FIN was sent
Usages
Making a LAN look as if it came from a single source (the firewall) Creating separate servers with a single IP
Netfilter NAT
DNAT - Destination Network Address Translation SNAT - Source Network Address Translation Requires Connection tracking to keep states and expectations
Netfilter Architecture
The Hooks
Parts of the kernel can register with netfilter to see packets at various points in the stack IPv4: PRE_ROUTING, LOCAL_IN, FORWARD, LOCAL_OUT, POST_ROUTING. Each hook can alter packets, return NF_DROP, NF_ACCEPT, NF_QUEUE, NF_REPEAT or NF_STOLEN.
FORWARD
LOCAL_IN
LOCAL_OUT
Options:
verbose, line numbers, exact, etc.
Matches:
dport, dst, sport, src, states, TCP options, owner, etc.
Targets:
ACCEPT, DROP, REJECT, SNAT, DNAT, TOS, LOG, etc.
Destination IP & Port -d, --destination [!] address[/mask] --dport, --destination-port [!] port[:port]
Destination port Numeric or resolvable (/etc/services) Port range Destination address Resolvable (/etc/resolve.conf)
DROP
Drops the packet No reply Ends all further processing
RETURN
Returns from a chain to the calling chain
Iptables syntax
Listing the rules
-L, --list [chain]
And a LAN
LAN
IP range 192.168.1.0/24
On Top of Netfilter
Currently, four major subsystems exist on top of netfilter:
The backwards-compatibility ipchains & ipfwadm +masq/redir modules. The `iptables' packet classification system. The connection-tracking system. The NAT system.
iptables
What It Is
Kernel: Lists of packet matching rules similar to ipchains/ipfwadm Userspace: program `iptables' and library `libiptc' which access tables Simple functionality (IP header matching) built in Supports multiple tables