sandy1
Posts: 4
Joined: Sat Jul 13, 2019 3:51 pm

How to set up a static IP using Raspbian Buster

Sun Jul 14, 2019 2:51 pm

Hi,

I am very new to all this raspberry pi server stuff. I am trying to set up a static IP. All of the tutorials I have followed are written for Jessie, and don't seem to work with buster. Can someone explain to me how to do it?

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

Re: How to set up a static IP using Raspbian Buster

Sun Jul 14, 2019 4:58 pm

"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

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

Re: How to set up a static IP using Raspbian Buster

Sun Jul 14, 2019 5:29 pm

Hi.

Since Raspbian Jessie setting a static IP on your pi has remained the same for both stretch and buster.

you just need to edit the file dhcpcd.conf with the command

Code: Select all

sudo nano /etc/dhcpcd.conf
in there you will find an example for setting a static IP, here is a copy from one of my pis

Code: Select all

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# Most distributions have NTP support.
#option ntp_servers

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private

# static IP configuration:
interface eth0
static ip_address=192.168.1.14/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=192.168.1.1
static domain_name_servers=192.168.1.251 

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
which has a static IP set.

You do need to understand your network addressing and know what your routers IP and DNS server IP's as well, before you can set a static IP.
Your static Ip should also be out side of the address range that your DHCP server in your can assign or you will end up with address conflicts.

The safer and often simpler option is to use reserved IP addressing in your router if it supports it.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

sandy1
Posts: 4
Joined: Sat Jul 13, 2019 3:51 pm

Re: How to set up a static IP using Raspbian Buster

Mon Jul 15, 2019 3:09 pm

Hi. Thank you for your reply. I tried following those instructions, but with no avail. It did not work. And on top of no static IP, Apache2 stopped working and

Code: Select all

sudo ifconfig
no longer showed an address. Any ideas?

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

Re: How to set up a static IP using Raspbian Buster

Mon Jul 15, 2019 3:20 pm

No idea. Post your config files, that should help.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

sandy1
Posts: 4
Joined: Sat Jul 13, 2019 3:51 pm

Re: How to set up a static IP using Raspbian Buster

Mon Jul 15, 2019 3:35 pm

I reverted them back to the original state

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

Re: How to set up a static IP using Raspbian Buster

Mon Jul 15, 2019 3:41 pm

Good move.
It is better to configure your router to give always the same IP address to a machine, rather than fiddling with manual IP config.
See the configuration pages of the DHCP server in your router.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

sandy1
Posts: 4
Joined: Sat Jul 13, 2019 3:51 pm

Re: How to set up a static IP using Raspbian Buster

Mon Jul 15, 2019 3:42 pm

Have solved the problem. I made the correct edits to /etc/dhcpcd.conf, but then added this line to /etc/network/interfaces:

Code: Select all

interface eth0 manual
A quick reboot and the problem was fixed.

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

Re: How to set up a static IP using Raspbian Buster

Mon Jul 15, 2019 3:58 pm

sandy1 wrote:
Mon Jul 15, 2019 3:42 pm
Have solved the problem. I made the correct edits to /etc/dhcpcd.conf, but then added this line to /etc/network/interfaces:

Code: Select all

interface eth0 manual
A quick reboot and the problem was fixed.
Editing /etc/network/interfaces is not needed nor expected in the general case (as here) in Raspbian. It's been link that for a few releases.
Glad it works for you, though.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
peterscargill
Posts: 16
Joined: Fri Apr 17, 2015 10:40 pm
Location: Northumberland
Contact: Website

Re: How to set up a static IP using Raspbian Buster

Sat Aug 10, 2019 11:16 am

Tried that interfaces trick, didnt work. Still no ip address on ETH0. With earlier Buster no problem, fully up to date yesterday, now Pi4 static addressing not working- fine on Pi3, just P4. I've been doing apt-get upgrade regularly but yesterday for the first time did apt-get didt-upgrade then apt-get dist-upgrade - Pi3 and Pi3B2 fine, everything works, but Pi4 will not form static IP address using dhcpcd.conf even with that interfaces mod. If I put the previous SD in P4, all is fine. If I put the new SD in a Pi3 all is fine
Regards

Peter Scargill (tech.scargill.net)

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

Re: How to set up a static IP using Raspbian Buster

Sat Aug 10, 2019 11:36 am

