3

I'm connecting my pi via ethernet to my router and is assigned an IP address (via static DHCP) but I'm unable to connect to any outside network. The strange thing is I can also connect via WIFI dongle and able to access outside networks:

pi@raspberrypi ~ $ ifconfig
eth0  Link encap:Ethernet  HWaddr b8:27:eb:7f:50:3d
      inet addr:192.168.2.200  Bcast:192.168.2.255  Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:1068 errors:0 dropped:0 overruns:0 frame:0
      TX packets:1346 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:75076 (73.3 KiB)  TX bytes:183304 (179.0 KiB)

lo    Link encap:Local Loopback
      inet addr:127.0.0.1  Mask:255.0.0.0
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:8 errors:0 dropped:0 overruns:0 frame:0
      TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:1104 (1.0 KiB)  TX bytes:1104 (1.0 KiB)

wlan0 Link encap:Ethernet  HWaddr 60:e3:27:0e:50:1b
      inet addr:192.168.2.199  Bcast:192.168.2.255  Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:918 errors:0 dropped:10 overruns:0 frame:0
      TX packets:390 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:196056 (191.4 KiB)  TX bytes:62046 (60.5 KiB)

able to ping google (presumably via wlan0):

pi@raspberrypi ~ $ ping google.com
PING google.com (103.233.38.108) 56(84) bytes of data.
64 bytes from 103.233.38.108: icmp_req=1 ttl=58 time=22.2 ms
64 bytes from 103.233.38.108: icmp_req=2 ttl=58 time=21.3 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 21.357/21.810/22.263/0.453 ms

disable wlan0:

pi@raspberrypi ~ $ sudo ifdown wlan0

after disabling wlan0:

pi@raspberrypi ~ $ ping google.com
ping: unknown host google.com

more info:

pi@raspberrypi ~ $ more /etc/network/interfaces
auto lo

iface lo inet loopback

iface eth0 inet dhcp
#iface eth0 inet static
#address 192.168.2.200
#netmask 255.255.255.0
#gateway 192.168.2.1

allow-hotplug wlan0
iface wlan0 inet dhcp
#address 192.168.2.199
#netmask 255.255.255.0
#gateway 192.168.2.1

wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

pi@raspberrypi ~ $ more /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
2

I note that both your eth0 and wlan0 are connecting to the same 192.168.2.x LAN network. I have noticed previously on other computers (such as my windows laptop) with multiple connections to the same LAN - that the LAST interface connected is the one used to send packets out. Unfortunately when this is disconnected, the computer doesn't automatically switch to the first interface.

Since the wireless generally takes longer to connect, it usually ends up being the one which is used, even though the wired interface is faster.

Try disconnecting the Ethernet cable and reconnecting it. I think you will find that now disabling wlan0 has no effect because eth0 is now the default.

0

Well, it seems that the wifi dongle itself is the problem. I disconnected the dongle and the ethernet connection worked.

  • 1
    The dongle may be the problem, but then your /etc/network/interfaces has errors. If you left it the way it was it may work. – Milliways Oct 24 '15 at 22:28
  • what is the error in my /etc/network/interfaces? – Ric Sapasap Oct 25 '15 at 19:03
  • iface wlan0 inet dhcp should be iface wlan0 inet manual if you are going to use wpa_supplicant. The fact that you use dhcp at all is also a problem, unless you have an old Raspbian and/or particularly do not want to use the current WiFi configuration. – Milliways Oct 25 '15 at 22:35
0

I think this is how ifupdown handles the default route. You are using as nameserver 8.8.8.8 and 8.8.4.4. These are outside of your local network 192.168.2.0/24 so ip request for name google.com have to follow the default route (to the internet). If you down an interface and ifupdown does not set the default route properly because there is another interface up, then your request does not find the route to the nameservers. The response is unknown host google.com.

Check the situation with command ~$ route. With it you can see the kernels current routing table. Have a look at the default route and its interface Iface. Try to ping with interface eth0 or wlan0 e.g.:

ping -I eth0 google.com

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.