How to Troubleshoot Network Connectivity Issues to Your Linux VPS

Introduction

In a fast-moving world, with high-end technology and mobile devices, many businesses rely heavily on websites which are hosted on web servers. This makes it very critical to maintain the web servers to be up all the time.

One of the main reasons a web server is down is network connectivity issues. There are many factors that could hinder network connection. Finding the root cause of the problem could prove challenging. Hence, in this article, we focus on how to troubleshoot and resolve network connectivity issues on Linux web server.

Pre-requisites

  • Linux VPS Setup – any Linux flavor, e.g. Ubuntu, Centos, Fedora, e.t.c
  • Access to ssh and sudo privileges
  • Basic Linux command and networking skills

1. Check if the Network Interface Is Up

$ ip address show eth0
[linuxuser@centos7-hostadvice ~]$ ip address show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000
  link/ether 42:01:0a:80:00:08 brd ff:ff:ff:ff:ff:ff
  inet 35.202.119.51/32 brd 35.202.119.255 scope global noprefixroute dynamic eth0
   	valid_lft 85814sec preferred_lft 85814sec
  inet6 fe80::4001:aff:fe80:8/64 scope link
   	valid_lft forever preferred_lft forever

Check for the following features:

UP: The network interface is enabled. If the interface is DOWN, run the command below to bring it up.

$ ip link set eth0 up

LOWER_UP: This indicates that the network signal is active.

The second line shows the ip address 35.202.119.51 ; network bit "32" which translates to subnet mask 255.255.255.255 ;  broadcast address 35.202.119.255. Ensure you have the correct ip address and subnet mask.

2. Check if you can reach the ip address of the web server

Ping using the ip address of the web server

$ ping -c 4 35.202.119.51
[linuxuser@centos7-hostadvice ~]$ ping -c 4 35.202.119.51
PING 35.202.119.51 (35.202.119.51) 56(84) bytes of data.
64 bytes from 35.202.119.51: icmp_seq=1 ttl=64 time=0.043 ms
64 bytes from 35.202.119.51: icmp_seq=2 ttl=64 time=0.061 ms
64 bytes from 35.202.119.51: icmp_seq=3 ttl=64 time=0.060 ms
64 bytes from 35.202.119.51: icmp_seq=4 ttl=64 time=0.063 ms
 
--- 35.202.119.51 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.043/0.056/0.063/0.012 ms

Ping using the hostname or domain of the web server

$ ping -c 4 centos7-hostadvice
[linuxuser@centos7-hostadvice ~]$ ping -c 4 centos7-hostadvice
PING centos7-hostadvice.c.sound-bay-179819.internal (35.202.119.51) 56(84) bytes of data.
64 bytes from centos7-hostadvice.c.sound-bay-179819.internal (35.202.119.51): icmp_seq=1 ttl=64 time=0.041 ms
64 bytes from centos7-hostadvice.c.sound-bay-179819.internal (35.202.119.51): icmp_seq=2 ttl=64 time=0.061 ms
64 bytes from centos7-hostadvice.c.sound-bay-179819.internal (35.202.119.51): icmp_seq=3 ttl=64 time=0.067 ms
64 bytes from centos7-hostadvice.c.sound-bay-179819.internal (35.202.119.51): icmp_seq=4 ttl=64 time=0.063 ms
 
--- centos7-hostadvice.c.sound-bay-179819.internal ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.041/0.058/0.067/0.010 ms

If ping reports no connectivity, then the issue could be firewall which has blocked ICMP requests.

Also, try to ping the server from a remote machine or through a different network. If it reports no network connectivity. Then use traceroute to check the path to the network and see at which point/hop exactly the server is down.

$ traceroute 35.202.119.51

3. Check name resolution

If ping by IP address works but ping by hostname fails, then you have name resolution problems:

To resolve this:

Ensure you have correct IP address entries for DNS nameservers in the file “/etc.resolv.conf”

$ sudo vim /etc/resolv.conf

Check name resolution

$ dig centos7-hostadvice
 
[linuxuser@centos7-hostadvice ~]$ dig centos7-hostadvice
 
; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.2 <<>> centos7-hostadvice
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18106
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
 
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;centos7-hostadvice.       	IN  	A
 
;; ANSWER SECTION:
centos7-hostadvice.    3600	IN  	A       35.202.119.51
 
;; Query time: 299 msec
;; SERVER: 35.202.119.51#53(209.126.212.51)
;; WHEN: Wed Jun 13 09:30:52 PDT 2018
;; MSG SIZE  rcvd: 64

Note: the answer section should map the hostname to the ip address of the web server. If you don’t receive the answer section, then there is an issue with the dns servers – Check the /etc/resolv.conf entries.

$ host centos7-hostadvice
[linuxuser@centos7-hostadvice ~]$ host centos7-hostadvice
centos7-hostadvice has address 35.202.119.51

Note: The output should map the hostname to the IP address of the web server. Also if you don’t get any output, then there is an issue with the DNS servers – Check the /etc/resolv.conf entries. If it maps to the wrong IP address, then you should edit the file /etc/hostsand add the correct IP address entry for your web server.

Sample /etc/hosts output

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1     	localhost localhost.localdomain localhost6 localhost6.localdomain6
35.202.119.51 centos7-hostadvice centos7-hostadvice.c.sound-bay-179819.internal

4. Check Route or Default Gateway Settings

If you cannot reach your gateway using traceroute command, then run:

$ route -n
[linuxuser@centos7-hostadvice ~]$ route -n
Kernel IP routing table
Destination     Gateway     	Genmask     	Flags Metric Ref	Use Iface
0.0.0.0         35.202.119.1  	0.0.0.0     	UG    100    0        0 eth0
10.128.0.0      0.0.0.0     	255.255.255.0   U     0  	0    	0 tun0
10.128.0.1      0.0.0.0     	255.255.255.255 UH	100	0        0 eth0
35.202.119.51      0.0.0.0     	255.255.255.255 UH	100	0        0 eth0

Note: the gateway ip address above is in the first line: 35.202.119.1

If the gateway IP address is wrong, add the correct default gateway settings by:

$ route add default gw <router-gateway-ip-address> eth0

5. Check for Incorrect Initialization of the System

Initialization refers to the processes run when the Linux machine is booting. The log output of all the processes run during the boot processes is saved in /var/log/messages.

$ sudo vim /var/log/messages

OR

$ dmesg | more

Check for any errors that could have caused network problems

6. Check for security settings

$ sudo vim /etc/hosts.allow
$ sudo vim /etc/hosts.deny

Check if the web server has blocked or allowed access from specific clients.

Conclusion

The steps above are the basic tools you can use to diagnose and resolve network issues. All VPS web hosting customers should know networking basics, including these tools to diagnose and resolve network issues.

If these steps don't resolve the issues, contact your web hosting service. If these issues persist, and your web hosting service's support is unable to resolve them, you should consider switching to another Web host. Consult HostAdvice to find the Best VPS hosting services

 

Check out these top 3 VPS services:

Was this article helpful?