Your application is reporting problems reaching the back end database server at 172.16.1.116 or maybe you are about to set up a new application and you want to make sure it can reach the back end database server. The first tool that comes to mind is ping but many hosts will no longer respond to ICMP echo (ping) requests and of those that do there is a high probability that their network firewalls will block either your ping requests or their replies. If ping times out (figure 1) there are other ways to test network connectivity.
ping 172.16.1.116
Pinging host 172.16.1.116 : 172.16.1.116
ping: No reply. Time Out !!
ping: No reply. Time Out !!
ping: No reply. Time Out !!
ping: No reply. Time Out !!
Host 172.16.1.116 replied to 0 of the 4 pings
ready 12:26:32
Figure 1 – ping timing out
Assuming that the host you are trying to reach is running a TCP (as opposed to UDP) based service you can just telnet to the host and specify the service’s port number. There are 4 possible responses, a connection (figure 2) a refusal (figure 6), an indication of something wrong (figures 7 and 8) or a timeout (figure 9).
telnet 172.16.1.116 1830
Trying...
Connected to 172.16.1.116.
Escape character is '^]'.
Figure 2 – connection
A “Connected” message indicates that you are connected to the host – probably. Some WAN accelerators will intercept the connection and complete it, acting as a proxy. If you get connected and then a few seconds later disconnected it may be that you connected to the accelerator and then the accelerator could not get connected to the final destination so it disconnected from you. Of course it might also be that you connected to the actual host and the application crashed. It pays to know if you are using any accelerator hardware and exactly how it works.
To disconnect type control-] and “quit” at the telnet> prompt.
telnet 172.16.1.116 1830
Trying...
Connected to 172.16.1.116.
Escape character is '^]'.
telnet> quit
Figure 3 – disconnecting a connected session
The only way to be absolutely sure that you have reach the correct service running on the target host is if that service responds to the connection request with some kind of banner message. For example, a login prompt identifying the host. If you have access to the target host and that host has Perl installed you can run the tcplisten Perl script which will send a specified banner message when it accepts a connection.
On target system (Linux)
[ndav@phx-lab-lnx64 ~]$ perl tcplisten.pl -p 1830 -m 'Connection has been accepted'
perl tcplisten.pl -port 1830 -message 'Connection has been accepted'
On OpenVOS client
stp -ttp ascii
ready 12:16:34
telnet 164.152.77.155 1830
Trying...
Connected to 164.152.77.155.
Escape character is '^]'.
Connection has been accepted
Escape character is '^]'.Connection closed by forei.
Ready 12:16:40
Figure 4 running tcplisten.pl on Linux system with OpenVOS client
Because the OpenVOS telnet client will clear the terminal window when the connection closes you will probably need to set your terminal type to ascii to see the connection message.
You can also run tcplisten on OpenVOS (assuming that you have the gnu_library installed).
On OpenVOS target system
perl tcplisten.pl -p 1830 -m 'made it to m16'
perl tcplisten.pl -port 1830 -message 'made it to m16'
On Linux client
[ndav@phx-lab-lnx64 ~]$ telnet 164.152.77.128 1830
Trying 164.152.77.128...
Connected to rigel.az.stratus.com (164.152.77.128).
Escape character is '^]'.
made it to m16
Connection closed by foreign host.
[ndav@phx-lab-lnx64 ~]$
Figure 5 running tcplisten.pl on OpenVOS system with Linux client
A “refused” message indicates that you reached the target host but that it did not have a service listening on that port – probably.
telnet 172.16.1.116 1830
Trying...
telnet: Unable to connect to remote host: The connection was refused.
ready 12:31:28
Figure 6 – refusal
Some firewalls may send a reset in response to an unapproved connection request. It is very difficult to impossible to tell which scenario is occurring, at least from the client end.
If telnet receives an indication that the network (figure 7) or host (figure 8) is unreachable it will report that. The “network … unreachable” message indicates that either OpenVOS does not have a route to the target network or some router in the middle of the network could not reach the destination network. The “No route to host” message indicates that the router attached to the destination network could not reach the target host. More than likely this means the target host is down.
telnet 172.16.1.116 1830
Trying...
telnet: Unable to connect to remote host: Network trying to be reached is unreac
+hable.
ready 12:54:34
Figure 7 – OpenVOS telnet client reporting that the network is unreachable.
telnet 172.16.1.116 1830
Trying...
telnet: Unable to connect to remote host: No route to host.
ready 12:55:44
Figure 8 – OpenVOS telnet client reporting that the host is unreachable
Telnet will not report the source of these errors. The tuc.pl (test UDP connection) Perl script directed to the same IP address and port number will report the source IP address (see the following discussion on UDP testing)
A timeout indicates that you cannot reach the host – probably. Most hosts will respond with either a connection or a refusal but if a host has a host based firewall it may just drop the request without responding. Similarly a network based firewall may just drop the request without responding; and of course any ICMP messages sent by a router or a host may also be dropped by another router or firewall.
telnet 172.16.1.116 1830
Trying...
telnet: Unable to connect to remote host: The operation timed out.
Figure 9 – OpenVOS telnet client reporting a timeout
In summary there are 5 possible results
Message
Meaning
Connected (with banner)
Can reach host and application
Connected (no banner)
Can reach host and application – probably
Refused
Can reach host but not application – probably
Unreachable
Cannot reach host
Timeout
Cannot reach host – probably
Figure 10 – summary of results and interpretations for TCP connections
If the application uses a UDP port things are trickier. First there are no standard utilities on OpenVOS for sending a UDP datagram. Second, a response can come back as either a UDP datagram or an ICMP message. The tuc.pl (test UDP connection) Perl script will send a datagram containing the current date-time to the specified host and port. It then waits for either a UDP datagram or an ICMP message. Ideally your application will return a message that is then displayed. Figure 11 shows that the listening application echoed the message sent by the script.
perl tuc.pl -i 172.16.1.116 -p 1830
Reply received on UDP socket from 164.152.77.128 message: echoed by udpecho.pl:
+sent by tuc.pl at Mon Aug 30 13:31:34 2010
ready 13:31:34
Figure 11 – UDP server application echoes received message
If the server is not listening on the target port it should send back a “destination port unreachable” message. Assuming that the message is received from the target IP address this means that you reached the server but no application was listening.
perl tuc.pl -i 172.16.1.116 -p 1830
ICMP Destination port unreachable message received from 172.16.1.116
ready 11:40:12
Figure 12 – target host sending a port unreachable message
Like the telnet tests, you can get ICMP messages indicating network and host issues and as I discussed above you get the senders IP address so you have a more definite starting point to begin your investigations.
perl tuc.pl -i 172.16.1.116 -p 1830
ICMP Destination network unreachable message received from 164.152.77.171
ready 11:43:50
perl tuc.pl -i 172.16.1.116 -p 1830
ICMP Destination host unreachable message received from 164.152.77.171
ready 11:44:54
Figure 13 – network and host unreachable messages
The above errors are probably two of the most common. Another indicates a routing loop
perl tuc.pl -i 172.16.1.116 -p 1830
ICMP Time exceeded , TTL expired in transit message received from 164.152.77.34
ready 11:45:39
Figure 14 – ICMP message indicating a routing loop
There are many other errors, some that indicate administrative action to prevent the flow of packets. You can be pretty sure that these messages indicate a firewall blocking your packets.
However, many applications expect a specifically formatted message. In that case you will probably be me met with silence. By default the script will timeout after 5 seconds and report “no response”.
perl tuc.pl -i 172.16.1.116 -p 1830
No response was received from 172.16.1.116
ready 16:43:26
Figure 15 – no response
If you want to wait longer (or shorter) you can use the “-t option”
perl tuc.pl -i 172.16.1.117 -p 1830 -t 10
No response was received from 172.16.1.117
ready 12:06:26
perl tuc.pl -i 172.16.1.117 -p 1830 -t 1
No response was received from 172.16.1.117
ready 12:06:32
Figure 16 – changing the default timeout
Silence is not necessarily bad. It could mean that you have reached the target host, it is listening on the target port but it just didn’t like the test message that was sent. Unfortunately, it could also mean that the test packet never made it to the target host and that any ICMP messages sent back to indicate that were blocked. If you have access to the server you can run the udpecho.pl Perl script which will append its own header and then echo whatever was sent to it (figure 11).
In summary
Message
Meaning
Application banner message
Can reach host and application
ICMP network/host message
Cannot reach host
ICMP port message from host
Can reach host but not application
No response, application sends banner message
Cannot reach host
No response, application does not send banner message
May or may not be able to reach host
Figure 17 – summary of results and interpretations for UCP connections

