I finally managed to make wlan0 (an Edimax EW-7811Un USB WiFi dongle) connect to my router, but after an apt-get update I discovered that my Raspberry can't connect outside the local network. The Raspberry is running on the latest (as of writing this) Raspbian image.

  • wlan0 is connected to my router and has been given an IP address
  • I can ping my router, my printer, and other machines inside the local network, but I can't ping anything in the outside net (also loopback ping on localhost says "host unreachable", but I'd say that it is NAT cancelling requests)
  • I can successfully connect through eth0, but I need to connect through wlan0.

ifconfig output:

pi@MinoPi ~ $ ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr *macaddresshere*
      inet addr:  Bcast:  Mask:
      RX packets:552 errors:0 dropped:6 overruns:0 frame:0
      TX packets:289 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:375003 (366.2 KiB)  TX bytes:318051 (310.5 KiB)

iwconfig output:

pi@MinoPi ~ $ iwconfig wlan0
wlan0     IEEE 802.11bg  ESSID:"Sanctuary"  Nickname:"<WIFI@REALTEK>"
      Mode:Managed  Frequency:2.437 GHz  Access Point: *macaddresshere*
      Bit Rate:54 Mb/s   Sensitivity:0/0
      Retry:off   RTS thr:off   Fragment thr:off
      Power Management:off
      Link Quality=100/100  Signal level=100/100  Noise level=0/100
      Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
      Tx excessive retries:0  Invalid misc:0   Missed beacon:0

/etc/network/interfaces file:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

iface wlan0 inet static
    wpa-ssid "Sanctuary"
    wpa-psk "somePasswordHere"

Any ideas?

1 Answer 1


Problem solved! It seems that even though I added the gateway information into the interfaces file, wlan0 didn't really have a default gateway.

When I ran

sudo route -n

it yielded

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 wlan0

There it is - no Gateway IP. I typed this:

 sudo route add default gw

(where is an IP address of my router, which is connected to the outside net)

Et voilà: it works.

  • 5
    Anyone got any clue as to why the gateway isn't being added automatically?
    – Endareth
    Jan 5, 2016 at 3:47
  • 3
    @Błażej Michalik, I am using Raspberry PI 3 operating system. The problem is in masking the gateway Ip address and * persisting it * across reboots. How would you propose to maskthe gateway Ip address and * persist it * across reboots? Thanks
    – Frank
    Aug 19, 2016 at 14:31
  • @Frank Gateway IP is not masked, it is just an address, it's not a range of addresses. You have to add a gateway route to your routing tables. The masking of destination addresses is up to your local network setting. The route utility should add the address in a persistent way, but I think it is depreciated now, you can look up ip route (man ip). Aug 20, 2016 at 15:50
  • 2
    I am very much interested in the answer to @Endareth question - even more so in how to code a response for the raspberry pi to find and connect to a response automatically. If you give a raspberry pi as a gift to someone who doesn't know computers, it shouldn't stop operating immediately.
    – chase
    Mar 24, 2017 at 17:36

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