In Windows, I go to command line and 'telnet ' to check the port. How to do the same in Unix?

It seems some people using 'tcpdump port ' commands. Is this monitoring the real time traffic? Thanks.

  • nmap – Zoredache Jul 15 '10 at 0:18
  • FYI if you ever have occasion to actually send data to a remote host and/or receive a response back, Linux/Unix has netcat which you can use in place of telnet for that. – David Z Jul 15 '10 at 4:31
  • Also, and I'm sad I don't see it in the comments section here, Unix has telnet too. – Slartibartfast Jul 15 '10 at 5:02
  • Thanks everyone, all answers have been really helpful. My last question is what tool is 'tcpdump port' commands in Unix? – Stan Jul 15 '10 at 18:50

nmap is a great general-purpose tool for such things and much else.

nmap host.domain.tld (or nmap host for a local machine, or nmap <ipaddr> to check a machine by address not name) will list what common ports are open.

nmap -p 22,80,443 will scan a range of hosts by address to see if the TCP ports usually associated with SSH, HTTP and HTTPS are open.

See man nmap for many more options - it is the kitchen sink of network checking tools.

You may not have nmap installed at the moment, but it is in just about all distros standard repositories. For debian or ubuntu variants aptitude install nmap to install it, or find it in the GUI package manager of your choice. If it isn't available easily on your system, get it and more info from http://nmap.org/

You could also just use the same telnet client technique that you are already familiar with as that is available too and usually installed in one of the default packages, but nmap is a tool worth getting to know as it can be helpful for diagnosing network issues, just checking that things are as they should be, and so on. There are also a few decent graphical front-ends to it, if you would prefer to interact with it away from the command line.

|improve this answer|||||
  • 2
    +1 nmap is way better than telnet for this task. – David Z Jul 15 '10 at 4:30

If you're using bash, then the man pages state that you could write to /dev/tcp/HostNameOrIP/port. I've used this a few times and if the remote port is open, then there is no response. If the system cannot connect to the remote port, then it states the reason

[kevin@box ~]$ echo -n > /dev/tcp/www.yahoo.com/80
[kevin@box ~]$ nslookup www.no-such-domain.com

** server can't find www.no-such-domain.com: NXDOMAIN

[kevin@box ~]$ echo -n > /dev/tcp/www.no-such-domain.com/80
-bash: www.no-such-domain.com: Name or service not known
-bash: /dev/tcp/www.no-such-domain.com/80: Invalid argument
[kevin@box ~]$ echo -n > /dev/tcp/    #no such server on my network
-bash: connect: No route to host
-bash: /dev/tcp/ No route to host
[kevin@box ~]$ echo -n > /dev/tcp/    #nothing listening on port 88
-bash: connect: Connection refused
-bash: /dev/tcp/ Connection refused
[kevin@box ~]$
|improve this answer|||||
  • I wouldn't advise to rely on this trick, because at least debian bash packages have this feature stripped off. – halp Jul 15 '10 at 1:40
  • Which is why I grumble at systems whose man pages say this works, but then I get 'no such file or directory'. – Kevin M Jul 24 '10 at 0:11

You can use telnet on a *nix machine, too.

|improve this answer|||||
  • +1 - there's even an SSL capable variant. – sybreon Jul 15 '10 at 6:10
  • @sybreon - I was not aware of that.. who provides it? – warren Jul 15 '10 at 11:10
  • 1
    You can download the Debian package or the source code from packages.debian.org/lenny/telnet-ssl – sybreon Jul 16 '10 at 13:20
  • cool - I'll look into it – warren Jul 16 '10 at 19:06

To test if port is accessible in Bash, you may use the following one-line command:

$ </dev/tcp/example.com/80 && echo Port is open || echo Port is closed
Port is open

To check manually, use telnet command (similar as on Windows).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.