version=pmwiki-2.2.130 ordered=1 urlencoded=1 agent=Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 author=tiramisu charset=UTF-8 csum= ctime=1622800064 host=2607:fb90:bdaa:a8fb:da68:fe9c:b1e9:f337 name=Netcat.Usage rev=2 targets=Openbsd.Mailopenproxy text=(:title Troubleshooting with netcat:)%0a%0anetcat 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.%0a%0a!! Debugging IRC%0a%0aTo test if you are able to establish an IRC connection, you can use netcat:%0a%0a[@%0a$ nc irc.ircnow.org 6667%0aNICK newnick%0aUSER newuser * * :newuser%0aPING: 12345%0aPONG: 12345%0a@]%0a%0a'''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.%0a%0aIf you successfully see the message of the day (MOTD) and other replies from the IRC server, then the IRC connection has succeeded.%0a%0aYou can specifically use netcat to test if an IPv6 address is working:%0a%0a[@%0a$ nc -s 2001:0db8:: ipv6.ircnow.org 6667%0aNICK newnick%0aUSER newuser * * :newuser%0aPING :12345%0aPONG :12345%0a@]%0a%0aThis 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.%0a%0aYou should see something like the following from the server's reply:%0a%0a[@%0a:irc.example.ircnow.org 396 newnick 2001:0db8:20:b4:f117:2f18:11eb:3a85 :is your displayed h%0aostname now%0a:newnick!newnick@2001:0db8:20:b4:f117:2f18:11eb:3a85 MODE newnick :+iC%0a@]%0a%0aIn 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:%0a%0a[@%0a:irc.example.ircnow.org 396 newnick newnick.example.ircnow.org :is your displayed hostname now%0a:newnick!newnick@newnick.example.ircnow.org MODE newnick :+iC%0a@]%0a%0aTo check your vhost, type @@WHOIS newnick@@:%0a%0a[@%0aWHOIS newnick%0a:irc.example.ircnow.org 311 newnick newnick newnick 2001:0db8:: * :newuser%0a:irc.example.ircnow.org 312 newnick newnick irc.example.ircnow.org :irc.example.ircnow.org%0a:irc.example.ircnow.org 378 newnick newnick :is connecting from *@2001:0db8::%0a:irc.example.ircnow.org 379 newnick newnick :is using modes +iC%0a:irc.example.ircnow.org 317 newnick newnick 15 1597224116 :seconds idle, signon time%0a:irc.example.ircnow.org 318 newnick newnick :End of WHOIS list%0a@]%0a%0aIn this above example, the vhost is not showing up properly. If it shows up properly, you should see something like this:%0a%0a[@%0a:irc.example.ircnow.org 311 newnick newnick newnick newnick.example.ircnow.org * :newnick%0a:irc.example.ircnow.org 312 newnick newnick irc.example.ircnow.org :irc.example.ircnow.org%0a:irc.example.ircnow.org 378 newnick newnick :is connecting from *@newnick.example.ircnow.org 2001:0db8:20:b4:f8fb:b8fa:9812:2562%0a:irc.example.ircnow.org 379 newnick newnick :is using modes +iC%0a:irc.example.ircnow.org 317 newnick newnick 86 1597224404 :seconds idle, signon time%0a:irc.example.ircnow.org 318 newnick newnick :End of WHOIS list%0a@]%0a%0aTo join a channel:%0a%0a[@%0aJOIN #ircnow%0a@]%0a%0aTo part a channel:%0a%0a[@%0aPART #ircnow%0a@]%0a%0aTo send a message to a channel or user:%0a%0a[@%0aPRIVMSG #ircnow :Hello, world!%0aPRIVMSG Mom :Look ma, no client!%0a@]%0a%0aTo identify with NickServ:%0a%0a[@%0aPRIVMSG Nickserv :identify PASSWORD%0a@]%0a%0aTo quit, just type CTRL+C.%0a%0a!! Debugging SMTP%0a%0aYou can use netcat to test for SMTP errors such as [[openbsd/mailopenproxy|open mail relays]].%0a%0aHere's how to send a simple letter:%0a%0a[@%0a$ nc ircnow.org 25 %0a220 ircnow.org ESMTP OpenSMTPD%0a@]%0a%0aNext, we type HELO followed by our sending domain:%0a%0a[@%0aHELO example.com%0a250 ircnow.org Hello example.com [38.81.163.143], pleased to meet you%0a@]%0a%0aAfterwards, we type our sending mail address:%0a%0a[@%0aMAIL FROM: %3ctest@example.com>%0a250 2.0.0 Ok%0a@]%0a%0aAnd the destination mail address:%0a%0a[@%0aRCPT TO: %3cjrmu@ircnow.org>%0a250 2.1.5 Destination address valid: Recipient ok%0a@]%0a%0aThen we type DATA followed by our email:%0a%0a[@%0aDATA%0a354 Enter mail, end with "." on a line by itself%0aSubject: Alpha Bravo Charlie Delta%0a%0aEcho Foxtrot Golf Hotel%0a@]%0a%0aThe blank line between the subject and the body of the message is essential.%0a%0aWe then type . to end the email, then QUIT:%0a%0a[@%0a.%0a250 2.0.0 e57f9a36 Message accepted for delivery%0aQUIT%0a221 2.0.0 Bye%0a@]%0a%0aHere's the complete process:%0a%0a[@%0a$ nc ircnow.org 25 %0a220 ircnow.org ESMTP OpenSMTPD%0aHELO example.com%0a250 ircnow.org Hello example.com [38.81.163.143], pleased to meet you%0aMAIL FROM: %3ctest@example.com>%0a250 2.0.0 Ok%0aRCPT TO: %3cjrmu@ircnow.org>%0a250 2.1.5 Destination address valid: Recipient ok%0aDATA%0a354 Enter mail, end with "." on a line by itself%0aSubject: Alpha Bravo Charlie Delta%0a%0aEcho Foxtrot Golf Hotel%0a.%0a250 2.0.0 e57f9a36 Message accepted for delivery%0aQUIT%0a221 2.0.0 Bye%0a@]%0a%0a%0a!! Debugging Web Servers%0a time=1659575524 title=Troubleshooting with netcat author:1659575524=tiramisu diff:1659575524:1622800064:minor=139,140d138%0a%3c %0a%3c The blank line between the subject and the body of the message is essential.%0a host:1659575524=2607:fb90:bdaa:a8fb:da68:fe9c:b1e9:f337 author:1622800064=jrmu diff:1622800064:1622800064:=1,172d0%0a%3c (:title Troubleshooting with netcat:)%0a%3c %0a%3c 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.%0a%3c %0a%3c !! Debugging IRC%0a%3c %0a%3c To test if you are able to establish an IRC connection, you can use netcat:%0a%3c %0a%3c [@%0a%3c $ nc irc.ircnow.org 6667%0a%3c NICK newnick%0a%3c USER newuser * * :newuser%0a%3c PING: 12345%0a%3c PONG: 12345%0a%3c @]%0a%3c %0a%3c '''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.%0a%3c %0a%3c If you successfully see the message of the day (MOTD) and other replies from the IRC server, then the IRC connection has succeeded.%0a%3c %0a%3c You can specifically use netcat to test if an IPv6 address is working:%0a%3c %0a%3c [@%0a%3c $ nc -s 2001:0db8:: ipv6.ircnow.org 6667%0a%3c NICK newnick%0a%3c USER newuser * * :newuser%0a%3c PING :12345%0a%3c PONG :12345%0a%3c @]%0a%3c %0a%3c 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.%0a%3c %0a%3c You should see something like the following from the server's reply:%0a%3c %0a%3c [@%0a%3c :irc.example.ircnow.org 396 newnick 2001:0db8:20:b4:f117:2f18:11eb:3a85 :is your displayed h%0a%3c ostname now%0a%3c :newnick!newnick@2001:0db8:20:b4:f117:2f18:11eb:3a85 MODE newnick :+iC%0a%3c @]%0a%3c %0a%3c 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:%0a%3c %0a%3c [@%0a%3c :irc.example.ircnow.org 396 newnick newnick.example.ircnow.org :is your displayed hostname now%0a%3c :newnick!newnick@newnick.example.ircnow.org MODE newnick :+iC%0a%3c @]%0a%3c %0a%3c To check your vhost, type @@WHOIS newnick@@:%0a%3c %0a%3c [@%0a%3c WHOIS newnick%0a%3c :irc.example.ircnow.org 311 newnick newnick newnick 2001:0db8:: * :newuser%0a%3c :irc.example.ircnow.org 312 newnick newnick irc.example.ircnow.org :irc.example.ircnow.org%0a%3c :irc.example.ircnow.org 378 newnick newnick :is connecting from *@2001:0db8::%0a%3c :irc.example.ircnow.org 379 newnick newnick :is using modes +iC%0a%3c :irc.example.ircnow.org 317 newnick newnick 15 1597224116 :seconds idle, signon time%0a%3c :irc.example.ircnow.org 318 newnick newnick :End of WHOIS list%0a%3c @]%0a%3c %0a%3c In this above example, the vhost is not showing up properly. If it shows up properly, you should see something like this:%0a%3c %0a%3c [@%0a%3c :irc.example.ircnow.org 311 newnick newnick newnick newnick.example.ircnow.org * :newnick%0a%3c :irc.example.ircnow.org 312 newnick newnick irc.example.ircnow.org :irc.example.ircnow.org%0a%3c :irc.example.ircnow.org 378 newnick newnick :is connecting from *@newnick.example.ircnow.org 2001:0db8:20:b4:f8fb:b8fa:9812:2562%0a%3c :irc.example.ircnow.org 379 newnick newnick :is using modes +iC%0a%3c :irc.example.ircnow.org 317 newnick newnick 86 1597224404 :seconds idle, signon time%0a%3c :irc.example.ircnow.org 318 newnick newnick :End of WHOIS list%0a%3c @]%0a%3c %0a%3c To join a channel:%0a%3c %0a%3c [@%0a%3c JOIN #ircnow%0a%3c @]%0a%3c %0a%3c To part a channel:%0a%3c %0a%3c [@%0a%3c PART #ircnow%0a%3c @]%0a%3c %0a%3c To send a message to a channel or user:%0a%3c %0a%3c [@%0a%3c PRIVMSG #ircnow :Hello, world!%0a%3c PRIVMSG Mom :Look ma, no client!%0a%3c @]%0a%3c %0a%3c To identify with NickServ:%0a%3c %0a%3c [@%0a%3c PRIVMSG Nickserv :identify PASSWORD%0a%3c @]%0a%3c %0a%3c To quit, just type CTRL+C.%0a%3c %0a%3c !! Debugging SMTP%0a%3c %0a%3c You can use netcat to test for SMTP errors such as [[openbsd/mailopenproxy|open mail relays]].%0a%3c %0a%3c Here's how to send a simple letter:%0a%3c %0a%3c [@%0a%3c $ nc ircnow.org 25 %0a%3c 220 ircnow.org ESMTP OpenSMTPD%0a%3c @]%0a%3c %0a%3c Next, we type HELO followed by our sending domain:%0a%3c %0a%3c [@%0a%3c HELO example.com%0a%3c 250 ircnow.org Hello example.com [38.81.163.143], pleased to meet you%0a%3c @]%0a%3c %0a%3c Afterwards, we type our sending mail address:%0a%3c %0a%3c [@%0a%3c MAIL FROM: %3ctest@example.com>%0a%3c 250 2.0.0 Ok%0a%3c @]%0a%3c %0a%3c And the destination mail address:%0a%3c %0a%3c [@%0a%3c RCPT TO: %3cjrmu@ircnow.org>%0a%3c 250 2.1.5 Destination address valid: Recipient ok%0a%3c @]%0a%3c %0a%3c Then we type DATA followed by our email:%0a%3c %0a%3c [@%0a%3c DATA%0a%3c 354 Enter mail, end with "." on a line by itself%0a%3c Subject: Alpha Bravo Charlie Delta%0a%3c %0a%3c Echo Foxtrot Golf Hotel%0a%3c @]%0a%3c %0a%3c We then type . to end the email, then QUIT:%0a%3c %0a%3c [@%0a%3c .%0a%3c 250 2.0.0 e57f9a36 Message accepted for delivery%0a%3c QUIT%0a%3c 221 2.0.0 Bye%0a%3c @]%0a%3c %0a%3c Here's the complete process:%0a%3c %0a%3c [@%0a%3c $ nc ircnow.org 25 %0a%3c 220 ircnow.org ESMTP OpenSMTPD%0a%3c HELO example.com%0a%3c 250 ircnow.org Hello example.com [38.81.163.143], pleased to meet you%0a%3c MAIL FROM: %3ctest@example.com>%0a%3c 250 2.0.0 Ok%0a%3c RCPT TO: %3cjrmu@ircnow.org>%0a%3c 250 2.1.5 Destination address valid: Recipient ok%0a%3c DATA%0a%3c 354 Enter mail, end with "." on a line by itself%0a%3c Subject: Alpha Bravo Charlie Delta%0a%3c %0a%3c Echo Foxtrot Golf Hotel%0a%3c .%0a%3c 250 2.0.0 e57f9a36 Message accepted for delivery%0a%3c QUIT%0a%3c 221 2.0.0 Bye%0a%3c @]%0a%3c %0a%3c %0a%3c !! Debugging Web Servers%0a host:1622800064=38.81.163.143