Adri74100
Posts: 8
Joined: Mon Jul 08, 2019 2:36 pm

Setting static IP address on a Pi 4

Mon Jul 08, 2019 2:45 pm

Hi,

I would like to set a static IP address on a Raspberry pi 4.
Actually, the Pi is connected with Wifi and ethernet, both with DHCP.
I connect using Putty (SSH).

I tried "nano /etc/dhcpcd.conf" :

Code: Select all

interface eth0
static ip_address=192.168.11.210/24
static routers=192.168.11.254
static domain_name_servers=192.168.11.254
After a reboot, "ip addr" shows :

Code: Select all

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether dc:a6:32:00:62:ac brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.33/24 brd 192.168.11.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::e4ec:8456:daf1:b7be/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether dc:a6:32:00:62:ad brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.48/24 brd 192.168.11.255 scope global noprefixroute wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::1f11:5fa:9945:f19b/64 scope link
       valid_lft forever preferred_lft forever
And of course, the Pi isn't reachable with the 192.168.11.210 address.
Do you have any suggestions ?

epoch1970
Posts: 3364
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Setting static IP address on a Pi 4

Mon Jul 08, 2019 3:36 pm

Check the DHCP range of addresses that are managed by the DHCP server.
The static IP .210 you want for yourself must be outside the range. Otherwise the server might well refuse to comply with the request and give the client another address, like .33 here.

In fact, do the other way around:
- configure the DHCP server to identify the MAC address of the Pi and always give it .210, from the pool
- revert to standard configuration in dhcpcd.conf.
You'll have your fixed .210 address on your LAN, and on other networks the Pi will work without need for reconfiguration.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Adri74100
Posts: 8
Joined: Mon Jul 08, 2019 2:36 pm

Re: Setting static IP address on a Pi 4

Mon Jul 08, 2019 3:46 pm

Hi, and thanks for your help.

Our DHCP range is from 192.168.11.1 to 99, but we are voluntarily setting the fixed IP addresses outside of this range. And we already have a lot of servers in that case (Windows).

So, I can't set a MAC binding for the .210 IP on the router, because this IP is outside of the DHCP range.

Maybe I should follow the second solution here, which involves disabling the DHCP client on the Pi ?
https://raspberrypi.stackexchange.com/q ... 4428#74428

epoch1970
Posts: 3364
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Setting static IP address on a Pi 4

Mon Jul 08, 2019 3:50 pm

Then it should work as is.
Check there isn't another machine using .210 on the network...

(You can do whatever you want on that machine, it is yours. But assuming the dhcp client does not work as it should and uninstalling it looks more inspired by hubris than logic.)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

JohnSoCalUSA
Posts: 10
Joined: Sun Jul 07, 2019 6:11 pm

Re: Setting static IP address on a Pi 4

Mon Jul 08, 2019 3:56 pm

Adri74100 wrote:
Mon Jul 08, 2019 3:46 pm
Maybe I should follow the second solution here, which involves disabling the DHCP client on the Pi ?
https://raspberrypi.stackexchange.com/q ... 4428#74428
Are you using Raspbian Buster?
I had a problem with dhcpcd crashing.
Try running dhcpcd from the command line and see what happens.

Adri74100
Posts: 8
Joined: Mon Jul 08, 2019 2:36 pm

Re: Setting static IP address on a Pi 4

Mon Jul 08, 2019 4:00 pm

epoch1970 wrote:
Mon Jul 08, 2019 3:50 pm
Then it should work as is.
Check there isn't another machine using .210 on the network...

(You can do whatever you want on that machine, it is yours. But assuming the dhcp client does not work as it should and uninstalling it looks more inspired by hubris than logic.)
I tried to ping this IP and checked the router, I'm pretty sure it's unused (but I forgot to check that, you were right !).

I thought of uninstalling the DHCP client because you said "the server might well refuse to comply with the request", and I thought the DHCP client could interfere with the fixed IP address I configured in dhcpcd.conf.
So I won't proceed that way for now, and wait for other answers !
Last edited by Adri74100 on Mon Jul 08, 2019 4:04 pm, edited 1 time in total.

Adri74100
Posts: 8
Joined: Mon Jul 08, 2019 2:36 pm

Re: Setting static IP address on a Pi 4

Mon Jul 08, 2019 4:03 pm

JohnSoCalUSA wrote:
Mon Jul 08, 2019 3:56 pm
Adri74100 wrote:
Mon Jul 08, 2019 3:46 pm
Maybe I should follow the second solution here, which involves disabling the DHCP client on the Pi ?
https://raspberrypi.stackexchange.com/q ... 4428#74428
Are you using Raspbian Buster?
I had a problem with dhcpcd crashing.
Try running dhcpcd from the command line and see what happens.
Yes, Raspbian Buster Lite.
dhcpcd returns
sending commands to master dhcpcd process

