I'm trying to setup a static IP address on my WIFI that can access Internet.

this my file /etc/dhcpcd.conf

interface wlan0

static ip_address=
static routers=
static domain_name_servers=

This is my file resolv.conf


This is the result of my command, route -ne

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface         UG        0 0          0 wlan0   U         0 0          0 wlan0

I can connect through SSH to my pi, once the IP address has been changed.

However, when doing a sudo ping google.com, this is what I have

ping: unknown host google.com

When I ping I get

( 56(84) bytes of data. From icmp_seq=1 Destination Host Unreachable

When I leave it set to DHCP then everything works.

Any ideas on what am I missing?


  • A few questions: does it work if you leave it set to DHCP? Can you ping external hosts using IP address (e.g. What do you mean by 'I can connect through SSH onc the IP address has been changed'? Changed ho and to what? – Dirk Jul 29 '18 at 16:34
  • hi @Dirk, when we dhcp, yes it works. 2) No I cannot ping 3) I can connect to my pi through ssh once the IP address has changed to static one. It is more the pinging that does not work – Andy K Jul 29 '18 at 16:38
  • Please try to add static domain_name_servers= – Benny Jul 29 '18 at 16:38
  • checking @Benny – Andy K Jul 29 '18 at 16:39
  • @Benny added in the resolv.conf but same issue PING ( 56(84) bytes of data. From icmp_seq=1 Destination Host Unreachable – Andy K Jul 29 '18 at 16:40

First setup your Raspberry Pi to use default DHCP and check if everything works. Then notice the output from this commands:

rpi ~$ ping -c3
rpi ~$ ip -4 route
rpi ~$ cat /etc/resolv.conf

If you got a response from the ping of course you cannot use that ip address again. But even you don't got a response you are not on the save side that it will not be used later. For static ip_address use an ip address that will not be served by your DHCP server, most likely your router. Look at your router configuration what address range it use to serve ip addresses. Select an ip address that is not in this range but in the subnet of your local network.

For static routers use the ip address you got with ip -4 route. Use the ip address from the line default via ....

For static domain_name_servers use the ip address you got with cat /etc/resolv.conf. If in daubt use static domain_name_servers=

Never touch /etc/resolv.conf! It is mangaged by openresolv and may be overwritten.

It would help us you can tell if there are other devices on your network and if they can get into the internet, e.g. a PC or a MAC and what gateway and dns server it has configured. Also knowing the address range reserved for DHCP is very helpful.

| improve this answer | |
  • use the ip address for wlan0 you got with ip -4 addr no, some routers don't like it if you choose a static address within the DHCP address range :p – Jaromanda X Jul 30 '18 at 8:30
  • what I mean is, the router could issue that address to something else - I think the inform option in dhcpcd.conf can overcome that, but not sure – Jaromanda X Jul 30 '18 at 8:38
  • @JaromandaX With DHCP you are right if not using dhcpcd. But I guessed Andy K is using dhcpcd to reduce complexity. So I have looked at man dhcpcd.conf before answering: "If you set ip_address then dhcpcd will not attempt to obtain a lease and just use the value for the address with an infinite lease time." I will update my answer for this. – Ingo Jul 30 '18 at 8:48
  • sure, but the router is free to issue any IP address within the range of IP addresses it has at its disposal - there's the potential (though routers are probably smarter these days) for two devices to end up with the same IP address if you assign a static address within the DHCP address range of the router – Jaromanda X Jul 30 '18 at 8:51
  • @JaromandaX I know, I know - but I don't use dhcpcd so I have to learn a bit about it. And with your comment I have just learned that dhcpcd is a dhcp client (man dhcpcd). I've confused that with serving ip addresses. That's from the router, OK. What is the best way to find a not served free ip address? Pinging it will only help at the moment, may be served later. The best way is to look at the router what range it has reserved. Other solution? – Ingo Jul 30 '18 at 9:09

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.