Troubleshooting 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

  1. If you don't find anything in the boot logs, then most probably, your network hardware is faulty or unsupported by Ubuntu.
  2. 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
  1. If you can see a line with link ok, then you have a working Ethernet connection.
  2. Next, check whether a proper IP address is assigned to the eth0 Ethernet port:
    $ ifconfig eth0
  1. 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.
  2. Even if you see a line stating the IP address, make sure that it is valid for network that you are connected to.
  3. 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 similarto iface eth0 inet dhcp:
    $ cat /etc/network/interfaces
ubuntu@ubuntu:/etc/haproxy$ sudo dhclient -v
Internet Systems Consortium DHCP Client 4.2.4
Copyright 2004-2012 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/eth0/00:0c:29:1c:fb:91
Sending on   LPF/eth0/00:0c:29:1c:fb:91
Sending on   Socket/fallback
DHCPREQUEST of 192.168.40.130 on eth0 to 255.255.255.255 port 67 (xid=0x2843ac78)
DHCPACK of 192.168.40.130 from 192.168.40.254
RTNETLINK answers: File exists
bound to 192.168.40.130 -- renewal in 847 seconds.


  1. If you can see a line similar to 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.
  2. Now, if you check the IP address again, you should see a newly IP address listed:
    $ ifconfig eth0
    
  3. Assuming that you have received a proper IP address, let's move on to the default gateway:
    $ ip route
default via 192.168.40.2 dev eth0  proto static 

192.168.40.0/24 dev eth0  proto kernel  scope link  src 192.168.40.128  metric 1 

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

ubuntu@ubuntu:/etc/haproxy$ sudo ufw status

Status: inactive



  1. Check the rules or temporarily disable the firewall and retry reaching your gateway:
    $ sudo ufw disable
    
  2. 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 8.8.8.8


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 8.8.8.8
ubuntu@ubuntu:/etc/haproxy$ mtr -r -c 1 8.8.8.8
Start: Sun Dec 25 11:28:18 2016
HOST: ubuntu                      Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- 192.168.40.2               0.0%     1    0.2   0.2   0.2   0.2   0.0

  2.|-- ???                       100.0     1    0.0   0.0   0.0   0.0   0.0


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:
nameserver 8.8.8.8

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


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.









Comments

Popular posts from this blog

HAproxy logging

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all

teamcity Automatic Agent Start under Linux