Open Source

Learn the many uses of netcat

The netcat tool allows admins to read and write TCP or UDP data across the network. It also helps with network debugging and testing. Learn more about netcat.

Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

Often referred to as the "Swiss Army Knife of networking," netcat is a tool that administrators can use to read and write TCP or UDP data across the network. In addition, it's extremely useful for network debugging and testing.

Netcat offers several interesting uses. For example, you can make it listen to a particular port and run a program. To do so, use the following:

$ netcat -v -l -p 10111 -e "/bin/cat /etc/motd"

This tells netcat to listen to port 10111. When there's a connection, it tells netcat to execute "/bin/cat /etc/motd," which essentially displays the contents of /etc/motd and exits.

You can also set up netcat on a machine to listen for incoming connections and run it on a remote machine to connect to the local machine and serve up a bash shell. For example, on a local machine with an IP address of, you would use the following:

$ netcat -v -l -p 10111

On the remote machine, you would use:

$ netcat 10111 -e /bin/bash

This tells the netcat instance on the remote machine to connect to the netcat instance listening on and serve up a bash shell from the remote machine, which will then be available on the local machine. Using the netcat instance on, you can execute shell commands on the remote host.

To perform some Web debugging, you could use something like the following:

$ netcat 80

Then, enter typical HTTP commands to get the unaltered output (e.g., "GET / HTTP 1.0").

As you can see, netcat is both an extremely versatile and very powerful utility. You can download this useful tool, based on the original netcat program, from the GNU Netcat Project Web site.

About Vincent Danen

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

Editor's Picks