mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Static fallback when no DHCP server

Tue Jan 26, 2016 8:56 pm

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

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Static fallback when no DHCP server

Tue Jan 26, 2016 9:37 pm

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.


mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: Static fallback when no DHCP server

Wed Jan 27, 2016 4:00 pm

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

ripat
Posts: 191
Joined: Tue Jul 31, 2012 11:51 am
Location: Belgium

Re: Static fallback when no DHCP server

Wed Jan 27, 2016 5:39 pm

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)
Using Linux command line usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

User avatar
DougieLawson
Posts: 36105
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Static fallback when no DHCP server

Wed Jan 27, 2016 6:23 pm

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
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: Static fallback when no DHCP server

Wed Jan 27, 2016 8:49 pm

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

ripat
Posts: 191
Joined: Tue Jul 31, 2012 11:51 am
Location: Belgium

Re: Static fallback when no DHCP server

Thu Jan 28, 2016 7:27 am

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
Using Linux command line usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

Milliways
Posts: 454
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: Static fallback when no DHCP server

Thu Jan 28, 2016 11:48 am

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.

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: Static fallback when no DHCP server

Thu Jan 28, 2016 12:28 pm

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

ripat
Posts: 191
Joined: Tue Jul 31, 2012 11:51 am
Location: Belgium

Re: Static fallback when no DHCP server

Thu Jan 28, 2016 5:02 pm

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.
Using Linux command line usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: Static fallback when no DHCP server

Thu Jan 28, 2016 5:22 pm

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

ripat
Posts: 191
Joined: Tue Jul 31, 2012 11:51 am
Location: Belgium

Re: Static fallback when no DHCP server

Thu Jan 28, 2016 6:18 pm

It was just an example ip for testing. Works also with 169.254.64.64/24. Just tried.
Using Linux command line usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: Static fallback when no DHCP server

Thu Jan 28, 2016 9:14 pm

Works also with 169.254.64.64/24. Just tried.
Could you post the code that works please :)

ripat
Posts: 191
Joined: Tue Jul 31, 2012 11:51 am
Location: Belgium

Re: Static fallback when no DHCP server

Fri Jan 29, 2016 12:34 pm

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.
Using Linux command line usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: Static fallback when no DHCP server

Fri Jan 29, 2016 10:51 pm

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

thomasj
Posts: 10
Joined: Fri Dec 14, 2018 5:10 pm

Re: Static fallback when no DHCP server

Tue Jun 11, 2019 4:28 pm

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)

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

Re: Static fallback when no DHCP server

Tue Jun 11, 2019 4:35 pm

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.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: Static fallback when no DHCP server

Tue Jun 18, 2019 3:10 pm

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!

Return to “Raspbian”