312-50V9 · Question #86
What is the outcome of the comm"nc -l -p 2222 | nc 10.1.0.43 1234"?
The correct answer is B. Netcat will listen on port 2222 and output anything received to a remote connection on 10.1.0.43. The piped netcat command creates a relay: the first nc instance listens on port 2222 and pipes all received data directly to a second nc instance that connects to the remote host 10.1.0.43 on port 1234.
Question
What is the outcome of the comm"nc -l -p 2222 | nc 10.1.0.43 1234"?
Options
- ANetcat will listen on the 10.1.0.43 interface for 1234 seconds on port 2222.
- BNetcat will listen on port 2222 and output anything received to a remote connection on 10.1.0.43
- CNetcat will listen for a connection from 10.1.0.43 on port 1234 and output anything received to
- DNetcat will listen on port 2222 and then output anything received to local interface 10.1.0.43.
How the community answered
(16 responses)- A6% (1)
- B81% (13)
- C13% (2)
Why each option
The piped netcat command creates a relay: the first nc instance listens on port 2222 and pipes all received data directly to a second nc instance that connects to the remote host 10.1.0.43 on port 1234.
Netcat does not accept an IP address as an interface filter in listen mode, and port values are not interpreted as time durations.
The command 'nc -l -p 2222' opens a listening socket on local port 2222. The pipe operator forwards its standard output to 'nc 10.1.0.43 1234', which initiates an outbound TCP connection to 10.1.0.43 on port 1234. Any data sent to port 2222 is therefore relayed to the remote host - a classic netcat traffic relay or port-forwarding pattern.
The listening component binds to the local port 2222, not to 10.1.0.43:1234 - the host 10.1.0.43 is the outbound destination of the second nc command, not the source of an inbound connection.
10.1.0.43 is a remote IP address being connected to outbound, not a local interface - netcat is forwarding data to that remote host, not to a local interface.
Concept tested: Netcat piped relay and traffic forwarding
Source: https://linux.die.net/man/1/nc
Topics
Community Discussion
No community discussion yet for this question.