How to check Internet connection on Raspberry Pi

It is always frustrating when the internet becomes inaccessible, especially on your Raspberry Pi. There are numerous reasons why your internet access could go down, and we have to take various troubleshooting measures to identify the cause of the problem. Things get tricky when the internet connection is seemingly working fine, yet websites are refusing to load on the Raspberry Pi. In this tutorial, we will show you how to check the internet connection on a Raspberry Pi through step by step troubleshooting instructions.

In this tutorial you will learn:

  • How to test internet connection on Raspberry Pi
  • How to test DNS resolution on Raspberry Pi
  • How to check IP and default gateway settings on Raspberry Pi
  • How to check your DNS resolution on Raspberry Pi
How to check Internet connection on Raspberry Pi
How to check Internet connection on Raspberry Pi
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Raspberry Pi
Software curl, ping, dig
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Check Internet connection on Raspberry Pi step by step instructions




We will go through various steps below to troubleshoot the Internet connection on your Raspberry Pi. Each step can help to identify what the problem is on your Raspberry Pi, and give you hints on how to start fixing it.

NOTE
See our tutorial on Connecting Your Raspberry Pi to Wi-Fi: A How-To for help with getting your Raspberry Pi connected to Wi-Fi and begin troubleshooting your wireless connection.
  1. The most basic way to begin troubleshooting the internet connection on your Raspberry Pi is to try loading a website. If you are using a desktop environment GUI on your Raspberry Pi, then you can simply open Chromium (default browser) or another internet browser and try loading a website, such as https://linuxconfig.org.

    If you do not have a GUI and therefore no internet browser, we can use a command line tool such as wget or curl to test the connection to a website. Try executing the following command:

    $ curl https://linuxconfig.org
    
    Testing the internet connection on a Raspberry Pi with curl command
    Testing the internet connection on a Raspberry Pi with curl command

    You will see some HTML output in the terminal if your connection to the website was successful. This is the same type of content that your browser would attempt to load if you were to navigate to a website with it, except the browser is also able to render it into a design that humans can digest. Nevertheless, this tells us if we can load a website. If it does not work, then there could be a problem with your connection to the router (default gateway) or your ISP could be down.

  2. The ping command is one of the best ways to quickly troubleshoot connectivity problems between your Raspberry Pi computer and a remote website, server, or other type of host. It is best to start with trying to ping a server on the internet. A favorite one to use for testing would be Google’s public DNS server at IP address 8.8.8.8. Try sending four packets to the IP address and see what kind of response you get.
    $ ping -4 2 8.8.8.8
    




    Look for a 0% packet loss output, which indicates that your connection was successful. If this does not work, try pinging something local, such as your default gateway. If the ping to your default gateway or other local area device does not work, then you know the problem is much closer to your Raspberry Pi and not something online.

    Using the ping command on a Raspberry Pi
    Using the ping command on a Raspberry Pi
  3. The next step to try is to check that your interface IP address and routing information is valid. Check our tutorial on Finding Your Raspberry Pi’s IP Address: A Quick Guide for more in depth explanation, but the gist of it is executing this command to check IP address information:
    $ ip a
    

    And the following command to check your routing information:

    $ ip r
    

    Using the information from the output of the commands above, ensure that your ethernet or Wi-Fi interface, including the default gateway information, is configured correctly.

  4. If you are able to connect to servers on the internet via IP address, but not by domain name, then it indicates a problem with your DNS server. Either your DNS server is currently inaccessible, or perhaps has never been correctly configured on your Raspberry Pi. You can check the contents of the following file to see what your DNS server is:
    $ cat /etc/resolv.conf
    

    It is suggested to add Google’s public DNS server to the configuration file, if you suspect that misconfigured DNS settings are playing a role in your connectivity issues. Add the following line to the file:

    nameserver 8.8.8.8
    
  5. The dig command is a perfect way to see if your DNS problems have been resolved by the step above. Test your DNS server by using the following command syntax, replacing 192.168.198.2 with your DNS server.
    $ dig @192.168.198.2 linuxconfig.org
    

    In the screenshot below, you will see that our DNS server successfully replied with the IP addresses of where to find the domain name that we specified.

    Using the dig command to check for a valid DNS configuration on Raspberry Pi
    Using the dig command to check for a valid DNS configuration on Raspberry Pi

Closing Thoughts




In this tutorial, we saw how to check the internet connection on a Raspberry Pi system. This involved basic troubleshooting steps like testing the local IP address and default gateway configuration, DNS settings, and testing connectivity between local devices or servers on the internet. These commands should help you to isolate and identify the issue with your internet connection, and hopefully get it back up and running in a short amount of time.



Comments and Discussions
Linux Forum