Page 1 of 1

Static fallback when no DHCP server

Posted: Tue Jan 26, 2016 8:56 pm
by mattmiller
It would be very useful to have the eth0 interface fallback to a static fixed 169.254/16 address when it fails to get an address from a DHCP server.
This would help a lot when plugging a Pi directly into a laptop when away from home and ssh or VNC into it from the laptop

But I am unable to work out/google how to do this with the new Jessie /etc/dhcpcd.conf file

Lots of clutter on the interwebs - no "solutions" seem to work

Has anyone actually managed to do this?

Matthew

Re: Static fallback when no DHCP server

Posted: Tue Jan 26, 2016 9:37 pm
by stderr
mattmiller wrote:It would be very useful to have the eth0 interface fallback to a static fixed 169.254/16 address when it fails to get an address from a DHCP server.
If you can't get the new way of getting the static addresses to work, you should be able to add one later with:

ifconfig eth0:staticTest 192.168.1.100 up

I recall that under earlier versions, trying to use /etc/network/interfaces with both a static and dhcp setting seemed to work and then not work in various Debian derived releases with no sense I could figure out. DHCP alone would work and I suspect will work in Jessie since people seem to be using it. But both at once, I don't know other than the above kludge.

Re: Static fallback when no DHCP server

Posted: Wed Jan 27, 2016 12:45 pm
by DirkS

Re: Static fallback when no DHCP server

Posted: Wed Jan 27, 2016 4:00 pm
by mattmiller
i've google everywhere and tried everything
to be fair this is the code I tried

Code: Select all

# define static profile
profile static_eth0
static ip_address=169.254.64.64/16

# fallback to static profile on eth0
interface eth0
fallback static_eth0
as don#t know what (if any values to put in the domain name and gateway addresses

Re: Static fallback when no DHCP server

Posted: Wed Jan 27, 2016 5:39 pm
by ripat
What's the IP address of your laptop when you try to connect the pi to it? Same subnet 169.154.0.0/16? (which, by the way, does not belong to the private address space)

Re: Static fallback when no DHCP server

Posted: Wed Jan 27, 2016 6:23 pm
by DougieLawson
ripat wrote: (which, by the way, does not belong to the private address space)
Eh? It's the link-local address block.
https://tools.ietf.org/html/rfc3927

Re: Static fallback when no DHCP server

