DEVOPS SERVICE
Devops Howto's GuideTroubleshooting Network Services in Linux
Written by devopsservice
Network service is an application and it is listening on specific ports. Below are the steps to troubleshoot network services in Linux. We will troubleshoot SSHD service for example.
1. Check the port on which service is listening using /etc/service file which gives information about different port used by service.
1
2
3
4
5
|
[root@devopsservice.com ~]# egrep -i '^ssh' /etc/services
ssh 22/tcp # The Secure Shell (SSH) Protocol
ssh 22/udp # The Secure Shell (SSH) Protocol
|
As you can see SSH is listening on port 22
2. Check using netstat command that SSHD is running on port 22.
1
2
3
4
5
6
|
[root@devopsservice.com ~]# netstat -nlp | grep -i ssh
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1323/sshd
tcp 0 0 :::22 :::* LISTEN 1323/sshd
[root@devopsservice.com ~]#
|
You can see that SSHD is listening on all interfaces.
We used different options with netstat command. Below is the use of each option.
-n : show the numerical IP only
-l : shows listening sockets only
-p: process ID attached to the socket
-l : shows listening sockets only
-p: process ID attached to the socket
We can also use “ss” command which will also show same output as netstat.
3. Use pgrep command to check the PID(Process ID) of SSH service and confirm as it is same as we have seen using netstat command. Netstat command show that PID of running SSHD is 1323. Other PID belongs to SSH are spawned SSH processes for different SSH connections.
1
2
3
4
5
6
|
[root@devopsservice.com ~]# pgrep -l ssh
1323 sshd
1736 sshd
[root@devopsservice.com ~]#
|
4. Use lsof to view which sockets are open by PID 2106, and it’s confirmed that IPv4 and IPv6 sockets are open and listening on port 22.
1
2
3
4
5
6
|
[root@devopsservice.com ~]# lsof -p 1323 | grep LISTEN
sshd 1323 root 3u IPv4 9570 0t0 TCP *:ssh (LISTEN)
sshd 1323 root 4u IPv6 9572 0t0 TCP *:ssh (LISTEN)
[root@devopsservice.com ~]#
|
5. Check port 22 is listening from other host.
1
2
3
4
|
devops2@devopsservice.com:~$ nc 192.168.16.78 22
SSH-2.0-OpenSSH_5.3
|
It seems that you are able to connect successfully.
The reason to try this is, when a firewall is blocking the service, it is still listening, but incoming connections are not allowed.
Because all six steps have worked, you can conclude that the service is running and listening, and that no firewall is blocking connections. The next step is to use the ssh command and determine whether the connection works or whether you get an error.
You can also troubleshoot other Linux services using same way.
Thanks for reading. Do let us know if you have any feedback/suggestions.
Let us know if you want us to write us on any particular topic. We will try our best.
All Rights Reserved © 2015-2016 Devopsservice.
LEAVE A REPLY