What is the difference in an iptable rule when i don't a state? E.g.
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
What's the default state (if any) in the second rule?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityThere isn't a default state value. If the state match missed in the rule, the state value isn't checked. This logic is applied to any iptables match (addresses, protocols, port numbers, interfaces etc).
So, the difference between these two rules is in that, what the second rule matches and accept all the input packets to port tcp/22
(standard ssh service port number). First rule matches only first (initial) incoming packets of connections to ssh port, but not next packets.
To get the introduction to the related netfilter/iptables concepts read the iptables tutorial:
-m state --state ESTABLISHED,RELATED -j ACCEPT
. Other rules is the -m state --state NEW -j ACCEPT
. So the most part of packets is accepted by first rule, but only small part of packets is accepted by the next rules, those allow the first packets of connections. This way improves the performance.
Aug 25, 2019 at 9:31
The --state NEW
will only match new connection, if it is TCP packet, it match SYN
packet.
If you don't have a rule like
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
The --state NEW
rule will not match the packet after TCP SYN
handshake.
For more detail: iptables doc
--state ESTABLISHED
rule is added, then the following packets of the TCP connection will match this rule. The packets will not match the --state NEW
rule. The --state NEW
rule matches only the TCP SYN packet.
Aug 25, 2019 at 8:33
state
is deprecated and replaced byconntrack
which supports mostly the same flags...