LFCS · Question #226
What does the following iptables rule accomplish: iptables A INPUT d 10.142.232.1 p tcp dport 20:21 j ACCEPT
The correct answer is D. Forwards all traffic on port 20 and 21 to the host 10.142.232.1. This iptables rule allows incoming TCP traffic on destination ports 20 and 21 to the local host at IP address 10.142.232.1.
Question
Options
- AForwards all traffic not on port 20 or 21 to the host 10.142.232.1.
- BDrops all traffic coming from the host 10.142.232.1 destined for port 20 or 21.
- CAccepts all traffic from the host 10.142.232.1 destined for port 20 or 21.
- DForwards all traffic on port 20 and 21 to the host 10.142.232.1.
How the community answered
(49 responses)- A8% (4)
- B2% (1)
- C4% (2)
- D86% (42)
Why each option
This `iptables` rule allows incoming TCP traffic on destination ports 20 and 21 to the local host at IP address 10.142.232.1.
The rule uses `-j ACCEPT` for specific ports, not for forwarding traffic, and it does not explicitly exclude ports.
The `j ACCEPT` target explicitly allows traffic, it does not drop it. Also, the rule specifies the destination of the local machine, not the source.
The rule specifies the destination IP of the local machine (`-d`), not the source IP. Therefore, it accepts traffic *to* 10.142.232.1, not *from* it.
The `iptables -A INPUT` command adds a rule to the `INPUT` chain, processing packets destined for the local host. The `-d 10.142.232.1` specifies the destination IP of the local machine, `-p tcp` specifies the TCP protocol, and `--dport 20:21` specifies a range of destination ports (20 to 21, inclusive). The `-j ACCEPT` target allows these matching packets.
Concept tested: Iptables rule interpretation (port range, destination)
Source: https://linux.die.net/man/8/iptables
Topics
Community Discussion
No community discussion yet for this question.