A port is a logical entity which acts as a endpoint of communication associated with an application or process on an Linux operating system. It is useful to know which ports are open and running services on a target machine before using them.
We can easily list open ports in Linux on a local machine using the netstat or several other Linux commands such NMAP.
In this guide, we will show you how to determine if ports on a remote host are reachable/open using simple netcat (in short nc) command.
netcat (or nc in short) is a powerful and easy-to-use utility that can be employed for just about anything in Linux in relation to TCP, UDP, or UNIX-domain sockets.
# yum install nc [On CentOS/RHEL]
# dnf install nc [On Fedora 22+]
$ sudo apt-get install netcat [On Debian/Ubuntu]
We can use it to: open TCP connections, listen on arbitrary TCP and UDP ports, send UDP packets, do port scanning under both IPv4 and IPv6 and beyond.
Using netcat, you can check if a single or multiple or a range of open ports as follows. The command below will help us see if the port 22 is open on the host 192.168.56.10:
$ nc -zv 192.168.1.15 22
In the command above, the flag:
-z – sets nc to simply scan for listening daemons, without actually sending any data to them.
-v – enables verbose mode.
The next command will check if ports 80, 22 and 21 are open on the remote host 192.168.5.10 (we can use the hostname as well):
nc -zv 192.168.56.10 80 22 21
It is also possible to specify a range of ports to be scanned:’
$ nc -zv 192.168.56.10 20-80
For more examples and usage of netcat command, read through our articles as follows.
- Transfer Files Between Linux Servers Using netcat Command
- Linux Network Configuration and Troubleshooting Commands
That’s all. In this article, we explained how to check if ports on a remote host are reachable/open using simple netcat commands. Make use of the comment section below to write back to us concerning about this tip.
',
enableHover: false,
enableTracking: true,
buttons: { twitter: {via: 'tecmint'}},
click: function(api, options){
api.simulateClick();
api.openPopup('twitter');
}
});
jQuery('#facebook').sharrre({
share: {
facebook: true
},
template: '
{total}
',
enableHover: false,
enableTracking: true,
click: function(api, options){
api.simulateClick();
api.openPopup('facebook');
}
});
jQuery('#googleplus').sharrre({
share: {
googlePlus: true
},
template: '
{total}
',
enableHover: false,
enableTracking: true,
urlCurl: 'https://www.tecmint.com/wp-content/themes/tecmint/js/sharrre.php',
click: function(api, options){
api.simulateClick();
api.openPopup('googlePlus');
}
});
jQuery('#linkedin').sharrre({
share: {
linkedin: true
},
template: '
{total}
',
enableHover: false,
enableTracking: true,
buttons: {
linkedin: {
description: 'How to Check Remote Ports are Reachable Using ‘nc’ Command',media: '/uploads/2017/02/Check-Open-Ports-in-Linux.png' }
},
click: function(api, options){
api.simulateClick();
api.openPopup('linkedin');
}
});
// Scrollable sharrre bar, contributed by Erik Frye. Awesome!
var shareContainer = jQuery(".sharrre-container"),
header = jQuery('#header'),
postEntry = jQuery('.entry'),
$window = jQuery(window),
distanceFromTop = 20,
startSharePosition = shareContainer.offset(),
contentBottom = postEntry.offset().top + postEntry.outerHeight(),
topOfTemplate = header.offset().top;
getTopSpacing();
shareScroll = function(){
if($window.width() > 719){
var scrollTop = $window.scrollTop() + topOfTemplate,
stopLocation = contentBottom - (shareContainer.outerHeight() + topSpacing);
if(scrollTop > stopLocation){
shareContainer.offset({top: contentBottom - shareContainer.outerHeight(),left: startSharePosition.left});
}
else if(scrollTop >= postEntry.offset().top-topSpacing){
shareContainer.offset({top: scrollTop + topSpacing, left: startSharePosition.left});
}else if(scrollTop < startSharePosition.top+(topSpacing-1)){
shareContainer.offset({top: startSharePosition.top,left:startSharePosition.left});
}
}
},
shareMove = function(){
startSharePosition = shareContainer.offset();
contentBottom = postEntry.offset().top + postEntry.outerHeight();
topOfTemplate = header.offset().top;
getTopSpacing();
};
/* As new images load the page content body gets longer. The bottom of the content area needs to be adjusted in case images are still loading. */
setTimeout(function() {
contentBottom = postEntry.offset().top + postEntry.outerHeight();
}, 2000);
if (window.addEventListener) {
window.addEventListener('scroll', shareScroll, false);
window.addEventListener('resize', shareMove, false);
} else if (window.attachEvent) {
window.attachEvent('onscroll', shareScroll);
window.attachEvent('onresize', shareMove);
}
function getTopSpacing(){
if($window.width() > 1024)
topSpacing = distanceFromTop + jQuery('.nav-wrap').outerHeight();
else
topSpacing = distanceFromTop;
}
});
Source:
tecmint.com