tcplisten.pl

# tcplisten.pl begins here

#

# Version 1.00 10-07-30

# This script has been tested on

#  Open VOS 17.0.2ah running Perl v5.8.0 built for i686-vos

#  Microsoft Windows XP Service Pack 3 running

#               ActiveState Perl v5.10.0 built for MSWin32-x86-multi-thread

#  Red Hat Linux 4AS-5.5 running

#                Perl v5.8.5 built for x86_64-linux-thread-multi

#

# noah.davids@stratus.com

#

use IO::Socket;

use Getopt::Long;

use Sys::Hostname;

use strict;

my ($result);

my ($localPort, $message, $peerAddr);

my ($newSock, $data);

$result = GetOptions (‘port=s’    => $localPort,

‘message=s’ => $message);

if (($result != 1) || !(defined($localPort)))

{

print “nnUsage:n”;

print “tperl tcplisten.pl -port PORT-NUMBER [-message MESSAGE]nn”;

exit;

}

if (!defined ($message))

{

print “No message specified – creating messagen”;

$message = “Connection accepted by tcplisten running on ” . hostname;

}

print “perl tcplisten.pl -port $localPort -message ‘” . $message . “‘n”;

my $sock = IO::Socket::INET->new(

Proto => ‘tcp’,

LocalPort => $localPort,

LocalAddr => ‘0.0.0.0’,

Listen => 1,

) or die “Could not create socket for port $localPort: $!n”;

