Answer the question
In order to leave comments, you need to log in
How does setup and keep-state work in IPFW?
Handbook quote:
"setup is a required keyword that defines the start of a session request for TCP packets.
keep-state is a required keyword. If it matches, the firewall creates a dynamic rule that will default to match bidirectional traffic between sender and destination for a given IP/port pairs over the specified protocol."
We have such a simple set of closed type rules:
#!/bin/sh
cmd="ipfw -q add"
skip="skipto 800"
pif="em0"
ks="keep-state"
ipfw -q -f flush
# LOCAL
$cmd 010 allow all from any to any via em1
$cmd 020 allow all from any to any via lo0
# NAT IN
$cmd 100 divert natd ip from any to any in via $pif
$cmd 101 check-state
# OUT
$cmd 120 $skip icmp from any to any out via $pif $ks
$cmd 130 $skip udp from any to any 53 out via $pif $ks
$cmd 140 $skip tcp from any to any 53 out via $pif setup $ks
$cmd 150 $skip tcp from any to any 80 out via $pif setup $ks
$cmd 160 $skip tcp from any to any 443 out via $pif setup $ks
# IN
$cmd 300 allow tcp from any to me 22 in via $pif setup $ks
$cmd 700 deny ip from any to any
# SKIPTO
$cmd 800 divert natd ip from any to any out via $pif
$cmd 810 allow ip from any to any
$cmd 900 deny ip from any to any
$cmd 300 allow tcp from any to me 22 in via $pif setup $ks
$cmd 300 allow tcp from any to me 22 in via $pif $ks
Answer the question
In order to leave comments, you need to log in
setup is an optional keyword. setup should be used only when for some reason you need to catch exactly the moment of establishing a TCP session, and do something with this connection (or with the SYN packet itself) in the future. In other words, if the rule contains setup, then it will only be applied to TCP packets with the SYN flag set. This is the very first packet in a TCP session and is used by the client to request a connection.
In this case, as far as I understand, the purpose of using setup is to create a dynamic rule based on the first packet in the TCP connection (SYN packet), and so that all further packets within this connection no longer fall into the rules where ports are checked and created dynamic rules.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question