How to Check if a Service is Running and Accessible

Good afternoon, guys ­čÖé

Today, i’m going to share about how to check if a service is running and accessible from public. ┬áI create this is just to remind us after we installing an application or service that runs on a port, the application is accessible from public.

For the test, for example i installed a nginx for our web server and postgresql for the DB Server. We all know that by default nginx will runs on port 80 and postgresql on port 5432. Then, we want our DB server only accessible from web server.

First thing to know that, we have to change the postgresql configuration file in /var/lib/pgsql/data/pg_hba.conf and /etc/postgresql/8.2/main/postgresql.conf. On pg_hba.conf, we add following line to give access to our network (e.g. :

host all all trust

While on postgresql.conf file, we change below parameter:


After that all, start the postgresql service.

To check the web server is connected to DB server, we can use telnet command like below from our web server:

telnet [db server hostname] 5432

if connected, it should give us result like below:

Connected to
Escape character is '^]'.
Connection closed by foreign host.

After that, we should check it from other host too. It is to make sure no server can access the DB server except the web server.

Beside that, to check port is in use on a server we can use nmap command like below:


If it give us result that port 5432 is open, then we can conclude that our db service is running.

Practice above is always give us a positive return, but what if we got a negative return? Port is already open but we can not access it?

Well, maybe you should check your firewall so you can access both web server or DB server.

If you use Ubuntu, you can simply using below command:

sudo ufw allow 80/tcp

If you use Centos, you can use below command:

sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT

Otherwise, if you use NAT (Network Address Translations) on your environment, make sure you are binding a right port to a right address like below:

Public IP
public port
Private IP
private port

So that’s all, guys. Maybe it sounds so mainstream or basic. But, i hope it would help us to setup our deployment correctly ­čÖé

Leave a Reply

Your email address will not be published. Required fields are marked *