LAB - Chapter 10.0 - Firewall - IPTable
LAB - Chapter 10.0 - Firewall - IPTable
Introduction
Characteristic
IPTable Package
Packet Processing
IPTable Table
o Filter
o NAT
o MANGLE
Practice
21/10/2024 2
1
21/10/2024
21/10/2024 3
21/10/2024 4
2
21/10/2024
21/10/2024 5
3
21/10/2024
You can start, stop, and restart iptables after booting by using the
commands:
o Starting IP tables: service iptables start
o Stopping IP tables: service iptables stop
o Restaring IP tables: service iptables restart
o Checking IP tables status (rulechains): service iptables status
To get iptables configured to start at boot, use the chkconfig
command: chkconfig iptables on
iptables itself is a command which we will see soon.
To show all current rule chains: iptables –-list
To drop all current rule chains: iptables –-flush
2. FILTER: packet filtering, has three builtin chains (your firewall policy rules)
o Forward chain: filters packets to servers protected by firewall
o Input chain: filters packets destinated for the firewall
o Output chain: filters packets orginating from the firewall
4
21/10/2024
PC PC
(source) (source)
Server
(source)
PC PC
(destination) (destination)
21/10/2024
Output chain: filters packets orginating from the firewall9
Server
(forward)
PC PC
(source) (destination)
10
21/10/2024
5
21/10/2024
Each firewall rule inspects each IP packet and then tries to identify it
as the target of some sort of operation. Once a target is identified,
the packet needs to jump over to it for further processing
ACCEPT
o iptables accepts further processing.
o The packet is handed over to the end application or the operating
system for processing
DROP
o iptables stops further processing.
o The packet is blocked.
REJECT
o Works like the DROP target, but will also return an error message to the
host sending the packet that the packet was blocked
--reject-with qualifierQualifier is an ICMP message
LOG
o The packet information is sent to the syslog daemon for logging.
o iptables continues processing with the next rule in the table.
o You can't log and drop at the same time ->use two rules.
--log-prefix ”reason"
SNAT
o Used to do source network address translation rewriting the source IP
address of the packet
o The source IP address is user defined
--to-source <address>[-<address>][:<port>-<port>]
DNAT
o Used to do destination network address translation. ie. rewriting the
destination IP address of the packet
--to-destination ipaddress
MASQUERADE
o Used to do Source Network Address Translation.
o By default the source IP address is the same as that used by the firewall's
interface
[--to-ports <port>[-<port>]]
6
21/10/2024
S
S
S
D
d
21/10/2024 13
7
21/10/2024
8
21/10/2024
Deny ping
iptables -A OUTPUT -p icmp --icmp-type -j REJECT
iptables -A INPUT -p icmp --icmp-type -j DROP
Allow ping request and reply
o iptables is being configured to allow the firewall to send ICMP echo-
requests (pings) and in turn, accept the expected ICMP echo-replies.
iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
o If more than 5 SYN packets per second, the packets are dropped.
o If source/destination sence dropped packets, it will resend three
times
o If drops continue after 3 reset packets, source will reduce packet
speed.
9
21/10/2024
10
21/10/2024
http request
http reply
2. Cấu hình
FILTER: Cho phép/ cấm các giao thức ICMP (ping), HTTP (web),
FTP, telnet
Đi vào LAN – INPUT:
Cho phép HTTP, FTP;
Cấm ICMP, Telnet
Từ mạng LAN ra – OUTPUT:
Cho phép ICMP, Telnet
Cấm HTTP, FTP
FORWARD gói tin
NAT OUT: cho phép máy trong mạng LAN ra ngoài Internet thông
qua Firewall.
11
21/10/2024
http request
ICMP
http reply
Ex:
Out: iptables -A OUTPUT -p icmp -j REJECT (DROP)
In: iptables -A INPUT -p icmp -j REJECT (DROP)
Filter: Forward
Server
(forward)
PC PC
(source) (destination)
21/10/2024 24
12
21/10/2024
IPTable – NATOUT
Ra 1 mạng khác:
Iptables –t nat -A POSTROUTING -o eth0 -s 172.16.1.0/24 -j SNAT --to 192.168.1.2
Hoặc ra internet:
Iptables –t nat -A POSROUTING -s 172.16.1.0/24 –o eth0 –j MASQUERADE
21/10/2024 26
13