My pi4 running buster lite is fully up to date as of yesterday and static IP set in dhcpcd.conf still works just fine without the need for any additional lines in interfaces files.

So is your static IP outside of the address range that your router DHCP can address ?

may be post the contents of your dhcpcd.conf file.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

CTGreybeard
Posts: 7
Joined: Fri Nov 27, 2015 2:35 pm
Location: Western Connecticut, USA

Re: How to set up a static IP using Raspbian Buster

Mon Oct 07, 2019 5:00 pm

Any resolution to this yet? I changed out my Pi3 for a new Pi4 using the same SD card (Buster) and suddenly could not get a static IP which I had set for a long time in dhcpcd.conf.

I did discover that if I run

Code: Select all

sudo dhchcd --rebind eth0
it does come up. I tried the "fix" mentioned above but it did not fix it.

I set a static IP in the router and that did not fix it but the dhcpcd is still set to static also.

Second try, I added

Code: Select all

reboot 10
to the dhcp.conf, no change. I also tried

Code: Select all

waitip 4
but that caused a dhcp timeout at startup and didn't fix anything.

So I looked at the systemd journal

Code: Select all

journalctl _SYSTEMD_UNIT=dhcpcd.service
and I find that there are multiple

Code: Select all

control command: \sbin\dhcpcd -f eth0
entries, each of which deletes the interface and ips.

Where are those coming from??

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

Re: How to set up a static IP using Raspbian Buster

Mon Oct 07, 2019 6:45 pm

First is the IP you are trying to set on the pi outside of the address range that your router can assign ?

Secondly post you dhcpcd.conf file contents , and if you have a working connection to your router when you have no static IP set then post the results of ifconfig too.

I would also suggest you reboot your router to clear the connected devices table.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

CTGreybeard
Posts: 7
Joined: Fri Nov 27, 2015 2:35 pm
Location: Western Connecticut, USA

Re: How to set up a static IP using Raspbian Buster

Mon Oct 07, 2019 7:21 pm

My problem is not my router as I am able to use the same SD card in the original Pi3 and it works fine. Looking in syslog I see "/sbin/dhcpcd -k eth0" several times. Looking at syslog, each time dhcp has come up, assigned the correct IP then promptly destroys it via this command. This does not happen on the Pi3. Also, when I tried using a "true" dynamic IP and not the static one I need it still does not work, dhcpcd destroys the interface right after establishing it.

For the time being I have enabled WiFi and am using the same dhcpcd.conf settings to get the correct IP on the wlan0 interface, this is working fine. The issue only seems to be with the eth0 interface.

After the system has booted a "dhcpcd --rebind eth0" gets a good (dynamically assigned in this case) IP. That also, when I tested before, would assign the correct static IP to eth0 but ONLY if I did that after logging into the console and running the command. For me, as I usually run headless, this was not a good solution. A kludge would be to make a systemd timer that ran x seconds after boot to do the --rebind ...

The problem appears to be a boot-time only problem. Perhaps there is a race condition. I have tried several things to isolate the cause but have been unsuccessful as of yet.

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

Re: How to set up a static IP using Raspbian Buster

Mon Oct 07, 2019 7:32 pm

Have you tried a fresh install of raspbian on another SD card ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

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

Re: How to set up a static IP using Raspbian Buster

Mon Oct 07, 2019 7:38 pm

Reboot your router between SD swaps.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

CTGreybeard
Posts: 7
Joined: Fri Nov 27, 2015 2:35 pm
Location: Western Connecticut, USA

Re: How to set up a static IP using Raspbian Buster

Mon Oct 07, 2019 7:44 pm

pcmanbob wrote:
Mon Oct 07, 2019 7:32 pm
Have you tried a fresh install of raspbian on another SD card ?
That is my next debugging try. My thought was that because this is a Stretch upgrade, done on a Pi 3, perhaps there is a config that didn't get set quite right. I have a new SD building now and will try that later when I get a chance.

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

Re: How to set up a static IP using Raspbian Buster

Mon Oct 07, 2019 7:54 pm

It is not recommended to upgrade from stretch to buster because it often does not work successfully or suffers strange software behaviour, as you have found,