Posted: Wed Jan 27, 2016 8:49 pm
by mattmiller
What's the IP address of your laptop when you try to connect the pi to it?
Its windows and it picks a random number in the 169.254.0.0/16 address space
It all works nicely under Wheezy but the new fangled use of /etc/dhcpcd.conf is seemingly not as flexible as the old /etc/network/interfaces file :(
Matthew

Re: Static fallback when no DHCP server

Posted: Thu Jan 28, 2016 7:27 am
by ripat
I have just tested the fallback option of dhcpcd following the link posted by DirkS above and it works flawlessly. What is that doesn't work? Wrong ip? Is the main dhcp server disabled when you test the the fall back. How do you resend a request for ip? For that last part, as root (or sudo) use # systemctl restart dhcpcd && systemctl status dhcpcd or # dhcpcd -n eth0

Re: Static fallback when no DHCP server

Posted: Thu Jan 28, 2016 11:48 am
by Milliways
mattmiller wrote:It would be very useful to have the eth0 interface fallback to a static fixed 169.254/16 address when it fails to get an address from a DHCP server.
This would help a lot when plugging a Pi directly into a laptop when away from home and ssh or VNC into it from the laptop

But I am unable to work out/google how to do this with the new Jessie /etc/dhcpcd.conf file

Lots of clutter on the interwebs - no "solutions" seem to work

Has anyone actually managed to do this?

Matthew
By default any network interface will have a link-local address, which will be replaced by a inet address if resolved by DHCP (or otherwise). link-local addresses are limited - by definition they only work on a link and are not routeable. If you are using a recent Raspbian (and haven't fiddled with the network settings) you should be able to connect using a zero-conf client over a link-local address e.g. by ssh pi@hostname.local (default hostname raspberrypi).
NOTE this works whether you have an IP address or not. I don't know (or care) what the actual inet address of my Pis actually are.

Re: Static fallback when no DHCP server

Posted: Thu Jan 28, 2016 12:28 pm
by mattmiller
I have just tested the fallback option of dhcpcd following the link posted by DirkS above and it works flawlessly
Does changing it to 169.254.64.64/16 work for you?

If it does - could you paste your text it here to make sure I'm not just incapable of typing without errors!

Matthew

Re: Static fallback when no DHCP server

Posted: Thu Jan 28, 2016 5:02 pm
by ripat
Here you go:

Code: Select all

## define static profile
profile static_eth0
static ip_address=192.168.0.6/24
static routers=192.168.0.201
static domain_name_servers=192.168.0.201

## fallback to static profile on eth0
interface eth0
fallback static_eth0
Other default options from dhcpcd.conf:

Code: Select all

hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option ntp_servers
require dhcp_server_identifier
slaac private
nohook lookup-hostname
But all this might be unnecessary as dhcpcd should automatically switch to IPv4LL (local-link as mentioned by Milliways) if it doesn't receive an answer from a dhcp server within the default timeout (30 seconds I believe). To simulate that while connected to your lan served by a dhcp server, just blacklist that dhcp server (router?) and shorten the timeout with:

Code: Select all

# blacklist dhcp router address
blacklist 192.168.0.201/24
# shorten timeout
timeout 3
After any change in the dhcpcd.conf file, don't forget to rebind your interface with systemctl or dhcpcd -n as in my post above.

Re: Static fallback when no DHCP server

Posted: Thu Jan 28, 2016 5:22 pm
by mattmiller
I think one or both of us isn't reading the others posts properly :)

I'm trying to get 169.254.64.64/16 working - you seem to be taking about addresses in 192.168.0.0/24 range

Re: Static fallback when no DHCP server

Posted: Thu Jan 28, 2016 6:18 pm
by ripat
It was just an example ip for testing. Works also with 169.254.64.64/24. Just tried.

Re: Static fallback when no DHCP server

Posted: Thu Jan 28, 2016 9:14 pm
by mattmiller
Works also with 169.254.64.64/24. Just tried.
Could you post the code that works please :)

Re: Static fallback when no DHCP server

Posted: Fri Jan 29, 2016 12:34 pm
by ripat

Code: Select all

## define static profile
profile static_eth0
static ip_address=169.254.64.64/24

## fallback to static profile on eth0
interface eth0
fallback static_eth0
Same default option as above.

Re: Static fallback when no DHCP server

Posted: Fri Jan 29, 2016 10:51 pm
by mattmiller
It works :)

Thanks :)

I did alter it to this just to make it match up to the proper 255.255.0.0 subnet

Code: Select all

## define static profile
profile static_eth0
static ip_address=169.254.64.64/16

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

Re: Static fallback when no DHCP server

Posted: Tue Jun 11, 2019 4:28 pm
by thomasj
I'm sorry for posting this but I think that I'm going blind.
Did mattmiller just post the same code block for his solution as his original posted code block that he claimed didn't work? :? (not a dig but just confused)

Re: Static fallback when no DHCP server

Posted: Tue Jun 11, 2019 4:35 pm
by epoch1970
Pointless thread anyway. The ipv4ll block is not designed for static ip assignment.
When DHCP fails, by default on Raspbian an ipv4ll address is given to the host. Properly validated via ARP, this one, so the address is unique.

Re: Static fallback when no DHCP server

Posted: Tue Jun 18, 2019 3:10 pm
by mattmiller
Did mattmiller just post the same code block for his solution as his original posted code block that he claimed didn't work?
I think I did :)

Sometimes the gremlins do get you!