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.
- 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 184.108.40.206/32 brd 220.127.116.11 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 18.104.22.168 ;
network bit "32" which translates to
subnet mask 255.255.255.255 ;
broadcast address 22.214.171.124. 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 126.96.36.199
[linuxuser@centos7-hostadvice ~]$ ping -c 4 188.8.131.52 PING 184.108.40.206 (220.127.116.11) 56(84) bytes of data. 64 bytes from 18.104.22.168: icmp_seq=1 ttl=64 time=0.043 ms 64 bytes from 22.214.171.124: icmp_seq=2 ttl=64 time=0.061 ms 64 bytes from 126.96.36.199: icmp_seq=3 ttl=64 time=0.060 ms 64 bytes from 188.8.131.52: icmp_seq=4 ttl=64 time=0.063 ms --- 184.108.40.206 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 (220.127.116.11) 56(84) bytes of data. 64 bytes from centos7-hostadvice.c.sound-bay-179819.internal (18.104.22.168): icmp_seq=1 ttl=64 time=0.041 ms 64 bytes from centos7-hostadvice.c.sound-bay-179819.internal (22.214.171.124): icmp_seq=2 ttl=64 time=0.061 ms 64 bytes from centos7-hostadvice.c.sound-bay-179819.internal (126.96.36.199): icmp_seq=3 ttl=64 time=0.067 ms 64 bytes from centos7-hostadvice.c.sound-bay-179819.internal (188.8.131.52): 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 184.108.40.206
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 220.127.116.11 ;; Query time: 299 msec ;; SERVER: 18.104.22.168#53(22.214.171.124) ;; 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
$ host centos7-hostadvice
[linuxuser@centos7-hostadvice ~]$ host centos7-hostadvice centos7-hostadvice has address 126.96.36.199
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.confentries. 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.
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 188.8.131.52 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 184.108.40.206 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 220.127.116.11 0.0.0.0 255.255.255.255 UH 100 0 0 eth0
Note: the gateway ip address above is in the first line:
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
$ sudo vim /var/log/messages
$ 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.
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.