XJDHDR
Posts: 18
Joined: Fri Aug 03, 2012 9:21 pm
Location: Durban, South Africa

dhcpcd: Fallback to static IP configuration if DHCP fails

Sun Aug 17, 2014 8:14 pm

Greetings

I'm trying to configure my Rpi so that it first tries to get IP configuration data from a DHCP server and falls back to a static configuration if there is no server.

After searching the Arch Linux wiki, I figured that using dhcpcd would probably be the easiest way to accomplish this (though if anyone has any other method, I'm all ears). Following the instructions I found here: https://wiki.archlinux.org/index.php/Dh ... ic_profile
I added the following to /etc/dhcpcd.conf (which is otherwise the default/unmodified configuration file):

Code: Select all

# define static profile
profile static_eth0
static ip_address=10.43.86.250
static routers=10.43.86.50
static domain_name_servers=10.43.86.50

# fallback to static profile on eth0
interface eth0
fallback static_eth0
I then tried to test my configuration by running dhcpcd eth0. Unfortunately, I get the following output in the CLI: https://onedrive.live.com/redir?resid=E ... hoto%2cjpg
From what I can see, dhcpcd seems to be just looking for a DHCP server without falling back to the static configuration.

Can anyone tell me what I am doing wrong? I also notice that the wiki page doesn't specify a parameter for subnet masks (mine has to be 255.255.254.0). Do I just add a line saying static subnet_mask=255.255.254.0 to the profile? Help will be greatly appreciated.

sdjf
Posts: 1388
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: dhcpcd: Fallback to static IP configuration if DHCP fail

Mon Aug 18, 2014 4:06 am

Don't you need to be going through netctl for this? I am not able to read your output on that other website, but take a look at the default profile in /etc/netctl and see if it might be interfering with what you are trying to do.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || My 512MB Model B only runs Arch.

XJDHDR
Posts: 18
Joined: Fri Aug 03, 2012 9:21 pm
Location: Durban, South Africa

Re: dhcpcd: Fallback to static IP configuration if DHCP fail

Mon Aug 18, 2014 7:25 pm

Thank you for the reply. I'm not sure why you couldn't see the image I uploaded. I guess I'll try again:
Image
Don't you need to be going through netctl for this?
I don't mine using netctl if that is the correct way to do it but I have no idea how I can make netctl do what I want. dhcpcd is the only program I've seen so far that can do the static IP configuration fallback I want.
...take a look at the default profile in /etc/netctl and see if it might be interfering with what you are trying to do.
I did manage to spot a profile there with the name eth0 (same as the interface I'm using) and the command netctl list seems to indicate that this profile and another one called ethernet are running but I didn't manage to stop them.

sdjf
Posts: 1388
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: dhcpcd: Fallback to static IP configuration if DHCP fail

Tue Aug 19, 2014 3:41 pm

I am visiting the forum in a text browser, without access to images. Copying and pasting output is more accessible to people using text browsers and screen readers.

I do not know how to do what you want using netctl, but take a look at the profile in /etc/netctl and change the settings to match your requirements. If they are not the same as what you need at this point, that would explain things not working.

There is information in the arch wiki about netctl.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || My 512MB Model B only runs Arch.

XJDHDR
Posts: 18
Joined: Fri Aug 03, 2012 9:21 pm
Location: Durban, South Africa

Re: dhcpcd: Fallback to static IP configuration if DHCP fail

Sun Sep 21, 2014 6:23 pm

I eventually decided to cut my losses and just assign a static IP address to my Raspberry Pi. If I ever find a way of doing what I asked for, I might put the instructions in this thread.

DavidCary
Posts: 2
Joined: Fri Jan 16, 2015 7:51 pm

Re: dhcpcd: Fallback to static IP configuration if DHCP fail

Mon Jul 27, 2015 8:46 pm

I also am trying to get my Raspberry Pi to fallback to a static IP configuration if DHCP fails.

I added the following lines to the end of my "/etc/dhcpcd.conf" file (
as suggested on the page "Fallback static profile"
https://wiki.archlinux.org/index.php/Dh ... ic_profile
):

Code: Select all

# 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
and then rebooted.

After I log in (with a keyboard and screen plugged directly into the Pi, and the ethernet cable connected to a small isolated network without a DHCP server),
running "ifconfig" does not have a "inet addr:" line in the "eth0" section.

After running "ping google.com" (which obviously failed),
running "ifconfig" shows a "inet addr:" with an IP address the same as what I set in the "/etc/dhcpcd.conf" file.

When I plug it into a network that *does* have a DHCP server,
running "ifconfig" shows a "inet addr:" line in the "eth0" section with a different IP address (assigned by the DHCP server).

I haven't had the chance to do much testing yet, but it *seems* be working for me with Raspbian.

martijnschippe
Posts: 1
Joined: Wed Apr 25, 2018 7:12 am

Re: dhcpcd: Fallback to static IP configuration if DHCP fails

Wed Apr 25, 2018 7:17 am

The fallback works for me.
But does anybody knows if the RPI should get an IP address from the DHCP server when it comes back online? That part doesn't seem to work for me....

Return to “Arch”

Who is online

Users browsing this forum: No registered users and 1 guest