CompTIA Linux+ (XK0-005) — Question 137
A DevOps engineer needs to allow incoming traffic to ports in the range of 4000 to 5000 on a Linux server. Which of the following commands will enforce this rule?
Answer options
- A. iptables -f filter -I INPUT -p tcp --dport 4000:5000 -A ACCEPT
- B. iptables -t filter -A INPUT -p tcp --dport 4000:5000 -j ACCEPT
- C. iptables filter -A INPUT -p tcp --dport 4000:5000 -D ACCEPT
- D. iptables filter -S INPUT -p tcp --dport 4000:5000 -A ACCEPT
Correct answer: B
Explanation
The correct command is B because it uses the correct syntax with the '-t' option to specify the filter table and the '-j' option to accept the traffic. Option A incorrectly uses '-I' which inserts a rule rather than appending it, and option C uses an invalid '-D' option which is meant for deleting rules. Option D uses '-S' which is intended for listing rules, not adding them.