Skip to content
KMyFirewall
Release 1.1.1 Download

The KMyFirewall Handbook

Checking the protocol

The protocol option matches the protocol of a packet. It accepts tcp, udp, icmp or all, a numeric value, or a name from /etc/protocols.

iptables ‑A INPUT ‑‑protocol tcp ‑j ACCEPT
iptables ‑A INPUT ‑‑protocol ! udp ‑j LOG

A ! before the protocol inverts the test. The number zero is equivalent to all. Protocol all matches every protocol and is the default when the option is omitted.

TCP specific options

TCP options inspect the TCP header, including source and destination ports, connection tracking, and TCP flags.

Source and destination ports

iptables ‑A INPUT ‑‑protocol tcp ‑‑source‑port 22:12 ‑j LOG
iptables ‑A POSTROUTING ‑‑protocol tcp ‑‑destination‑port ! 21232 ‑j DROP

TCP flags

iptables ‑A INPUT ‑‑protocol tcp ‑‑tcp‑flags ! SYN,ACK,FIN SYN,ACK ‑j LOG

Flags are SYN, ACK, FIN, RST, URG, PSH, ALL and NONE. The first list names the flags to examine, the second names the flags that must be set.

TCP options

iptables ‑A INPUT ‑‑protocol tcp ‑‑tcp‑option 0 ‑j LOG

UDP specific options

UDP does not provide a stateful connection, so its packets are anonymous and easy to fake. It is very fast and is used by DNS and NFS, among others.

iptables ‑A INPUT ‑‑protocol udp ‑‑source‑port 22:12 ‑j LOG
iptables ‑A POSTROUTING ‑‑protocol udp ‑‑destination‑port ! 21232 ‑j DROP

ICMP

The Internet Control Message Protocol carries control messages such as host unreachable, echo request (ping) and source quench.

iptables ‑A INPUT ‑‑protocol icmp ‑‑icmp‑type echo‑request ‑j LOG

Use iptables ‑p icmp ‑h to list the allowed type names.

Multiport match extension

The multiport extension allows up to 15 ports in a comma separated list within a TCP or UDP rule.

iptables ‑A INPUT ‑‑protocol tcp ‑‑match multiport ‑‑source‑ports 22,21,20,80 ‑j LOG
iptables ‑A INPUT ‑‑protocol udp ‑‑match multiport ‑‑destination‑ports 20,80,10 ‑j LOG
iptables ‑A INPUT ‑‑protocol tcp ‑‑match multiport ‑‑ports 20,50,1660 ‑j LOG

Continue with Incoming and outgoing interface.

Back to top