You are on page 1of 37

Firewalls

Firewalls protect our network from the


world
Firewalls protect our network from us

Firewall Architecture
Basic

External
Servers

External
Clients

External public network

Firewall

Internet

Public
Servers

Internal
Servers

Internal
Clients

Internal Private Network

Firewall Architecture
Layered
External
Servers

Internal
Servers

Interior firewall

External
Clients

Exterior firewall

Internet

Public
Servers

Screened Service
Network

Internal
Clients

Internal Private Network


External Public Network

Firewall Architecture
Enterprise
Public Network
External DNS
SMTP Server

Protected Network
Internal
Servers

Web Server

Internal DNS
Mail Server
IDS

Intern
et

Exterior
Firewall

Interior
Firewall

Logging
Alerting
Server

Internal
Clients

Packet Filters
Linux
IPChains

Static packet inspection

Red Hat 7.3 and earlier


Inspects fields in the packet

Maintains a rule set

IPTables

Statefull packet inspection

Red Hat 7.0 and later


Inspects fields and state consistency of the packet

Maintains a rule set

iptables
Stateful Packet Filters
Keeps track of the state of each connection

Concept of state in common protocols


iptables command

IPTables
Uses most of the command structure of ipchains
Uses some of the architecture of ipchains
Topics
Command structure
Parameters
Simple tables

IPTables
Three tables each consists of one or more
chains
filter
nat
mangle

Filter Table
Consists of three chains
FORWARD

For packets forwarded from one network


interface to another network interface
INPUT

For packets sent to firewall host


OUTPUT
For packets sent by firewall host

NAT Table
NAT Network Address Translation
PREROUTING
Destination NAT operations

POSTROUTING
Source NAT operations

Mangle Table
Enables the modification of the TOS or the TTL field
and used for load balancing when there are multiple
firewalls
PREROUTING, OUTPUT chains
Kernel <= 2.4.17
PREROUTING, INPUT, FOREWARDING, OUTPUT and
POSTROUTING chains
Kernel >= 2.4.18

User Chains

Chains of rules
Associated with a specific table
A packet can be diverted to a user chain
The packet is returned to the step after
it's diversion

Packet Path
Network

mangle
PREROUTING

filter
INPUT

filter
OUTPUT

nat
PREROUTING

Local
Process

nat
POSTROUTING

route

Mangle
OUTPUT

Network

filter
FORWARD

Command Structure
Iptables operation chain specs -j target flags

Rule Operations

-I
-A
-D
-R

Add a rule to the head of a chain


Appends a rule to the tail of a chain
Deletes a rule that matches the specifiers
Replaces a rule in a chain

Syntax
iptables -t table -OP chain specifiers
iptables -t table -OP chain line# specifiers
iptables -OP chain specifiers

Chain Operations
Listing a chain
iptables -t table -L chain
iptables -L chain
iptables -L

Flags
-n
addr/port numbers rather than names
-v
verbose
--line-numbers
include line numbers in the listing

Chain Operations
cont'd

Flushing a chain
Deletes all rules associated with a chain
iptables -t table -F chain
iptables -F chain
iptables -F

Setting the default policy of a chain


(filter)
iptables -P chain policy
policy DROP, ACCEPT, REJECT

Chain Operations
cont'd
Creating a user chain
iptables -t table -N chain
iptables -N chain

Deleting a user chain


iptables -t table -X chain
iptables -X chain
iptables -X

Renaming a user chain


iptables -t table -E old new
iptables -E old new

Chain Operations
cont'd

Chain counter
Iptables maintains a set of counters for each rule
Counts the number of packets and bytes
processed by each rule

Zeroing a chain's counters


iptables -t table -Z chain
iptables -Z chain
iptables -Z

Packet characteristics
specs

Protocol
Source IP
Destination IP
Input Interface
Output interface
Frag flag

TCP Datagrams

Src port
Dest port
Flags
TCP options

UDP Datagrams

Src port
Dest port

ICMP Messages

Type and code

Protocol field
Protocol name: tcp,udp,icmp
/etc/protocols
Protocol number

