0

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=192.168.1.200/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

This is my file resolv.conf

nameserver 192.168.1.1

This is the result of my command, route -ne

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   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 8.8.8.8 I get

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

When I leave it set to DHCP then everything works.

Any ideas on what am I missing?

Cheers

  • A few questions: does it work if you leave it set to DHCP? Can you ping external hosts using IP address (e.g. 8.8.8.8)? 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 8.8.8.8 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=192.168.1.1 8.8.8.8 – 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 8.8.8.8 (8.8.8.8) 56(84) bytes of data. From 192.168.1.200 icmp_seq=1 Destination Host Unreachable – Andy K Jul 29 '18 at 16:40
2

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

rpi ~$ ping -c3 192.168.1.200
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=8.8.8.8.

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.

  • 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.