When it's time to change....
Author: John on March 24, 2019
"When it's time to change, then it's time to change
Don't fight the tide, come along for the ride
Don't ya see?
When it's time to change, you've got to rearrange
Who you are into what you're gonna be"
If you know those lyrics above, then you might be as old as me :)
For those that do not know, the above is a snippet from a song performed by the kids on the show "Brady Bunch". This was a very popular show in the 1970s.
It is time to change. I can't believe it has been just over two years since I last posted a blog here. I have done a couple over at Medium, but I am disappointed in myself in that I let my writing slack off for so long. So it is time to change - time to correct things.
As part of this change, inclusive of my journey to lear Golang, I am migrating this blog over to Hugo. In addition, The new blog site will move off of this server, a Digital Ocean VM, and find its' new home over at Heroku.
The new site can be found here: https://ognt-io-hugo.herokuapp.com Please be patient with me as I make the migration. I'm learning a new blogging tool, Hugo, re-learning how to use Heroku, and converting all the posts from here, which are in a Postgres database, over to the new site which uses markdown files.
I hope to see you over at my new blogging home.
HoGi....
NetCat Part Deux - The Writing on the Wall
Author: John on January 12, 2017
SUMMARY: TUse NetCat to help troubleshoot a TCP Port issue on a Linux VM (Guest) and our Laptop (OS X) which is a Host running VirtualBox.
My node (laptop) on the network cannot talk to a new application running on a linux server. Ever found yourself in this scenario? To add a layer of complexity, that application running on Linux server is a VirtualBox VM (virtual machine.) The VM was created with the network settings set to 'Nat'. What does that mean? It means that the VM can use the host computers network connection to get on the network, and out to the Internet - assuming your laptop/desktop has a working Internet connection.
But what if I want to connect to that VM (guest) using ssh from my laptop (host)? We can do this with VirtualBox, but you need to update your Network settings in VirtualBox and enable port forwarding. For example, you may add a port forwarding entry as follows:
Name Protocol Host IP Host Port Guest IP Guest Port ssh TCP 127.0.0.1 2222 22
Once the above is setup and you start your VM, from your laptop (host) you should be able to connect using: ssh username@127.0.0.1 -p 2222
VirtualBox will forward your ssh connection from the laptop (host) on port 2222 on to the Linux server (guest) on port 22. Normally, this setup works and you shouldn't encounter any issues. However, if say you just installed a shiney new app on the Linux server (guest) that should run on ports 7001 and 7003, but you find that you have issues connecting from your laptop (host) then it would be time to roll up your sleeves and trouble shoot.
This is where NectCat (nc) can be helpful. Remember, in this scenario we have our laptop (host) using VirtualBox to handle port forwarding to your Linux server (guest.) If for example you try the following from your laptop, you may get a false-positive response:
jhogarty: ~ $ nc -v -z localhost 9001
found 0 associations
found 1 connections:
1: flags=82
outif lo0
src 127.0.0.1 port 58563
dst 127.0.0.1 port 9001
rank info not available
TCP aux info available
Connection to localhost port 9001 [tcp/etlservicemgr] succeeded!
jhogarty: ~ $
In the above example I am using port 9001, an unprotected port, on my laptop (host) to try and connect to the Linux server (guest) on port 7001. From the output in the above example, using netcat, all looks well. But it isn't. We need to modify the use of our tools to do a better test given our current scenario.
On the Linux server (guest) we will use NetCat with the following arguments:
nc -l 7001
# Example:
jhogarty: ~ $ ssh oracle@127.0.0.1 -p 2223
oracle@127.0.0.1's password:
Last login: Fri Jan 13 09:38:13 2017 from 10.0.2.2
[oracle@localhost ~]$ nc -l 7001
{cursor_here}
To help with our testing, you should have two terminal sessions up - one for your Linux server and one for your laptop. We set up the Linux server in one terminal with the example above and now we need to use NetCat in a different terminal session on your laptop. Use the following:
nc 127.0.0.1 9001
# Example
jhogarty: ~ $ nc 127.0.0.1 9001
{cursor_here}
Hmm, don't see much going yet. But here comes the cool part, assuming that we have good network connectivity between the server and the laptop. In the terminal window for your laptop, start typing something - 'Hey, is this working?' Press enter. Take a look in the other terminal window, the one connected to your Linux server. Do you see the text that you typed? If so, you have a clear networking path between the two computers (nodes.) Congratulations!
# Example
LAPTOP
jhogarty: ~ $ nc 127.0.0.1 9001
Hey, is this working? <- you just typed this!
And on the Linux Server you should see:
[oracle@localhost ~]$ nc -l 7001
Hey, is this working? <- you should see this appear after typing on LAPTOP and pressing Enter
If you do not see the text on your Linux server, check to make sure you typed the commands correctly based on the examples given above. If you are working in a similar scenario, using VirtualBox, make sure you have setup your port forwarding properly. For example, for the Host Port setting, do not use any protected ports. Another thing you can check, if using VirtualBox, are you using NAT?
Should you be troubleshooting a similar problem, but without something like VirtualBox, but instead your laptop/desktop/server-a is on a network that can normally talk to the target server, for example ssh works fine, then you may have a firewall or port blocking issue. And that would be a topic for another day!
Learn Something New Everyday
OMG Netcat Can Do That?!!!
Author: John on December 14, 2016
SUMMARY: Today we will see yet another cool thing netcat can do - file transfer.
I could be King if I surrounded myself by fools. But I'd rather immerse myself in a group of people smarter than me so I can learn and grow. I believe that I am pretty comfortable and good at the command line - far from a guru, but I've been known to impress. Today however, I saw something my co-worker, Glenn Struzinski, did that just blew my mind.
In my previous post one of the tips I covered included using netcat (nc). When I saw that tip I thought I had learned something really cool about Netcat. But what I will share with you today I think is a mind-bender of a tip - using netcat to transfer a file from Host-A to Host-B. These hosts need to be able to communicate over the network. My example will have Host-A as my server hosted at Digital Ocean, and Host-B is my laptop. Currently my laptop is connected to the internet at a Starbucks cafe.
For illustrative purposes, let's say Host-A has an ip address of 104.237.47.10 (I am pulling this address out of the air, please use your own real address.) While logged in to Host-A I enter the following:
➜ ~ cat BinaryIpsum.zip | nc -l -p 1234
Now you may have noticed that in the above terminal, the server is waiting for a connection to occur. Let's review the command. We have a file on our server called BinaryIpsum.zip. Replace that with your desired file name. Now we use cat and our file name and then we pipe that output to netcat (nc) and tell netcat to "listen" using the -l flag. Lastly, we tell netcat to use port 1234 with the -p 1234.
So now we need to open up a terminal session on our laptop. Navigate to a directory where you want to place the file and execute the following:
➜ NETCAT_TEST pwd
/Users/jfhogarty/Documents/NETCAT_TEST
➜ NETCAT_TEST ls -la
total 0
drwxr-xr-x 2 jfhogarty staff 68 Dec 13 19:49 .
drwx------+ 176 jfhogarty staff 5984 Dec 13 19:49 ..
➜ NETCAT_TEST
➜ NETCAT_TEST
➜ NETCAT_TEST nc 104.237.47.10 1234 > NewFile.zip
➜ NETCAT_TEST
➜ NETCAT_TEST ls -la
total 10632
drwxr-xr-x 3 jfhogarty staff 102 Dec 13 19:49 .
drwx------+ 176 jfhogarty staff 5984 Dec 13 19:49 ..
-rw-r--r-- 1 jfhogarty staff 5440660 Dec 13 19:49 NewFile.zip
➜ NETCAT_TEST
Is that FREAKING AWESOME?
Let's review what we did on our destination computer. We used nc with the ip address of the host that has the file we want. We redirected the output of that command using the greater than sign (>) which directed the output to the file named NewFile.zip. I could have used the name BinaryIpsum.zip or something else if I had wanted.
If you do some pretty wild stuff with Netcat, let me know - I love learning new things, every day!
Learn Something New Everyday