nerdexam
Linux_Foundation

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.

Submitted by satoshi_tk· Apr 18, 2026Networking

Question

What does the following iptables rule accomplish: iptables A INPUT d 10.142.232.1 p tcp dport 20:21 j ACCEPT

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)
  • A
    8% (4)
  • B
    2% (1)
  • C
    4% (2)
  • D
    86% (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.

AForwards all traffic not on port 20 or 21 to the host 10.142.232.1.

The rule uses `-j ACCEPT` for specific ports, not for forwarding traffic, and it does not explicitly exclude ports.

BDrops all traffic coming from the host 10.142.232.1 destined for port 20 or 21.

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.

CAccepts all traffic from the host 10.142.232.1 destined for port 20 or 21.

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.

DForwards all traffic on port 20 and 21 to the host 10.142.232.1.Correct

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

#iptables#Firewall#Networking#TCP/IP ports

Community Discussion

No community discussion yet for this question.

Full LFCS Practice