Installing netcat on linux

Содержание
  1. How to Install netcat(nc) command on Linux (RedHat/CentOS 7/8) in 5 Easy Steps
  2. Install Netcat(nc) Command on Linux
  3. Step 1: Prerequisites
  4. Step 2: Update Your System
  5. Step 3: Install Netcat Package
  6. Step 4: Verify netcat package installation
  7. Step 5: Test nc command
  8. How to Use Netcat Commands with Examples
  9. How to install netcat
  10. How to install netcat from source code
  11. Netcat Examples
  12. 1) Test if a particular TCP port of a remote host is open
  13. 2) Perform TCP port scanning against a remote host
  14. 3) Perform UDP port scanning against a remote host
  15. 4) Send a test UDP packet to a remote host
  16. 5) Copy a file (e.g., test.txt) from one host to another
  17. 6) Transfer a whole directory (including its content) from one host to another
  18. 7) Create a compressed backup of hard drive (e.g., /dev/sdc) on a remote host
  19. 8) Restore a hard drive (e.g. /dev/sdc) from a compressed disk image stored in a remote host
  20. 9) Run insecure online chat between two hosts
  21. 10) Run a web server with a static web page
  22. 11) Listen on a TCP port using IPv6 address
  23. 12) Stream a video file from a server for client to watch the streamed video using video player (e.g., mplayer)
  24. Read Also:
  25. Landoflinux
  26. Linux netcat — nc command examples
  27. netcat — nc — Utility
  28. Installing netcat on Ubuntu/Mint
  29. Installing nmap-netcat on RHEL/CentOS Systems
  30. Examples of netcat utility
  31. Checking for an Open Port
  32. netcat as a Port Scanner
  33. Port Scanning UDP ports
  34. Having a Chat with Netcat
  35. For more information regarding netcat/nc command
  36. Installing netcat on linux
  37. Installation method 1: yum installation
  38. Installation method 2: compile and install

How to Install netcat(nc) command on Linux (RedHat/CentOS 7/8) in 5 Easy Steps

Table of Contents

In this article, i will take you through the steps to install netcat command in Linux. nc command in Linux can be used for variety of purposes like checking the status of remote ports, initiating chat services between server and client, start listening on some ports for incoming connections etc. Now a days there are lot of open source networking tools available in Linux Based Systems to perform network troubleshooting activity. netcat is one such tool.

In this session we will only look into the steps to install netcat on RedHat Based Systems. I will cover other networking tools in future articles. Since netcat package does not comes by default in RedHat Based systems, so we need to install it manually using below steps.

Install Netcat(nc) Command on Linux

Step 1: Prerequisites

a)You need to have a running RedHat/CentOS 7/8 System.

b)You should have sudo access to install netcat package.

c)Also you need to have yum command installed in your system.

Step 2: Update Your System

You need update all the packages to use latest updates before proceeding with the netcat package installation. Packages can be updated by running yum install -y command as shown below. In this case, since system has all the latest updates installed hence there are no further updates available to install.

Step 3: Install Netcat Package

Once system is updated you can install netcat package using yum install -y nc command as shown below. This command will also install any dependent packages which needs to be installed with netcat package.

Step 4: Verify netcat package installation

After successful installation of netcat package, you can check the rpm db to confirm if the netcat package is installed successfully using rpm command as shown below.

Step 5: Test nc command

Now that we have netcat package installed successfully in the System, you can quickly verify the functionality of nc command by checking google.com port 443 as shown below. As you can check in the below output, system is currently able to reach to google.com on port 443.

-v : Set verbosity level (can be used several times)

z : Zero-I/O mode, report connection status only

Check other options that can be used with nc command using -h flag as shown below.

Читайте также:  Журнал работы системы windows

I hope you liked this article on How to Install netcat command in Linux. Please let me know your feedback on Comment Box.

Popular Recommendations:-

Источник

How to Use Netcat Commands with Examples

Netcat (nc) command is a powerful tool to analyze network connections, scan for open ports, transfer data etc. It is a networking utility for reading from and writing to network connections using TCP or UDP protocols.

How to install netcat

Its is a cross-platform tool and it is available for Linux, macOS, Windows and BSD. We are going to install netcat on Ubuntu 18.04 machine using apt install or compiling it from source code.

Installation using apt is pretty simple, you just need to type the following command in the terminal:

On CentOS 8

The ncat can be installed with nmap package on RHEL 8/CentOS 8. Use dnf command as below

How to install netcat from source code

Compiling netcat from source code is not as easy as installing via apt install , but if you follow the steps below you can install it easily.

Download the source code from netcat website with the following command

