1

In windows when you are connecting via wireless it's tell you if their is internet access or no. in ubuntu i already connect to router but i don't know if the router is connect to internet or not?!

How to know if the router is connected to internet or not on ubuntu

2 Answers 2

0

You probably are looking into Network and Sharing Center on windows, which says if you have internet or not, as shown bellow in the screen. But this is not always a reliable method. For example , on my college network, some computers say there's no internet, and yet I can surf internet just fine. enter image description here

heemayl alrady mentioned ping command which is the basic network testing tool on any system, windows or linux, and it is used in command line; the app for that is cmd on windows and terminal on ubuntu or any other linux distro, and macs. If you can ping -c4 google.com and get response, you have internet.

There's another method, graphical, using gnome-nettool, which is an app with network utilities all put together into graphical interface. Idea is the same, ping utility to test if you have response from internet; there's also traceroute, which will show if you can go past your router ip address to the internet or not.

Another way is through Unity Lenses and Scopes. Remember how when you type in dash when you search for some files, you get suggestions from amazon? well, that means those suggestions come from internet, right ? Personally, I have those disabled, so can't elaborate much on this.

But really, command line tools are far more reliable and much better and many linux users will strongly recommend you use those

1
  • on the signal icon on taskbar their sometimes a yellow triangle that tell you "no internet access" Apr 18, 2015 at 20:57
0

Run this in the terminal:

[[ $(ping -c4 google.com) ]] 2>~/ping_check.txt && echo "I have Internet" || echo "I don't have Internet"

For example:

$ [[ $(ping -c4 google.com) ]] 2>~/ping_check.txt && echo "I have Internet" || echo "I don't have Internet"
I have Internet

This uses the basic ping utility to send ICMP ECHO_REQUEST packets to the remote host and get the ECHO_REPLY from the remote host (google.com in this case). If the host is UP (& if the firewall at both end allowing ICMP), you will get response back from the remote host, otherwise not.

This one-liner has an added advantage, the error message (STDERR) will be saved in a file in your homw directory ~/ping_check.txt. If you don't have internet then you can check the file content and get an idea of the cause.

EDIT: Explanation of the command:

The command has three portions:

  • [[ $(ping -c4 google.com) ]] 2>~/ping_check.txt will ping "google.com" 4 times and 2>~/ping_check.txt will save any error message from the command in the file ~/ping_check.txt so that you can check it later for potential problem. As we are only concerned about the success or failure of the command ping -c4 google.com we have put it inside the bash keyword [[]] so that it will return true $? = 0 if the command succeeded or false $? != 0 if the command failed.

  • Then we have fairly simple command echo "I have Internet" which will just print I have Internet only if the previous returns success, this is ensured by &&. && indicates that the next command will run only if the previous command (ping) is successful.

  • the next part has echo "I don't have Internet" after ||. || means the next command will be run only if the previous command is successful ($? != 0). So I don't have Internet will be printed only if the ping command returns failure.

9
  • 2
    Ping != "internet" as sometimes one can ping but not connect to servers due to DNS failure. Sure it is a good first step, but is it really any better then opening firefox ?
    – Panther
    Apr 15, 2015 at 19:08
  • @bodhi.zazen: I have modified the answer..
    – heemayl
    Apr 15, 2015 at 19:49
  • Why don't you add a ping to 8.8.8.8 and tell the user if only dns isn't working? Apr 16, 2015 at 6:27
  • @WilhelmErasmus: it was the initial approach, the i have changed it to take DNS into account.
    – heemayl
    Apr 16, 2015 at 9:58
  • @heemayl but why not have it tell you if dns is available and if internet is available? Apr 16, 2015 at 11:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .