- Cheat Sheet and Example is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools






Linux Commands#network

nc(netcat) - How to use nc(netcat) command in Linux with examples

nc Command Hlep

I cann't find “-e” option with my Linux server.

# nc -h
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port]
          [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version]
          [-x proxy_address[:port]] [hostname] [port[s]]
        Command Summary:
                -4              Use IPv4
                -6              Use IPv6
                -D              Enable the debug socket option
                -d              Detach from stdin
                -h              This help text
                -i secs         Delay interval for lines sent, ports scanned
                -k              Keep inbound sockets open for multiple connects
                -l              Listen mode, for inbound connects
                -n              Suppress name/port resolutions
                -p port         Specify local port for remote connects
                -r              Randomize remote ports
                -s addr         Local source address
                -T ToS          Set IP Type of Service
                -C              Send CRLF as line-ending
                -t              Answer TELNET negotiation
                -U              Use UNIX domain socket
                -u              UDP mode
                -v              Verbose
                -w secs         Timeout for connects and final net reads
                -X proto        Proxy protocol: "4", "5" (SOCKS) or "connect"
                -x addr[:port]  Specify proxy address and port
                -z              Zero-I/O mode [used for scanning]
        Port numbers can be individual or ranges: lo-hi [inclusive]
# man nc

       ncat - Concatenate and redirect sockets

       ncat [OPTIONS...] [hostname] [port]


Port Scan

# nc  xx.xx.xx.xx 22    <- TCP

#nc 23
Ncat: Connection refused.

# nc 22
# nc  -u xx.xx.xx.xx   53   <- UDP
# nc -vz  22
Connection to 22 port [tcp/ssh] succeeded!
# nc -vz 1-1023  <- Check port from 1 to 1023
nc: connect to port 1 (tcp) failed: Connection refused
nc: connect to port 2 (tcp) failed: Connection refused
nc: connect to port 3 (tcp) failed: Connection refused
nc: connect to port 4 (tcp) failed: Connection refused
nc: connect to port 5 (tcp) failed: Connection refused
nc: connect to port 6 (tcp) failed: Connection refused
# echo -en "GET / HTTP/1.1\n\n" | nc xx.xx.xx.xx  80

Simple Web Server

# while true; do ( echo "HTTP/1.0 200 Ok"; echo; echo "Hello World" ) | nc -l 80; [ $? != 0 ] && break; done

Check Firewall


Server1# nc -l  12345    <- Listening Port 12345
Server2# nc Server1 12345  <- Connection Server1 Port 12345
aaa      <- push character 'aaa'
Server1# nc -l 12345
aaa                       <- Listen caracter 'aaa'


Server1# nc -l -p 1234  -e /bin/sh   <- Listening Port 1234
Server2# nc Server1 1234  <- Connection Server1 Port 1234
uname -a      <- push 'uname -a' command
Linux AAAA2.4.2-2  <- listen Server1's 'uname -a'

os/linux/command/netcat.html.txt · Last modified: 2019/09/18 by admin

Page Tools