24/7/365 Support

Troubleshooting Ubuntu network connectivity

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.

Getting ready

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.

How to do it…

Follow these steps to troubleshoot network connectivity:

Let's start with checking the network card. If it is working properly and is detected by Ubuntu. Check boot time logs and search for lines related to Ethernet, eth:

$ dmesg | grep eth

If you don't find anything in the boot logs, then most probably, your network hardware is faulty or unsupported by Ubuntu.

Next, check whether the network cable is plugged in and is working properly. You can simply check the LED indicators on the network card or use the following command:

$ sudo mii-tool

If you can see a line with link ok, then you have a working Ethernet connection.

Next, check whether a proper IP address is assigned to the eth0 Ethernet port:

$ ifconfig eth0

Check whether you can find a line that starts with 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.

Even if you see a line stating the IP address, make sure that it is valid for network that you are connected to.

Now assuming that you have not assigned an IP address, let's try to get dynamic IP address from the DHCP server. Make sure that eth0 is set for dynamic configuration. You should see line similar to iface eth0 inet dhcp:

$ cat /etc/network/interfaces

Execute the dhclient command to query the local DHCP server:

$ sudo dhclient -v

If you can see a line similar to bound to, 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.

Now, if you check the IP address again, you should see a newly IP address listed:

$ ifconfig eth0

Assuming that you have received a proper IP address, let's move on to the default gateway:

$ ip route

The preceding command lists our default route. In my case, it is Let's try to ping the default gateway:

$ ping –c 5

If you get a response from the gateway, this means that your local network is working properly. If you do not get a response from gateway, you may want to check your local firewall.

Check the firewall status:

$ sudo ufw status

Check the rules or temporarily disable the firewall and retry reaching your gateway:

$ sudo ufw disable

Next, check whether we can go beyond our gateway. Try to ping an external server. I am trying to ping a public DNS server by Google:

$ ping -c 5

If you successfully receive a response, then you have a working network connection. If this does not work, then you can check the problem with the mtr command. This command will display each router between your server and the destination server:

$ mtr -r -c 1

Next, we need to check DNS servers:

$ nslookup www.ubuntu.com

If you received an IP address for Ubuntu servers, then the DNS connection is working properly. If it's not, you can try changing the DNS servers temporarily. Add the nameserver entry to /etc/resolve.conf above other nameserver, if any:


At this point, you should be able to access the Internet. Try to ping an external server by its name:

$ ping -c 3 www.ubuntu.com

There's more…

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.

Help Category:

What Our Clients Say