Blob


1 version=pmwiki-2.2.130 ordered=1 urlencoded=1
2 agent=w3m/0.5.3+git20210102
3 author=jrmu
4 charset=UTF-8
5 csum=
6 ctime=1635937306
7 host=38.87.162.47
8 name=Netcat.Http
9 rev=5
10 targets=
11 text=(:title Troubleshooting httpd with netcat:)%0a%0anetcat is the swiss-army knife of networking. It can be a valuable tool to help diagnose networking errors in your web server.%0a%0a[@%0a$ print "GET / HTTP/1.1\nHostname: www.example.com\r\n\r\n" | nc www.example.com 80%0a@]%0a%0aYou may get a few possible responses:%0a%0a!! 302 Response%0a%0aA 302 response indicates that the web page has been moved.%0aThis will occur if openhttpd is set to redirect to port 443:%0a%0a[@%0aHTTP/1.0 302 Found%0aDate: Tue, 23 Feb 2021 14:01:28 GMT%0aOpenBSD httpd%0aConnection: close%0aContent-Type: text/html%0aContent-Length: 486%0aLocation: https://www.example.com/index.html%0a%0a%3c!DOCTYPE html>%0a%3chtml> %0a%3chead>%0a%3cmeta charset="utf-8"> %0a%3ctitle>302 Found%3c/title>%0a%3cstyle type="text/css">%3c!--%0abody { background-color: white; color: black; font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }%0ahr { border: 0; border-bottom: 1px dashed; }%0a@media (prefers-color-scheme: dark) {%0abody { background-color: #1E1F21; color: #EEEFF1; }%0aa { color: #BAD7FF; }%0a}%0a-->%3c/style>%0a%3c/head>%0a%3cbody>%0a%3ch1>302 Found%3c/h1>%0a%3chr>%0a%3caddress>OpenBSD httpd%3c/address>%0a%3c/body>%0a%3c/html>%0aConnection closed by foreign host.%0a@]%0a%0aThis response indicates that%0a%0aHTTP/1.0 302 Found%0aDate: Tue, 23 Feb 2021 14:01:28 GMT%0aOpenBSD httpd%0aConnection: close%0aContent-Type: text/html%0aContent-Length: 486%0aLocation: https://www.example.com/index.html%0a@]%0a
12 time=1635949819
13 title=Troubleshooting httpd with netcat
14 author:1635949819=jrmu
15 diff:1635949819:1635949608:=7,16d6%0a%3c @]%0a%3c %0a%3c You may get a few possible responses:%0a%3c %0a%3c !! 302 Response%0a%3c %0a%3c A 302 response indicates that the web page has been moved.%0a%3c This will occur if openhttpd is set to redirect to port 443:%0a%3c %0a%3c [@%0a23,24c13,14%0a%3c Location: https://www.example.com/index.html%0a%3c %0a---%0a> Location: https://example.com/index.html%0a> %0a48,57c38%0a%3c This response indicates that%0a%3c %0a%3c HTTP/1.0 302 Found%0a%3c Date: Tue, 23 Feb 2021 14:01:28 GMT%0a%3c OpenBSD httpd%0a%3c Connection: close%0a%3c Content-Type: text/html%0a%3c Content-Length: 486%0a%3c Location: https://www.example.com/index.html%0a%3c @]%0a---%0a> !! Debugging Web Servers%0a
16 host:1635949819=38.87.162.47
17 author:1635949608=jrmu
18 diff:1635949608:1635949305:=6c6,14%0a%3c $ print "GET / HTTP/1.1\nHostname: www.example.com\r\n\r\n" | nc www.example.com 80%0a---%0a> $ telnet example.com 80%0a> GET /index.html HTTP/1.1%0a> Host: example.com%0a> @]%0a> %0a> then, press enter key twice.%0a> You should a response similar to the one below:%0a> %0a> [@%0a36a45,48%0a> %0a> To quit, just type CTRL+C.%0a> %0a> Here's the complete process:%0a
19 host:1635949608=38.87.162.47
20 author:1635949305=jrmu
21 diff:1635949305:1635937717:=1,4d0%0a%3c (:title Troubleshooting httpd with netcat:)%0a%3c %0a%3c netcat is the swiss-army knife of networking. It can be a valuable tool to help diagnose networking errors in your web server.%0a%3c %0a45c41,135%0a%3c %0a---%0a> (:title Troubleshooting with netcat:)%0a> %0a> 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> %0a> !! Debugging IRC%0a> %0a> To test if you are able to establish an IRC connection, you can use netcat:%0a> %0a> [@%0a> $ nc irc.ircnow.org 6667%0a> NICK newnick%0a> USER newuser * * :newuser%0a> PING: 12345%0a> PONG: 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> %0a> If you successfully see the message of the day (MOTD) and other replies from the IRC server, then the IRC connection has succeeded.%0a> %0a> You can specifically use netcat to test if an IPv6 address is working:%0a> %0a> [@%0a> $ nc -s 2001:0db8:: ipv6.ircnow.org 6667%0a> NICK newnick%0a> USER newuser * * :newuser%0a> PING :12345%0a> PONG :12345%0a> @]%0a> %0a> 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> %0a> You 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%0a> ostname now%0a> :newnick!newnick@2001:0db8:20:b4:f117:2f18:11eb:3a85 MODE newnick :+iC%0a> @]%0a> %0a> 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> %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> %0a> To check your vhost, type @@WHOIS newnick@@:%0a> %0a> [@%0a> WHOIS 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> %0a> In 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> %0a> To join a channel:%0a> %0a> [@%0a> JOIN #ircnow%0a> @]%0a> %0a> To part a channel:%0a> %0a> [@%0a> PART #ircnow%0a> @]%0a> %0a> To send a message to a channel or user:%0a> %0a> [@%0a> PRIVMSG #ircnow :Hello, world!%0a> PRIVMSG Mom :Look ma, no client!%0a> @]%0a> %0a> To identify with NickServ:%0a> %0a> [@%0a> PRIVMSG Nickserv :identify PASSWORD%0a> @]%0a> %0a47a138,188%0a> !! Debugging SMTP%0a> %0a> You can use netcat to test for SMTP errors such as [[openbsd/mailopenproxy|open mail relays]].%0a> %0a> Here's how to send a simple letter:%0a> %0a> [@%0a> $ nc ircnow.org 25 %0a> 220 ircnow.org ESMTP OpenSMTPD%0a> @]%0a> %0a> Next, we type HELO followed by our sending domain:%0a> %0a> [@%0a> HELO example.com%0a> 250 ircnow.org Hello example.com [38.81.163.143], pleased to meet you%0a> @]%0a> %0a> Afterwards, we type our sending mail address:%0a> %0a> [@%0a> MAIL FROM: %3ctest@example.com>%0a> 250 2.0.0 Ok%0a> @]%0a> %0a> And the destination mail address:%0a> %0a> [@%0a> RCPT TO: %3cjrmu@ircnow.org>%0a> 250 2.1.5 Destination address valid: Recipient ok%0a> @]%0a> %0a> Then we type DATA followed by our email:%0a> %0a> [@%0a> DATA%0a> 354 Enter mail, end with "." on a line by itself%0a> Subject: Alpha Bravo Charlie Delta%0a> %0a> Echo Foxtrot Golf Hotel%0a> @]%0a> %0a> We then type . to end the email, then QUIT:%0a> %0a> [@%0a> .%0a> 250 2.0.0 e57f9a36 Message accepted for delivery%0a> QUIT%0a> 221 2.0.0 Bye%0a> @]%0a> %0a48a190,210%0a> %0a> [@%0a> $ nc ircnow.org 25 %0a> 220 ircnow.org ESMTP OpenSMTPD%0a> HELO example.com%0a> 250 ircnow.org Hello example.com [38.81.163.143], pleased to meet you%0a> MAIL FROM: %3ctest@example.com>%0a> 250 2.0.0 Ok%0a> RCPT TO: %3cjrmu@ircnow.org>%0a> 250 2.1.5 Destination address valid: Recipient ok%0a> DATA%0a> 354 Enter mail, end with "." on a line by itself%0a> Subject: Alpha Bravo Charlie Delta%0a> %0a> Echo Foxtrot Golf Hotel%0a> .%0a> 250 2.0.0 e57f9a36 Message accepted for delivery%0a> QUIT%0a> 221 2.0.0 Bye%0a> @]%0a> %0a
22 host:1635949305=38.87.162.47
23 author:1635937717=jrmu
24 diff:1635937717:1635937306:=1,40d0%0a%3c [@%0a%3c $ telnet example.com 80%0a%3c GET /index.html HTTP/1.1%0a%3c Host: example.com%0a%3c @]%0a%3c %0a%3c then, press enter key twice.%0a%3c You should a response similar to the one below:%0a%3c %0a%3c [@%0a%3c HTTP/1.0 302 Found%0a%3c Date: Tue, 23 Feb 2021 14:01:28 GMT%0a%3c OpenBSD httpd%0a%3c Connection: close%0a%3c Content-Type: text/html%0a%3c Content-Length: 486%0a%3c Location: https://example.com/index.html%0a%3c %0a%3c %3c!DOCTYPE html>%0a%3c %3chtml> %0a%3c %3chead>%0a%3c %3cmeta charset="utf-8"> %0a%3c %3ctitle>302 Found%3c/title>%0a%3c %3cstyle type="text/css">%3c!--%0a%3c body { background-color: white; color: black; font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }%0a%3c hr { border: 0; border-bottom: 1px dashed; }%0a%3c @media (prefers-color-scheme: dark) {%0a%3c body { background-color: #1E1F21; color: #EEEFF1; }%0a%3c a { color: #BAD7FF; }%0a%3c }%0a%3c -->%3c/style>%0a%3c %3c/head>%0a%3c %3cbody>%0a%3c %3ch1>302 Found%3c/h1>%0a%3c %3chr>%0a%3c %3caddress>OpenBSD httpd%3c/address>%0a%3c %3c/body>%0a%3c %3c/html>%0a%3c Connection closed by foreign host.%0a%3c @]%0a
25 host:1635937717=38.87.162.47
26 author:1635937306=jrmu
27 diff:1635937306:1635937306:=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
28 host:1635937306=38.87.162.47