Networking consists of various components and services working together to enable systems to communicate with each other. A lot of times it happens that everything seems good, but we are not able to access other servers or the Internet. In this recipe, we will look at some tools provided by Ubuntu to troubleshoot the network connectivity issues.
As you are reading this recipe, I am assuming that you are facing a networking issue. Also, I am assuming that the problems are with a primary network adapter, eth0
.
You may need access to root account or account with similar privileges.
Follow these steps to troubleshoot network connectivity:
eth
:$ dmesg | grep eth
$ sudo mii-tool
link ok
, then you have a working Ethernet connection.eth0
Ethernet port:$ ifconfig eth0
inet addr
. If you cannot find this line or it is listed as inet addr 169.254, then you don't have an IP address assigned.eth0
is set for dynamic configuration. You should see line similar to iface eth0 inet dhcp
:$ cat /etc/network/interfaces
dhclient
command to query the local DHCP server:$ sudo dhclient -v
bound to 10.0.2.15
, then you are assigned with a new IP address. If you keep getting DHCPDISCOVER
messages, this means that your DHCP server is not accessible or not assigning an IP address to this client.$ ifconfig eth0
$ ip route
10.0.2.2
. Let's try to ping the default gateway:$ ping –c 5 10.0.2.2
$ sudo ufw status
$ sudo ufw disable
$ ping -c 5 8.8.8.8
mtr
command. This command will display each router between your server and the destination server:$ mtr -r -c 1 8.8.8.8
$ nslookup www.ubuntu.com
nameserver
entry to /etc/resolve.conf
above other nameserver
, if any:nameserver 8.8.8.8
$ ping -c 3 www.ubuntu.com
The following are some additional commands that may come handy while working with a network:
lspci
lists all pci devices. Combine it with grep
to search for specific device.Lsmod
shows the status of modules in Linux kernels.ip link
lists all the available network devices with status and configuration parameters.ip addr
shows the IP addresses assigned for each device.ip route
displays routing table entries.tracepath
/traceroute
lists all the routers (path) between local and remote hosts.iptables
is an administration tool for packet filtering and NAT.dig
is a DNS lookup utility.ethtool
queries and controls network drivers and hardware settings.route
views or edits the IP routing table.telnet
was the interface for telnet protocol. Now it is a simple tool to quickly check remote working ports.Nmap
is a powerful network mapping tool.netstat
displays network connections, routing tables, interface stats, and more.ifdown
and ifup
start or stop the network interface. They are similar to ifconfig down
or ifconfig up
.