When troubleshooting a network integration or any other connection issue in Linux, step one is usually a matter of checking to see if the network port on the other side is even responding.
Netcat -The network Swiss Army knife (Hobbit, not nmap)- is the right tool for the job.
Before we begin, NetCat needs to be installed.
# RHEL / CentOS
~$ yum install nc
# Debian / Ubuntu
~$ apt-get install nc
Once installed, you can invoke Netcat like so:
~$ nc [REMOTE_SERVER] [PORT]
[REMOTE_SERVER] – The server to be checked
[PORT] – The service/port to be checked
Connection to google.com 443 port [tcp/https] succeeded!
Using NetCat to upload files can sometimes be handy, however it would be awesome if you could track the upload ETA and not just stare patiently for a prompt. PV, or “Pipe Viewer”, is a handy little command that allows you to track the progress of any Unix pipe. Using it as an replacement for “cat” in the NetCat transfer, gives you a fancy progress-bar.
lazyclient@lazyclient-desktop:~$ nc -l 7000 > verybigfile.bin
superitguy@pro-server:~$ pv verybigfile.bin | nc 18.104.22.168 7000
70.2MB 0:00:11 [5.95MB/s] [============================================================>] 100%
Fetch the latest binary @ pv’s project homepage: http://www.ivarch.com/programs/pv.shtml
When downloading large files in Linux, wget gets the job done but isn’t very fast. When speed is of the issue, a multi-connection tool is needed. That is where axel, a simple command-line based download accelerator, comes in. Axel is as easy to use as wget, it may not have the advanced features such as logging and timeout variables. But gets the job done, quickly.
~$ axel [DOWNLOAD-LINK]
The default download progress-indicator looks a bit like the older releases of wget. So I recommend using the -a or –alternate flag for a prettier output. Example:
~$ axel -a [DOWNLOAD-LINK]
If you want to use the alternate output by default, set it as an alias in bash with ~$ alias axel=’axel -a’. For a more permanent solution, add the alias to .bashrc in your home-dir or /etc/bashrc for the entire system.
As with any application in Linux, piping the output from an application to a logfile or perhaps another application. Can sometimes clarify what is going on. It would be even better if you could “cat” any output over the Network (Ncat, get it?) to another computer. That is where Ncat comes in.
First, some basics
- ncat The command in question
- -v Verbose output, recommended for testing
- -l Tells ncat to listen
- -k Tells ncat to keep the connection up (ncat exits on client disconnect by default)
- -n Tells ncat to skip DNS resolution (not necessary when connecting/listening on plain IP’s)
- –ssl Tells ncat to send data encrypted with ssl (optional)
- –send-only Tells ncat to only send data (optional)
- –recv-only Tells ncat to only receive data (optional)
Now, some examples
- [Server] $ncat -l 1025 > file.txt [Client] $cat file.txt | ncat [IP of Server] 1025 – Sends “file.txt” to the server over port 1025
- [Server] $ncat -lkv 12345 > file.txt [Client] $cat file.txt | ncat [IP of Server] 12345 – Sends “file.txt” to the server over port 12345. The server will verbosely print what is going on, and keep the connection open when the client disconnects
- [Server] $ncat -lkvn –recv-only 1337 > supersecretfile.txt [Client] $cat supersecretfile.txt | ncat –send-only –ssl [IP of Server] 1337 – Sends “supersecretfile.txt” to the server over port 1337. The server will verbosely print output, keep the connection open and skip resolving DNS. While the client sends the data encrypted over ssl