while (1)

{

my $newSock = $sock->accept ();

print “Connected accepted from ” . $newSock->peerhost .

” at ” . localtime () . “n”;

print $newSock $message . “n”;

$newSock -> shutdown(2);

$sock->read($data, 1024); # wait to get a close indication */

$newSock->close();

}

#

# tcplisten.pl ends here

tuc.pl

# tuc.pl begins here

#

# Version 1.00 10-07-30

# This script has been tested on

#  Open VOS 17.0.2ah running Perl v5.8.0 built for i686-vos

#  Microsoft Windows XP Service Pack 3 running

#               ActiveState Perl v5.10.0 built for MSWin32-x86-multi-thread

#  Red Hat Linux 4AS-5.5 running

#                Perl v5.8.5 built for x86_64-linux-thread-multi

#

# noah.davids@stratus.com

#

use IO::Socket;

use IO::Select;

use Getopt::Long;

use strict;

my ($result);

my ($destIP, $destPort, $timeout, $result, $message, $flags);

my ($ready, $socket);

my ($x, $c, $icmpAlready);

$result = GetOptions (‘ip=s’      => $destIP,

‘port=s’    => $destPort,

‘timeout=s’ => $timeout);

if (($result != 1) || !(defined($destIP) && defined($destPort)))

{

print “nnUsage:n”;

print “tperl tuc.pl -ip DESTINATION-IP-ADDRESS ” .

“-port DESTINATION-PORT-NUMBERnn”;

exit;

}

if (!defined($timeout)) { $timeout = 5; }

elsif ($timeout > 15) { print “OK, but ” . $timeout .

” seems unreasonably long.n”; }

$message = “sent by tuc.pl at ” . localtime ();

my $sock = IO::Socket::INET->new(

Proto => ‘udp’,

PeerPort => $destPort,

PeerAddr => $destIP

) or die “Could not create socket for destination $destIP: $!n”;

my $isock = IO::Socket::INET->new(

Proto => ‘icmp’);

$sock->send($message) or die “Send error: $!n”;

$message = “”;

my $read_set = new IO::Select();

$read_set->add($sock);

$read_set->add($isock);

($ready) = IO::Select->select($read_set, undef, undef, $timeout);

$icmpAlready = 0;

$c = 0;

foreach $socket (@$ready)