0 or all
-p tcp, udp
-p ! tcp
-p all

icmp Type and Code


RFC 792

-p icmp icmp-type echorequest


Examples

echo-request
echo-reply
destination-unreachable
source-quench
time-exceeded

Private IP Addresses
10.0.0.0
172.16.0.0
192.168.0.0

10.255.255.255 (10/8 prefix)


172.31.255.255 (172.16/12 prefix)
192.168.255.255 (192.168/16 prefix)

Source/Destination
IP Address

-s -d - source destination
-s 1.2.3.4
-s 192.168.0.1/255.255.255.0
IP address/network mask
Specifies a range of IP addresses

-s 192.168.0.0/24
Specifies a range of addresses
192.168.0.0 192.168.0.255

-s ! 10.0.0.0/8
Everything except 10.0.0.010.255.255.255

Interface
-i Input interface
Only in INPUT, FORWARD, PREROUTING chains

-i
-i
-i
-i

eth0
! eth0
eth+
lo

except eth0
all ethernet interfaces
loop back interface

-o Output interface
Only in OUTPUT, FORWARD, POSTROUTING chains

Fragment
-f
! -f

frag flag is set


frag flag is not set

Port specs
--sport
--dport

-p
-p
-p
-p
-p

Source port
Destination port

tcp --sport 80
udp -dport 53
tcp,udp --sport 0:1023
tcp,udp --sport 1024
tcp,udp -dport 1024:

SYN
Tests tcp packets for SYN to be set and
ACK and FIN not set
-p tcp -syn
Filters all packets requesting tcp connection

-p tcp ! --syn

TCP Flags
-p tcp tcp-flags SYN,ACK,FIN SYN
Tests SYN, ACK, FIN flags to see if the SYN bit is the
only flag set
Possible flags
ACK
FIN
RST
PSH
SYN
URG

Connection State
-m state -state state-specifier

State-specifiers
NEW
Associated with a connection request
ESTABLISHED
Associated with an established connection
RELATED
Associated with a new connection request
related to an established connection (ftp,
icmp)
INVALID
Associated with a bad connection or is
malformed

Rate Limits
-m limit -limit rate/unit

rate/unit
rate
Packets per unit time
unit
Second, minute, hour, day
-m limit -time-burst number -limit rate/unit
number max permitted burst before rate limit is
applied

Targets/Actions
Target types
Firewall actions filter table chains & user
defined
ACCEPT, DROP, REJECT, LOG, RETURN

NAT support
DNAT, MASQ, REDIRECT, SNAT

Uncommon targets
MARK, MIRROR, QUEUE, TOS, TTL,
ULOG

Firewall Actions
iptables operation specification -j target

If the packet does not match the specification


the packet is handed off to the next rule in the
chain
If the packet meets the specification then the
rule is passed to the target

Firewall Actions
cont'd

-j ACCEPT
Lets the packet satisfying the specification pass
to the next chain in the packet path

-j DROP
The packet satisfying the specification is dropped
with no error packet sent to the sender
Stealth mode used for packet blocking on
sensitive hosts

Firewall Actions
cont'd
-j REJECT
The packet satisfying the specification is dropped with an error
packet sent to the sender
-j REJECT default error is port unreachable
-j REJECT --reject-with flag

icmp-net-unreachable
icmp-host-unreachable
icmp-port-unreachable
Icmp-proto-unreachable
icmp-net-prohibited
icmp-host-prohibited
tcp-reset

Sends a tcp packet with the RST bit set

Firewall Actions
cont'd
-j LOG
Causes the packet satisfying the specification to be logged using
the Syslog facility
--log-prefix IPT description of entry
IPT identifies the source of the log entry, i.e. Iptables
Description within quotes is limited to 29 characters

--log-ip-options
--log-level
--log-tcp-options
--log-tcp-sequence
To log a dropped packet a log rule must precede the dropping rule

Firewall Actions
cont'd

-j user-chain-name
Lets the packet satisfying the specification pass
to the named user chain

-j RETURN
Used in the user chain to return to the calling
chain

You might also like