Using nc
The netcat command (nc) is a very useful tool for testing network
communications between hosts. It goes one step beyond the ping command
and actually establishes a TCP or UDP connection between two network
hosts. One way to use this command is to open a listening TCP or UDP
socket on one host, and then connect to that socket from another host.
In the following example, I first open a TCP listening socket on one
of the hosts being tested:
openSUSE:/ # nc -l 2388
The
–l option
tells netcat to listen for incoming connections instead of trying to establish a connection with another computer. Because I didn’t specify a protocol, TCP is used by default.
If I wanted to use UDP, I would need to include the
–u option with the command.
I also specified the IP port to listen on (2388).
With a listening socket established on one system, I can then connect
to it from another system and establish a TCP (or UDP) connection
using the nc command again. This time, I enter the following:
[root@fs5 ~]# nc 10.0.0.83 2388
This command tells nc the IP address of the host to connect to and
which IP port to use. Once the connection is established, I can type
text at the prompt of the second system and see if it appears on the
screen of the second system, as shown here:
[root@fs5 ~]# nc 10.0.0.83 2388
This is a test.
openSUSE:/ # nc -l 2388
This is a test.
LX0-104 Exam Objectives (T)
No comments:
Post a Comment