especially as there have been many changes from stretch to buster and in the pi4 hardware compared to the pi3.
We do not recommend upgrading an existing Stretch (or earlier) system to Buster – we can’t know what changes everyone has made to their system, and so have no idea what may break when you move to Buster.
https://www.raspberrypi.org/blog/buster ... -raspbian/
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

pilot222
Posts: 1
Joined: Tue Nov 19, 2019 4:10 am

Re: How to set up a static IP using Raspbian Buster

Tue Nov 19, 2019 4:38 am

I have installed the RasPBX (FreePBX version) image based on Raspbian 10 Buster on a Pi4 and had the same problem of not being able to setup a static IP. Very frustrating. With all my many years of Linux experience that's the first time an Ethernet interface does not accept a static IP configuration!

I finally found a solution using the default /etc/dhcpcd.conf file with a few modifications (I only use IPV4):
- un-commented line: controlgroup wheel
- commented line persistent
- modified the bottom section # Example static IP configuration
Change according to your needs (your own network settings)
Do not ask me what did the trick but after several re-boots the right configuration stays on!

Code: Select all

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
# persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# Most distributions have NTP support.
#option ntp_servers

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
#slaac private

# Example static IP configuration:
interface eth0
static ip_address=172.16.10.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=172.16.10.1
static domain_name_servers=172.16.10.1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

fern-jim
Posts: 1
Joined: Fri Dec 06, 2019 11:15 pm

Re: How to set up a static IP using Raspbian Buster

Fri Dec 06, 2019 11:41 pm

ok, no one wants to hear yet more about buster and static addresses, but I haven't seen a clear, universal explanation and procedure. I have a bit of information to add that may indicate a hardware dependent bug....
I have been installing buster on 2 new pi4's and also on an older pi3b, all running raspbian. The installs of the pi4s worked normally. I added a static address at the end of dhcpcd.conf and rebooted. got the new addresses for both pi4s. However, I had also edited resolv.conf to change nameservers, and this did not work. dig and nslookup reported incorrect dns; my resolv.conf changes had been overwritten by the program resolvconf. I fixed this problem by adding a line "static domain_name_servers= 1.0.0.1 8.8.8.8" to dhcpcd.conf and after a reboot both the static addresses and my selected nameservers were working properly.
HOWEVER, the pi3b is a different story. I used the identical NOOBs install software (a fresh download of 3.2.1) that I used with the pi4s. Now many of the problems being discussed in this thread appear. I cannot set a static IP on the pi3 by editing dhcpcd.conf identically to what I did with the pi4s, and the problem with resolvconf overwriting my resolv.conf configuration cannot be fixed by editing dhcpcd.conf to add static nameservers, which worked fine with both pi4s.
Its as though dhcpcd is not initializing properly, is not using dhcpcd.conf, or is unable to write the changes if finds from dhcpcd.conf. This only happens on pi3, not on either pi4. I suspect one reason some things work for some users and not others may be due to a **hw dependent bug** that is messing up static networking and DNS, due to incorrect dhcpcd initialization.

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

Re: How to set up a static IP using Raspbian Buster

Sun Dec 08, 2019 10:30 am

Hi fern-jim.

You should not have any problem setting a static IP on any pi from the original pi1 B right up to the pi4B using buster , I often use the same SD card in different pi's with a static IP set on it , ( I have several SD cards I use fort testing when helping people here ) it just works , which ever pi has the SD card has that static IP.

The same process using dhcpdc.conf has been used from the late jessie versions right through stretch and now on to buster.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

blahhh
Posts: 1
Joined: Wed Jan 15, 2020 1:26 am

Re: How to set up a static IP using Raspbian Buster

Wed Jan 15, 2020 7:02 am

Hi,

maybe check & possibly upgrade your version of dhcpcd5 ? (apt-get upgrade dhcpcd5)
or maybe "apt-get update" and "apt-get upgrade"?

what version of dhcpcd in buster lite sept 2019?
try this:
systemctl status dhcpcd ### => shows "active", and "ExecStart=/usr/lib/dhcpcd5/dhcpcd"
dpkg -S /usr/lib/dhcpcd5/dhcpcd ### => shows package is called "dhcpcd5"
dpkg -s dhcpcd5 ### => shows "Version: 1: 7.0.8-01 " => which looks like 7.0.8

google dhcpcd => https://roy.marples.name/projects/dhcpcd
looks like 7.2.5 is downloadable (jan 2020) and also a 8.x version
looks like maybe 7.0.8 is from 2018?