{

$c = $c + 1;

if ($socket == $sock)

{

$x = “Reply received on UDP socket from “;

$socket->recv($message, 100, $flags);

if ($icmpAlready == 0)

{

if (length ($message) > 0)

{ print $x . $socket->peerhost . ” message: ” . $message . “n”; }

else { print $x . $socket->peerhost . “n”; }

}

}

else # icmp message received

{

$icmpAlready = 1;

$socket->recv($message, 100, $flags);

if (length ($message) > 98)

{ print “Unexpectedly long (” . length ($message) .

“) ICMP message from ” . $socket->peerhost .

” message: ” . $message . “n”; }

elsif (length ($message) < 52)

{ print “Unexpecedly short (” . length ($message) .

“) ICMP message from ” . $socket->peerhost . “n”; }

else # process icmp message

{

my $type = ord (substr ($message, 20, 1));

my $code = ord (substr ($message, 21, 1));

my $port = ord (substr ($message, 50, 1)) * 256 +

ord (substr ($message, 51, 1));

if ($port != $destPort)

{ print “Unexpected ICMP message received from ” .

$socket->peerhost . ” message : ” . substr ($message, 20) .

“n”; }

else # icmp message is good

{

if ($type == 3)

{

if ($code == 0) { print “ICMP Destination network ” .

“unreachable message received from ” .

$socket->peerhost . “n”; }

elsif ($code == 1) { print “ICMP Destination host ” .

“unreachable message received from ” .

$socket->peerhost . “n”; }

elsif ($code == 3) { print “ICMP Destination port ” .

“unreachable message received from ” .

$socket->peerhost . “n”; }

elsif ($code == 6) { print “ICMP Destination network ” .

“unknown message received from ” .

$socket->peerhost . “n”; }

elsif ($code == 7) { print “ICMP Destination host unknown ” .

“message received from ” . $socket->peerhost . “n”; }

elsif ($code == 8) { print “ICMP Source host isolated ” .

“message received from ” .

$socket->peerhost . “n”; }

elsif ($code == 9) { print “ICMP Network administratively ” .

“prohibited message received from ” .

$socket->peerhost . “n”; }

elsif ($code == 10) { print “ICMP Host administratively ” .

“prohibited message received from ” .

$socket->peerhost . “n”; }

elsif ($code == 11) { print “ICMP Network unreachable for ” .

“TOS message received from ” .

$socket->peerhost . “n”; }

elsif ($code == 12) { print “ICMP Host unreachable for ” .

“TOS message received from ” .

$socket->peerhost . “n”; }

elsif ($code == 13) { print “ICMP Communication ” .

“administratively prohibited message received from ” .

$socket->peerhost . “n”; }

else { print “Unexpected ICMP message received type = ” .

$type . “, code = ” . $code . ” from ” .

$socket->peerhost . “n”; }

} # if ($type == 3)

elsif (($type == 11) & ($code == 0))

{ print “ICMP Time exceeded , TTL expired in transit ” .

“message received from ” . $socket->peerhost . “n”; }

else { print “Unexpected ICMP message received type = ” .

$type . “, code = ” . $code . ” from ” .

$socket->peerhost . “n”; }

} # else # icmp message is good

} # else # process icmp message

} # else #icmp message received

} # foreach $socket (@$ready)

if ($c == 0) { print “No response was received from ” .

$sock->peerhost . “n”; }

#

# tuc.pl ends here

udpecho.pl

# udpecho.pl begins here

#

# Version 1.00 10-07-30

# This script has been tested on

#  Open VOS 17.0.2ah running Perl v5.8.0 built for i686-vos

#  Microsoft Windows XP Service Pack 3 running

#               ActiveState Perl v5.10.0 built for MSWin32-x86-multi-thread

#  Red Hat Linux 4AS-5.5 running

#                Perl v5.8.5 built for x86_64-linux-thread-multi

#

# noah.davids@stratus.com

#

use IO::Socket;

use IO::Select;

use Getopt::Long;

use strict;

my ($result);

my ($localPort, $debug, $result, $message, $flags);

my ($ready, $socket);

my ($x, $c);

$result = GetOptions (‘port=s’    => $localPort,

‘debug’     => $debug);

if (($result != 1) || !(defined($localPort)))

{

print “nnUsage:n”;

print “tperl udpecho.pl -port LOCAL-PORT-NUMBER [-debug]nn”;

exit;

}

if (defined($debug)) { print “local port number is ” . $localPort . “n”; }

my $sock = IO::Socket::INET->new(

Proto => ‘udp’,

LocalPort => $localPort

) or die “Could not create socket $!n”;

my $read_set = new IO::Select();

$read_set->add($sock);

$message = “”;

while (1)

{

($ready) = IO::Select->select($read_set, undef, undef, 300);

foreach $socket (@$ready)

{

$socket->recv($message, 100, $flags);

if (defined ($debug)) { print “Message from ” . $socket->peerhost .

” message: ” . $message . “n”; }

$socket->send(“echoed by udpecho.pl: ” . $message) or die “Send error: $!

+n”;

}

}

#

# udpecho.pl ends here