Extract the newly downloaded archive. To do so you can run:

cd to the directory containing the package’s source code and type ./configure to configure the package for your system.

If you are getting error message like this — «no acceptable C compiler found in $PATH» when running ./configure command, make sure you have installed gcc compiler. To install it type the following command:

Running configure takes awhile.

Once configure has been successfully finished run:

You can remove the program binaries and object files from the source code directory by typing make clean . To also remove the files that configure created, run make distclean command.

Netcat Examples

Before starting to explore some netcat commands it’s important to know that if you are binding to well-known ports (0-1023) with nc, you need root privilege. Otherwise, you can run nc as a normal user.

1) Test if a particular TCP port of a remote host is open

Output if the 2424 port on remote server is closed

Output if the port on remote server is opened (e.g. 22 port)

2) Perform TCP port scanning against a remote host

The command below will check the ports from 20 to 25 on the remote host and print the result.

Output will look like this

3) Perform UDP port scanning against a remote host

Output will show only the ports which allow udp connections.

4) Send a test UDP packet to a remote host

The command above will send a test UDP packet with 1 second timeout to a remote host at port 2424

5) Copy a file (e.g., test.txt) from one host to another

On the receiver host (192.168.40.146 in my case) run:

On the sender host (192.168.40.144) run the following command:

This will copy test.txt file from sender host to receiver host via 2424 port. make sure to allow incoming connections on 2424 port on the receiver host.

6) Transfer a whole directory (including its content) from one host to another

On the receiver host run:

On the sender host run the following command:

7) Create a compressed backup of hard drive (e.g., /dev/sdc) on a remote host

On the remote host run:

On the local host run the following command:

8) Restore a hard drive (e.g. /dev/sdc) from a compressed disk image stored in a remote host

On the local host run:

On the remote host run the following command:

9) Run insecure online chat between two hosts

On one host (e.g. 192.168.40.144) run the command below:

On another host (e.g. 192.168.40.146) run the following command:

After running these commands, anything typed in both terminals will be seen on both host machines.

10) Run a web server with a static web page

Run the command below on local host (e.g. 192.168.40.144) to start a web server that serves test.html on port 80. Note that you must run with sudo privileges as 80 is in range of well known ports (1-1023)

Читайте также:  Windows 10 игнорирует маршруты

Now open http://192.168.40.144/test.html from another host to access it.

11) Listen on a TCP port using IPv6 address

You can use the following command to allow nc use IPv6 address when listening on a TCP port.

Check if it works with the command below

Output will look like this

12) Stream a video file from a server for client to watch the streamed video using video player (e.g., mplayer)

On a video server (192.168.40.144):

On a client host (192.168.40.146):

nc 192.168.40.144 2424 | mplayer -vo x11 -cache 3000 —

Read Also:

As you can see netcat is a great tool for TCP/IP networking and it is one of the most favorite tools of sysadmins when it comes to do networking related troubleshooting and experimentation. That’s why a lot of Linux distros are being delivered with preinstalled netcat.

Источник

Landoflinux

Linux netcat — nc command examples

netcat — nc — Utility

The netcat utility or nc is often referred to as the Swiss Army Knife for working with TCP/IP networks. This tool is very popular amongst System Administrators and Network Administrators because of its wide range of capabilities. The netcat utility is used for almost anything under the sun involving TCP, UDP, or UNIX-domain sockets. Netcat can open TCP connections, send UDP packets of data, listen on arbitrary TCP and UDP ports, carry out port scanning, transfer data from one server to another. In the following examples I will be using a Linux Mint system and a CentOS system.

Installing netcat on Ubuntu/Mint

If you need to install netcat, you can use the following commands:

Installing nmap-netcat on RHEL/CentOS Systems

On RHEL 8 and CentOS 8 systems, «netcat» has been replaced by a package called «nmap-ncat«. To install this package, issue the following command:

dnf install nmap-ncat -y

Examples of netcat utility

In the following examples we will take a quick look at some of the popular uses of netcat/nmap-ncat.

Checking for an Open Port

In this example we will use netcat to interrogate a port to see if it is open. We will use the netcat command in conjunction with the «-v» and «-n» flags. The «-v» flag specifies that we would like verbose output (more detailed). The «-n» option specifies that we do not wish to use DNS or service lookups on any addresses, hostnames or ports.

Example Command: nc -vn 192.168.122.75 22

In the above example we have specified the IP address of a CentOS 8 server followed by the port we wish to interrogate. In this example we are looking at port 22 (normally used for ssh).

As we can see from the output port 22 is open for connections. If we now check for a port which is closed, you will see the difference in the output from the command:

netcat as a Port Scanner

