Guide for troubleshooting network services on a Linux system
This project is maintained by bertvv
The Internet layer is responsible for routing of network traffic between any hosts on the network. In order to be able to communicate, each host should have three settings configured correctly:
Before “reaching out” to other hosts, first check local settings.
The IP address may have been set automatically (DHCP), or manually. Check this in /etc/sysconfig/network-scripts/ifcfg-IFACE
, with IFACE the name of the network interface.
This is an exerpt from a network interface configuration file configured to use DHCP:
DEVICE="enp0s3"
ONBOOT="yes"
BOOTPROTO="dhcp"
Things to check:
DEVICE
should be the interface nameONBOOT
should be yes
, or the interface will not attempt to activate the interface on boot, or when restarting the network interfaces (systemctl restart network
)BOOTPROTO
should be set to dhcp
If a fixed IP address is set, the configuration should look like this:
DEVICE=enp0s8
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.56.24
NETMASK=255.255.255.0
DEVICE
and ONBOOT
like in the previous exampleBOOTPROTO
should be none
IPADDR
and NETMASK
must be specifiedUse the command ip address
(or shortcut ip a
) to list the IP addresses for each interface.
You should know the expected value: if not the exact IP, at least the network range or network IP and network mask.
Possible problems and causes (automatic IP assignment with DHCP):
Possible problems and causes (manual IP setting):
Usually, a host is connected to a LAN through a switch. Network traffic to the outside world goes through a router, connected to the same LAN. Every host on the LAN should know this router, the “default gateway”.
Use the command ip route
(or shortcut ip r
). There should be a line starting with default via x.y.z.w
.
Possible problems and causes (automatic IP assignment with DHCP):
In order to be able to resolve host names to IP addresses, every host should be able to contact a DNS server. View the file /etc/resolv.conf
. It usually has a header that mentions it was generated automatically, and should have one or more lines starting with nameserver
.
$ cat /etc/resolv.conf
# Generated by NetworkManager
search hogent.be
nameserver 193.190.173.1
nameserver 193.190.173.2
Possible problems and causes are equivalent to those with the default gateway setting.
If the previous settings are correct, you can check whether other hosts on the LAN can be reached.
ping a.b.c.d
A command like ping www.google.com
(for some the first command they try in case of network connection problems) is not very suitable, in that it depends on too many things to work at once:
Be aware that ping
(and other network troubleshooting tools like the traceroute
family) may not always work. Some system administrators will block ICMP traffic on routers, rendering the results useless.
A Windows sytem may also block ICMP traffic (including ping
). Be sure to check the firewall settings and if necessary, allow this type of network traffic. The following PowerShell one-liner does exactly that:
Get-NetFirewallRule -DisplayName "*Echo Request*" | Set-NetFirewallRule -enabled true
Having a DNS server configured in /etc/resolv.conf
does not necessarily mean that the service is actually available. Check this with e.g. the commands nslookup
or dig
(in the package bind-utils
).
$ dig www.google.com +short
216.58.213.196
$ nslookup www.google.com
Server: 193.190.173.1
Address: 193.190.173.1#53
Non-authoritative answer:
Name: www.google.com
Address: 216.58.213.228
Name: www.google.com
Address: 2a00:1450:4013:c04::67
You can query a specific DNS server (instead of the default one specified in /etc/resolv.conf
) by passing it as an argument:
$ dig www.google.com @8.8.8.8 +short
216.58.211.100
$ nslookup www.google.com 8.8.8.8
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: www.google.com
Address: 172.217.19.196
Name: www.google.com
Address: 2a00:1450:400e:809::2004
If nslookup
or dig
are not available, and installing bind-utils
is not an option, use getent ahosts
:
$ getent ahosts www.google.com
216.58.213.196 STREAM www.google.com
216.58.213.196 DGRAM
216.58.213.196 RAW
2a00:1450:4013:c04::67 STREAM
2a00:1450:4013:c04::67 DGRAM
2a00:1450:4013:c04::67 RAW