14

I'm trying to determine if port 25 is available on a server. I tried using nc and telnet to connect, but each of those failed to connect.

Is there any other test I can do to find out if there is anything listening on that port?

Eric Renouf
  • 18,141
  • 4
  • 49
  • 65
rahul dubey
  • 151
  • 1
  • 1
  • 3
  • 3
    Well, if `nc 25` or `telnet 25` do not report anything back, it is very likely that the port is blocked either by a firewall or the service is not listening to the IP address you are trying to connect. To check on which IP addresses and ports services are listening run `netstat -tulpan` on the host the service should run on and have a look at that output. – Thomas Aug 28 '16 at 10:20
  • 1
    Please rephrase the question so that the objective is made clear. – sjsam Aug 28 '16 at 11:21
  • 1
    I just reworded your question, if I missed the point rahul please fix it again. – Eric Renouf Aug 28 '16 at 11:47

3 Answers3

16

If you have access to the system and you want to check whether it's blocked or open, you can use netstat -tuplen | grep 25 to see if the service is on and is listening to the IP address or not.

You can also try to use iptables -nL | grep <port number> to see if there is any rule set by your firewall.

If you saw nothing wrong, finally you can do what you have already done by using telnet yourTarget 25or nc yourTarget 25, and if you get a message saying that the connection is refused, it might be blocked and filtered by your ISP since most ISPs block the default SMTP port 25. In that case you can change the default port - if you need it - to an alternative.

The other option you have, is to use Nmap

You can use nmap -sT localhost to determine which ports are listening for TCP connections from the network. To check for UDP ports, you should use -sU option.

To check for port 25, you can easily use nmap -p25 localhost.

And if you do not have access to the system, you can use nmap -sS -p25 yourTargetIP.

N.B. Nmap is a super-powerful tool, but you should know how to use it. For instance, sometimes you might be in need of using -Pn option for a pingless scan.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
4

To check the port 25 , you can use:

netstat (TCP and UDP):

netstat -plntu | grep ':25'

ss (TCP and UDP):

 ss -lntu | grep ':25'

nmap (TCP):

nmap -sT -O localhost | grep 25

lsof (TCP and UDP):

lsof -i:25
muru
  • 69,900
  • 13
  • 192
  • 292
GAD3R
  • 63,407
  • 31
  • 131
  • 192
-1
# nmap --script smtp-open-relay server.nila.com
25/tcp   open   smtp
|_smtp-open-relay: Server is an open relay (13/16 tests)
HalosGhost
  • 4,732
  • 10
  • 33
  • 41