does adding a rule to iptables mean it takes effect immediately?
Solution 1:
Yes, adding rules via the iptables command takes effect immediately.
Presumably you want to add an ACCEPT rule for the port because you want to override rule that blocks all or most ports.
However, you have added the rule with -A
which would append the rule to the table. Since you already have a blocking rule (using something like DROP or REJECT), the new rule would be added after that, making it ineffective.
If you want this to work, you need to either insert the rule (-I #) before the blocking rule, or add the rule to the correct position in a config file and reload all rules. (Or use something like ufw or firewalld to do this for you). You can get a numbered list of rules with iptables --line-numbers -L INPUT
and insert your new rule at or before the position of your blocking rule.
If the assumption that you have a blocking rule is wrong, then you need to go back and check if anything even has the port open. You can use netstat -nl | grep 2222
or ss -nlt | grep 2222
and if it isn't listed, then there is nothing listening on the port.
From the output you added to your question, the INPUT table is basically empty (except for your accept rule) and -P INPUT ACCEPT
says accept anything that doesn't match rules in the input table.