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

Ingo
  • 42,107
  • 20
  • 85
  • 197
Andy K
  • 123
  • 8

1 Answers1

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.

Ingo
  • 42,107
  • 20
  • 85
  • 197
  • 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 08: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 08: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 08: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 08: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 09:09
  • well, router DHCP settings usually include a range (100-199) or a first/length (100/100) setting - in this example you'd just avoid x.x.x.100 to x.x.x.199 – Jaromanda X Jul 30 '18 at 09:13
  • Your suggestion to first use DHCP is very sound advice, esp. since the OP hasn't provided any details on his gateway. Nor has he declared if his router serves any other hosts on his network successfully. ISP-provided routers do very weird things these days, and there's just no way to anticipate that. Also, I wonder if you might get some traction by adding a step in your answer that has the OP look at his PC/Mac network config to verify he's got his bearings straight? – Seamus Jul 30 '18 at 11:46
  • @Seamus can you edit my answer? I will accept it. – Ingo Jul 30 '18 at 12:27
  • I think you're on the right track... I had just completed my answer to the Q you posted re DHCP, but your Q was put "on hold" ... Timing is everything :) I've asked goldilocks for a suggestion on how to proceed, but no response yet. If I don't hear something soon, I'll post it all in an edit to your answer, and then it's up to you to decide if it makes any sense :) ha ha – Seamus Jul 30 '18 at 12:39
  • Have just seen that. Or you can make it an answer here, maybe with little adjustments? – Ingo Jul 30 '18 at 12:43
  • No, I'm out of time for a while, so why don't you just add something to your answer? You might suggest the OP do something to verify that his gateway/DHCP server is functioning; e.g. if he's using a PC, and he can reach the Internet, what's the PC's gateway and DNS? Network questions are always obtuse because there's so much most people just aren't aware of, and it makes it tough to even ask a proper question. It always comes down to a process of elimination (i.e. time consuming). – Seamus Jul 30 '18 at 12:58
  • And BTW, take my answer to your question w/ a 'grain of salt'... I think it's correct, but DHCP has become very nuanced... they now have RFCs on DHCP options :) – Seamus Jul 30 '18 at 13:01
  • @Seamus Done - (updating answer) – Ingo Jul 30 '18 at 16:22