Questo contenuto non è disponibile nella lingua selezionata.

1.7. Managing Data Using the ncat utility


The ncat networking utility replaces netcat in Red Hat Enterprise Linux 7. ncat is a reliable back-end tool that provides network connectivity to other applications and users. It reads and writes data across the network from the command line, and uses Transmission Control Protocol (TCP), User Datagram Protocol (UDP), Stream Control Transmission Protocol (SCTP) or Unix sockets for communication. ncat can deal with both IPv4 and IPv6, open connections, send packets, perform port scanning, and supports higher-level features such as SSL, and connection broker.
The nc command can also be entered as ncat, using the identical options. For more information about the ncat options, see the New networking utility (ncat) section in the Migration Planning Guide and the ncat(1) man page.

Installing ncat

To install the ncat package, enter as root:
~]# yum install ncat
Copy to Clipboard Toggle word wrap

Brief Selection of ncat Use Cases

Example 1.1. Enabling Communication between a Client and a Server

  1. Set a client machine to listen for connections on TCP port 8080:
    ~]$ ncat -l 8080
    Copy to Clipboard Toggle word wrap
  2. On a server machine, specify the IP address of the client and use the same port number:
    ~]$ ncat 10.0.11.60 8080
    Copy to Clipboard Toggle word wrap
    You can send messages on either side of the connection and they appear on both local and remote machines.
  3. Press Ctrl+D to close the TCP connection.

Note

To check a UDP port, use the same nc commands with the –u option. For example:
~]$ ncat -u -l 8080
Copy to Clipboard Toggle word wrap

Example 1.2. Sending Files

Instead of printing information on the screen, as mentioned in the previous example, you can send all information to a file. For example, to send a file over TCP port 8080 from a client to a server:
  1. On a client machine, to listen a specific port transferring a file to the server machine:
    ~]$  ncat -l 8080 > outputfile
    Copy to Clipboard Toggle word wrap
  2. On a server machine, specify the IP address of the client, the port and the file which is to be transferred:
    ~]$  ncat -l 10.0.11.60 8080 < inputfile
    Copy to Clipboard Toggle word wrap
After the file is transferred, the connection closes automatically.

Note

You can transfer a file in the other direction as well:
~]$  ncat -l 8080 < inputfile
Copy to Clipboard Toggle word wrap
~]$  ncat -l 10.0.11.60 8080 > outputfile
Copy to Clipboard Toggle word wrap

Example 1.3. Creating an HTTP proxy server

To create an HTTP proxy server on localhost port 8080:
~]$  ncat -l --proxy-type http localhost 8080 
Copy to Clipboard Toggle word wrap

Example 1.4. Port Scanning

To view which ports are open, use the –z option and specify a range of ports to scan:
~]$  ncat -z 10.0.11.60 80-90
    Connection to 192.168.0.1 80 port [tcp/http] succeeded!
Copy to Clipboard Toggle word wrap

Example 1.5. Setting up Secure Client-Server Communication Using SSL

Set up SSL on a server:
~]$ ncat -e /bin/bash -k -l 8080 --ssl
Copy to Clipboard Toggle word wrap
On a client machine:
~]$ ncat --ssl 10.0.11.60 8080 
Copy to Clipboard Toggle word wrap

Note

To ensure true confidentiality of the SSL connection, the server requires the --ssl-cert and --ssl-key options, and the client requires the --ssl-verify and --ssl-trustfile options. For information on OpenSSL, see the Using OpenSSL section in the Security Guide.
For more examples, see the ncat(1) man page.
Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat