Check whether INPUT contains a rule accepting TCP port 22 without adding or deleting rules.
Which command is appropriate?
iptables -C checks whether a specified rule exists in a chain without changing it.
Detailed explanation
iptables -A INPUT -p tcp --dport 22 -j ACCEPTIncorrect. -A appends the allow rule.
Incorrect. -A appends the allow rule.
iptables -D INPUT -p tcp --dport 22 -j ACCEPTIncorrect. -D deletes a matching rule.
Incorrect. -D deletes a matching rule.
iptables -L INPUT --dport 22Incorrect. -L does not take --dport as a direct filter in this form.
Incorrect. -L does not take --dport as a direct filter in this form.
iptables -C INPUT -p tcp --dport 22 -j ACCEPTCorrect. -C checks for the exact rule.
Correct. -C checks for the exact rule.
Try it yourself
An example you can run in a temporary verification environment.
iptables --help 2>&1 | grep -E -- '^-C|check' | head -n 2Expected result
check ruleまたは-Cに関するhelp行Key points
- -C is check
- -A adds
- -D deletes
Notes
- Environment: iptables help / rule変更なし
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.