Another popular use of the netcat command is to use it as a port scanner. In this example we will be using the flags «-w» and «-z» in addition to the «-v» and «-n» flags. The «-w» flag is used to specify a timeout limit. By default, netcat will listen forever, however, in this example we are going to use a more realistic value of «1» second. The «-z» flag specifies that netcat should scan for listening daemons without sending any data. We will also specify a range of ports to check. In this example we are only going to check ports 1 through to 30.

Example Command: nc -vnz -w 1 192.168.122.75 1-30

We can see from the above output that a connection to port 22 has succeeded.

You can also specify more than one port to scan.

Читайте также:  Символические ссылки linux примеры

Example Command: nc -vnz -w 1 192.168.122.75 20 21 22 23 24 25

In the above example, we are going to scan ports «20, 21, 22, 23, 24 and 25».

Port Scanning UDP ports

In this example we are going to specify «UDP» ports to be scanned. To specify UDP we will use the «-u» flag. In the example below we are going to scan ports «60 through to 80».

Example Command: nc -vnzu -w 1 192.168.0.33 60-80

Having a Chat with Netcat

In this example we will use a Linux Mint 20 terminal and connect this to a remote terminal on a CentOS 8 Server.

On the Linux Mint system, we need to identify the IP address. This can be done by issuing the command: ip a s

From the above we can see that the IP address in use on interface «enp1s0» is «192.168.0.33«.

This IP address is needed by the CentOS server. Now, on the Linux Mint system we issue the following command:

nc -lp 2468. Here we are instructing netcat to listen on port 2468.

Now on the remote CentOS server we issue the following command:

nc 192.168.0.33 2468

Here we are telling our CentOS server to make a connection to our Linux Mint system on port 2468.

Now any text typed on one terminal will now appear on the other terminal screen. (Warning, this is not a secure way to chat!)

Linux Mint System

CentOS Server

For more information regarding netcat/nc command

As always a vast amount of information can be looked at via the man pages. To view more information regarding netcat/nc, issue the command: man nc

Источник

Installing netcat on linux

NetCat (hereinafter referred to as nc), which has the reputation of «Swiss Army Knife» among network tools, is still in our hands after we have used it for N years. Because it is short and powerful (this is very suitable for it, some people have modified it to about 10K, and the function is not reduced).
A simple and useful tool to read and write data through a network connection using TCP or UDP protocol. It is designed as a stable backdoor tool that can be easily driven directly by other programs and scripts.

Installation method 1: yum installation

yum install -y netcat
or
yum install -y nc

Installation method 2: compile and install

1. Download
2. Upload to linux server and unzip

Go to the directory where netcat-0.7.1.tar.gz is located and execute the following command:
tar -zxvf netcat-0.7.1.tar.gz -C /usr/local/

3. Compile and install netcat

Enter the unzipped directory
cd /usr/local/netcat-0.7.1/

Execute the command to compile and install:
[[email protected] netcat-0.7.1]# ./configure –prefix=/usr/local/netcat

出 现 以 下 错 误 : » role=»presentation»> Out Now To under wrong error :

The cause of the error is that there is no gcc compiler, you can install gcc using yum
[[email protected] netcat-0.7.1]# yum install -y gcc

do it again
[[email protected] netcat-0.7.1]# ./configure –prefix=/usr/local/netcat

Compile and install
[[email protected] netcat-0.7.1]# make && make install

Compile and install successfully, enter the netcat directory:
[[email protected] netcat-0.7.1]# cd /usr/local/netcat
[[email protected] netcat]# ll
total 16
drwxr-xr-x. 2 root root 4096 Aug 1 20:40 bin
drwxr-xr-x. 2 root root 4096 Aug 1 20:40 info
drwxr-xr-x. 3 root root 4096 Aug 1 20:40 man
drwxr-xr-x. 3 root root 4096 Aug 1 20:40 share

注 : 此 处 的 / u s r / l o c a l / n e t c a t − 0.7.1 / 相 当 于 源 码 文 件 , 安 装 成 功 的 文 件 是 / u s r / l o c a l / n e t c a t , 这 里 可 以 将 / u s r / l o c a l / n e t c a t − 0.7.1 / 删 除 » role=»presentation»> Note : this Place of / u s r / l o c a l / n e t c a t − 0.7.1 / phase when to source code Text Piece , An Outfit to make Merit of Text Piece Yes / u s r / l o c a l / n e t c a t , This in can To will / u s r / l o c a l / n e t c a t − 0.7.1 / delete except

4. Configure environment variables

Reload the configuration file:
[[email protected] netcat]# source /etc/profile

Источник

Оцените статью