JohnSoCalUSA
Posts: 10
Joined: Sun Jul 07, 2019 6:11 pm

Re: Setting static IP address on a Pi 4

Mon Jul 08, 2019 4:46 pm

Adri74100 wrote:
Mon Jul 08, 2019 4:03 pm
Yes, Raspbian Buster Lite.
dhcpcd returns
sending commands to master dhcpcd process
At least you did not get an error like I did.
You might want to try this command line to see if this works.

sudo dhcpcd -4 -S ip_address=192.168.11.210/24 \
-S routers=192.168.11.254 \
-S domain_name_servers=192.168.11.254 \
eth0

drgeoff
Posts: 9626
Joined: Wed Jan 25, 2012 6:39 pm

Re: Setting static IP address on a Pi 4

Mon Jul 08, 2019 6:17 pm

You did save dhcpcd.conf file before rebooting?

DirkS
Posts: 9876
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Setting static IP address on a Pi 4

Mon Jul 08, 2019 7:02 pm

drgeoff wrote:
Mon Jul 08, 2019 6:17 pm
You did save dhcpcd.conf file before rebooting?
+1
also make sure it was actually saved as you need admin rights to do that.

Adri74100
Posts: 8
Joined: Mon Jul 08, 2019 2:36 pm

Re: Setting static IP address on a Pi 4

Tue Jul 09, 2019 6:33 am

JohnSoCalUSA wrote:
Mon Jul 08, 2019 4:46 pm
Adri74100 wrote:
Mon Jul 08, 2019 4:03 pm
Yes, Raspbian Buster Lite.
dhcpcd returns
sending commands to master dhcpcd process
At least you did not get an error like I did.
You might want to try this command line to see if this works.

sudo dhcpcd -4 -S ip_address=192.168.11.210/24 \
-S routers=192.168.11.254 \
-S domain_name_servers=192.168.11.254 \
eth0
This command returns "sending commands to master dhcpcd process". And ip addr still shows another IP for eth0... even after a reboot.

For the others comments : yes I saved the file, and I connect as root. I'm used to configure some Debian web servers.

pcmanbob
Posts: 6449
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Setting static IP address on a Pi 4

Tue Jul 09, 2019 10:34 am

So first question, are you connecting to a standard domestic broadband router or is it a work or university network ?

what happens if you remove one of the connections to the network , having both wired and wireless connection to the same network may not be a good idea.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Adri74100
Posts: 8
Joined: Mon Jul 08, 2019 2:36 pm

Re: Setting static IP address on a Pi 4

Tue Jul 09, 2019 10:50 am

pcmanbob wrote:
Tue Jul 09, 2019 10:34 am
So first question, are you connecting to a standard domestic broadband router or is it a work or university network ?

what happens if you remove one of the connections to the network , having both wired and wireless connection to the same network may not be a good idea.
Hi, and thanks for your help !

It is at work, the router is a Zyxel USG60.
I disabled the Wifi connection, but the Pi is still accesible at the .33 address :cry:

pcmanbob
Posts: 6449
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Setting static IP address on a Pi 4

Tue Jul 09, 2019 11:01 am

Adri74100 wrote:
Tue Jul 09, 2019 10:50 am
It is at work, the router is a Zyxel USG60.

Then the first thing you should do it talk to the network admin to see if there is anything set on the router that prevents static IP addresses being set on a device.

if you had given us this information at the start you would have got this advice as the first response.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Adri74100
Posts: 8
Joined: Mon Jul 08, 2019 2:36 pm

Re: Setting static IP address on a Pi 4

Tue Jul 09, 2019 11:29 am

pcmanbob wrote:
Tue Jul 09, 2019 11:01 am
Adri74100 wrote:
Tue Jul 09, 2019 10:50 am
It is at work, the router is a Zyxel USG60.

Then the first thing you should do it talk to the network admin to see if there is anything set on the router that prevents static IP addresses being set on a device.

if you had given us this information at the start you would have got this advice as the first response.
As I already said : we already have a lot of servers in that case (with a fixed IP address, outside of the DHCP range).

However, I tried configuring my laptop to use this IP address, and I couldn't make it work.
So, the problem is probably not on the Raspberry side !

I contacted the network admin and will keep you informed.

Adri74100
Posts: 8
Joined: Mon Jul 08, 2019 2:36 pm

Re: Setting static IP address on a Pi 4

Tue Jul 23, 2019 8:48 am

Hi everyone,

For the record : I tried with another IP address (.211 instead of .210) and everything worked fine !
So, the procedure mentionned in my first post is okay.

Thanks for your help.

Hcgrant
Posts: 17
Joined: Sun Oct 14, 2012 4:51 pm

Re: Setting static IP address on a Pi 4

Wed Jul 31, 2019 3:29 pm

I also thought Buster was not letting me set a static ip .. but thanks to this I looked at the router and found that the ip was already in use!
So thanks :)

Return to “Beginners”