Once upon a time I wanted to check if some ports are open. The network I wanted to check was at my office, and when I forwarded some ports on my Mikrotik I wanted to be sure if I did it correctly. So I started to find solution in the internet and I found that netcat can do it:
nc 127.0.0.1 123 < /dev/null; echo $?
for remote host:
nc 22.214.171.124 123< /dev/null; echo $?
After this command you will get an answer 0 or 1.
0 means port is open
1 means port is closed
If you don’t have netcat on your Ubuntu, you can easy install it by command:
sudo apt-get install netcat