Troubleshooting with netcat
netcat is the swiss-army knife of networking. It is an extremely valuable tool to help diagnose any networking errors. You can and should use it often when working on sysadmin and writing code.
Debugging IRC
To test if you are able to establish an IRC connection, you can use netcat:
$ nc irc.ircnow.org 6667
NICK newnick
USER newuser * * :newuser
PING: 12345
PONG: 12345
WARNING: Do not ever connect to IRC as root. Some networks will gline your entire IP address if you attempt to connect as root because you will appear to be a drone.
If you successfully see the message of the day (MOTD) and other replies from the IRC server, then the IRC connection has succeeded.
You can specifically use netcat to test if an IPv6 address is working:
$ nc -s 2001:0db8:: ipv6.ircnow.org 6667
NICK newnick
USER newuser * * :newuser
PING :12345
PONG :12345
This will cause netcat to bind to the IPv6 address 2001:0db8::. If you configured the IPv6 address 2001:0db8:: correctly, you should be able to see the MOTD.
You should see something like the following from the server's reply:
:irc.example.ircnow.org 396 newnick 2001:0db8:20:b4:f117:2f18:11eb:3a85 :is your displayed h
ostname now
:newnick!newnick@2001:0db8:20:b4:f117:2f18:11eb:3a85 MODE newnick :+iC
In this case, the vhost is not a nice hostname, which means that either your rDNS or DNS AAAA record is not configured properly. When done properly, you should see something like:
:irc.example.ircnow.org 396 newnick newnick.example.ircnow.org :is your displayed hostname now
:newnick!newnick@newnick.example.ircnow.org MODE newnick :+iC
To check your vhost, type WHOIS newnick
:
WHOIS newnick
:irc.example.ircnow.org 311 newnick newnick newnick 2001:0db8:: * :newuser
:irc.example.ircnow.org 312 newnick newnick irc.example.ircnow.org :irc.example.ircnow.org
:irc.example.ircnow.org 378 newnick newnick :is connecting from *@2001:0db8::
:irc.example.ircnow.org 379 newnick newnick :is using modes +iC
:irc.example.ircnow.org 317 newnick newnick 15 1597224116 :seconds idle, signon time
:irc.example.ircnow.org 318 newnick newnick :End of WHOIS list
In this above example, the vhost is not showing up properly. If it shows up properly, you should see something like this:
:irc.example.ircnow.org 311 newnick newnick newnick newnick.example.ircnow.org * :newnick
:irc.example.ircnow.org 312 newnick newnick irc.example.ircnow.org :irc.example.ircnow.org
:irc.example.ircnow.org 378 newnick newnick :is connecting from *@newnick.example.ircnow.org 2001:0db8:20:b4:f8fb:b8fa:9812:2562
:irc.example.ircnow.org 379 newnick newnick :is using modes +iC
:irc.example.ircnow.org 317 newnick newnick 86 1597224404 :seconds idle, signon time
:irc.example.ircnow.org 318 newnick newnick :End of WHOIS list
To join a channel:
JOIN #ircnow
To part a channel:
PART #ircnow
To send a message to a channel or user:
PRIVMSG #ircnow :Hello, world!
PRIVMSG Mom :Look ma, no client!
To identify with NickServ:
PRIVMSG Nickserv :identify PASSWORD
To quit, just type CTRL+C.
Debugging SMTP
You can use netcat to test for SMTP errors such as ?open mail relays.
Here's how to send a simple letter:
$ nc ircnow.org 25
220 ircnow.org ESMTP OpenSMTPD
Next, we type HELO followed by our sending domain:
HELO example.com
250 ircnow.org Hello example.com [38.81.163.143], pleased to meet you
Afterwards, we type our sending mail address:
MAIL FROM: <test@example.com>
250 2.0.0 Ok
And the destination mail address:
RCPT TO: <jrmu@ircnow.org>
250 2.1.5 Destination address valid: Recipient ok
Then we type DATA followed by our email:
DATA
354 Enter mail, end with "." on a line by itself
Subject: Alpha Bravo Charlie Delta
Echo Foxtrot Golf Hotel
The blank line between the subject and the body of the message is essential.
We then type . to end the email, then QUIT:
.
250 2.0.0 e57f9a36 Message accepted for delivery
QUIT
221 2.0.0 Bye
Here's the complete process:
$ nc ircnow.org 25
220 ircnow.org ESMTP OpenSMTPD
HELO example.com
250 ircnow.org Hello example.com [38.81.163.143], pleased to meet you
MAIL FROM: <test@example.com>
250 2.0.0 Ok
RCPT TO: <jrmu@ircnow.org>
250 2.1.5 Destination address valid: Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Subject: Alpha Bravo Charlie Delta
Echo Foxtrot Golf Hotel
.
250 2.0.0 e57f9a36 Message accepted for delivery
QUIT
221 2.0.0 Bye
Debugging Web Servers