also interesting => there's mailing list with searchable archives - to help troubleshoot
https://roy.marples.name/archives/dhcpc ... search.php

guessing about resolv.conf stuff:
man dhcpcd.conf also lists dhcpcd-run-hooks (at the bottom)
man dhcpcd-run-hooks mentions /etc/resolv.conf and the "hook" scripts in /lib/dhcpcd/dhcpcd-hooks/
ls -l /lib/dhcpcd/dhcpcd-hooks/ => some scripts about resolv.conf, ntp, etc...
view 20-resolv.conf => comments at top mention trying to support "resolvconf", looks like the script (re)builds resolv.conf?
man resolvconf => part of systemd stuff...it's all intertwined/complicated...?!

looking at the mailing list search page - there's stuff about resolv.conf and scripts that were patched/fixed in different versions of dhcpcd and thus the light bulb about upgrading dhcpcd5 versions ;)

in my own case of dhcpcd and setting static IP address not working which led to this thread

following doc at https://www.raspberrypi.org/documentati ... /README.md
had similar problem with rpi4 2gb raspbian buster lite sept 2019
static ip settings for dhcpcd.conf not working for wired connection eth0

but, in my situation, i had the rpi ethernet cable unplugged from the network (a security precaution for initial install... ;))

found a possible work around if wanting static ip address for wired but temporarily unplugged eth0 for dhcpcd v7.0.8:
1) add "nolink" to /etc/dhcpcd.conf (in addition to 4 lines of static ip config) - man dhcpcd.conf suggests it's for buggy drivers fix - and restart dhcpcd (systemctl restart dhcpcd) and seems to work fine

or

2) disable dhcpcd (systemctl disable dhcpcd) and instead create a config file /etc/network/interfaces.d/eth0 to contain 6 config lines for static ip, and then restart the "networking.service" (systemctl restart networking)


for adding "nolink" (along with the suggested other lines for static ip address) in case of temporary unplugged eth0

* /etc/dhcpcd.conf has default lines:
hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option interface_mtu
require dhcp_server_identifier
slaac private
* static ip config lines put at bottom of /etc/dhcpcd.conf
added these 5 lines at bottom:
interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_server=192.168.1.1
nolink

the suggested 4 lines for static eth0 ip address wasn't working if the eth0 cable was unplugged from the network
systemctl status dhcpcd => mentioned "no carrier" and "timed out"
journalctl -u dhcp* => shows a little more info
trying the "fallback static_eth0" profile thing & few other lines, didn't appear to work either - and when plugged in got 2 ips (1 static, 1 dhcp) instead of 1 static (0 dhcp)
but adding "nolink" seems to work fine - if cable is unplugged, the static ip is still assigned
and after plugging in eth0, static ip seems to keep working

maybe if i plugged in the cable to begin with, it would work fine without the "nolink" and just the 4 lines of static - but originally wanted unplugged pi to get static ip on boot...later would plug in

also - disabling dhcpcd and using /etc/network/interfaces.d/eth0 also seems to work - but maybe there's warnings in various docs/internet posts about doing this? if u don't disable dhcpd, then it looks like u get 2 ip addresses? 1 static from networking.service, and 1 dynamic from dhcpcd5.service (if you have dhcp server listening & handing out ips, etc...)

/etc/network/interfaces.d/eth0 contained:

auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameserver 192.168.1.1

castletonroad
Posts: 135
Joined: Sat Jul 25, 2015 11:23 pm

Re: How to set up a static IP using Raspbian Buster

Sat Jan 18, 2020 7:33 pm

I configure the relevant section of /etc/dhcpcd.conf for my raspberrypi running pihole (DNS blocker) as:

Code: Select all

interface wlan0
    static ip_address=192.168.0.25/24
    static routers=192.168.0.1
    static domain_name_servers=127.0.0.1  # other raspberry pis on my network use 192.168.0.24

interface eth0
    static ip_address=192.168.0.24/24
    static routers=192.168.0.1
    static domain_name_servers=127.0.0.1  # other raspberry pis on my network use 192.168.0.24
I *also* reserve the static IP addresses for all my raspberrypis in my router.
Raspberry Pi 4 Model B | Raspberry Pi 3 Model B | Raspberry Pi 2 Model B

Return to “Networking and servers”