1

I am using a private hotspot to connect a Raspberry Py to internet. I've setup the password and the ssid in the /etc/network/interfaces file. With this configuration I'm able to connect to the wifi but I can't connect to internet.

pi@tenzo /etc $ ping google.com
PING google.com (173.194.40.2) 56(84) bytes of data.
From tenzo.local (192.168.1.115) icmp_seq=1 Destination Host Unreachable

I've asked around and they said it's a gateway issue. Running traceroute from a laptop connected to the same network I get:

userk@dopamine:~$ traceroute google.com
traceroute to google.com (216.58.212.110), 30 hops max, 60 byte packets
 1  192.168.43.1 (192.168.43.1)  2.423 ms  5.088 ms  5.084 ms
 2  * * *
 3  10.4.129.165 (10.4.129.165)  120.018 ms  120.027 ms  120.020 ms
 4  10.4.129.196 (10.4.129.196)  129.488 ms  129.490 ms  129.471 ms
 5  10.4.129.196 (10.4.129.196)  138.994 ms  141.969 ms  144.439 ms

Do you have any advice?

EDIT 1 I've added to the interfaces the gateway, address and netmask. SEE EDIT 2

Now, when I ping google.com I get the same error as before...

This is the output of route -n

pi@tenzo ~ $ route -n
Kernel IP routing table
Destination     Gateway       Genmask      Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1   0.0.0.0       UG    0      0        0 eth0
0.0.0.0         192.168.43.1  0.0.0.0       UG    303    0        0 wlan0
192.168.1.0     0.0.0.0      255.255.255.0   U     0      0        0 eth0
192.168.43.0    0.0.0.0      255.255.255.0   U     303    0        0 wlan0

EDIT 2 This is my interfaces file:

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static

address 192.168.1.115
netmask 255.255.255.0
gateway 192.168.1.1

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
        address 192.168.43.235
        netmask 255.255.255.0
        gateway 192.168.43.1
        wpa-ssid "UserKOnTheNet"
        wpa-psk "xxxxx"

This is the output of traceroute

pi@tenzo ~ $ traceroute google.com
traceroute to google.com (173.194.40.7), 30 hops max, 60 byte packets
 1  tenzo.local (192.168.1.115)  2995.172 ms !H  2995.058 ms !H  2995.016 ms !H
2

A gateway would need to be configured in your interfaces file; e.g., something like

iface wlan0 inet static
    address 192.168.x.y
    gateway 192.168.x.z
    netmask 255.255.255.0

would work (where x is your network number, y the address for your host, and z the address for your gateway). Obviously you need to retain your encryption settings, too.

If you're using dhcp on that interface, then something is wrong with your dhcp server.

EDIT: you should also make sure no other network interface has a gateway setting, or if it does, that the gateway setting on that interface is correct. A "gateway" or "default gateway" is a machine which offers a connection to the Internet. It is a valid configuration to have a network interface without a gateway line if no such host exists on that network connection.

In your case, assuming there is no internet router on the network that eth0 is linked to, you should ensure that the iface eth0 stanza looks like this:

iface eth0 inet static
    address 192.168.1.115
    netmask 255.255.255.0

i.e., what you already have, but without the gateway 192.168.1.1 line. (the indentation at the start of the line is optional, but does make the file easier to read).

  • Thanks for the reply. I've added what you suggested. Please see my Edit – UserK Aug 30 '15 at 15:56
  • did you run sudo service networking restart (or reboot your pi) after making that change? If not, the changes you made haven't been activated yet. – Wouter Verhelst Aug 31 '15 at 14:10
  • Yes I did it. It was using as gateway address the one of eth0... – UserK Aug 31 '15 at 14:16
0

By comparing the outputs of the traceroute google.com command I noticed that the working laptop connected to the internet throught the same wifi network had the first hop with the correct gateway address 192.168.43.1 and the Raspberry Pi had 1 tenzo.local (192.168.1.115) which is the static address of the eth0 interface.

I solved the problem using @Wouter Verhelst 's suggestion and disabling the eth0 interface with

sudo ifconfig eth0 down

Now the internet connection works!

  • you can also change it so that the line gateway 192.168.1.1 is removed from the iface eth0 stanza. That line is wrong, and won't work, and without it you should be able to use network over eth0 even if wireless is enabled. – Wouter Verhelst Aug 31 '15 at 14:13
  • Could you add this suggestion to you answer? How should I configure eth0 then? – UserK Aug 31 '15 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.