rdsk
Posts: 7
Joined: Thu Jan 28, 2016 8:34 pm

How to get Rpi router to issue static ip addresses?

Thu Dec 27, 2018 11:16 pm

Hi, I set up an Rpi as a router on standalone WIFI network to other Rpis using
https://www.raspberrypi.org/documentati ... s-point.md

I can add many Rpi to this network but each time I reboot them they get issued different IP addresses. Hence chaos!

I need to use these Rpi headless but dont know how to find each Rpi's new IP address and so cant use Termius or RealVND until I find a way to get the IP address. Ofc I can plug in a monitor but I need to do find new IP address headless. But I want no monitor at all on my little Rpi network for reasons of portability. The only way I can think of is to repeatedly try different possible Rpi addresses which would be very frustrating.

Does the router Rpi have way of distinguishing the other Rpi on network when they reboot?

If so could I issue them each with a fixed IP address?

PhatFil
Posts: 1034
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: How to get Rpi router to issue static ip addresses?

Fri Dec 28, 2018 12:35 am

a few ways,

edit the dhcpcd.conf file on all the clients to assign a static ip but that defeats the point of running a dhcp server..

Or set the lease time for each address issued to a LONG time, therfore the same addy should be issued to the same client for the lease duration

OR RTFM ;) https://blog.monotok.org/setup-raspberr ... cp-server/ * hint - look about 1/2 way down the page

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

Re: How to get Rpi router to issue static ip addresses?

Fri Dec 28, 2018 9:49 am

Strictly speaking a router (or any DHCP server) does not issue "static IP addresses". It might issue the same dynamic IP address each time a client requests one.

User avatar
thagrol
Posts: 1334
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: How to get Rpi router to issue static ip addresses?

Fri Dec 28, 2018 11:32 am

PhatFil wrote:
Fri Dec 28, 2018 12:35 am
a few ways,

edit the dhcpcd.conf file on all the clients to assign a static ip but that defeats the point of running a dhcp server..

Or set the lease time for each address issued to a LONG time, therfore the same addy should be issued to the same client for the lease duration

OR RTFM ;) https://blog.monotok.org/setup-raspberr ... cp-server/ * hint - look about 1/2 way down the page
Nope.

Editing dhcpcd.conf doesn't get the address from the dhcp server.
Long lease times don't guarantee a client gets the same address.
That tutorial is for the wrong dhcp server. And the correct "RTFM" would be

Code: Select all

man dnsmasq
in a terminal.

@rdsk
dnsmasq supports assigning client IP addresses by the client's MAC address.

One way to set this up is as follows:
  1. Edit /etc/dnsmasq.conf and add the following line

    Code: Select all

    read-ethers
  2. Create /etc/ethers
  3. Add a line in /etc/ethers for each client you want to have a "static" address of the form

    Code: Select all

    <MAC address> <IP address>
    e.g.

    Code: Select all

    11:22:33:44:55:66 192.168.0.2
    22:33:44:55:66:77 192.168.0.3
  4. Restart dnsmasq
Changes won't show up on the clients until you restart them and, possibly until any current dhcp lease has expired.

You can get MAC address of the client by logging in and running

Code: Select all

ifconfig
in a terminal. Look for "ether" in the output.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

User avatar
rpdom
Posts: 13748
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: How to get Rpi router to issue static ip addresses?

Fri Dec 28, 2018 5:11 pm

Interesting.

I've been using DNSMasq for many years and didn't know about the "read-ethers" option. Although the IPs on most of my systems are assigned by announced hostname in the dnsmasq conf file.

PhatFil
Posts: 1034
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: How to get Rpi router to issue static ip addresses?

Fri Dec 28, 2018 5:27 pm

thagrol wrote:
Fri Dec 28, 2018 11:32 am
PhatFil wrote:
Fri Dec 28, 2018 12:35 am
a few ways,

edit the dhcpcd.conf file on all the clients to assign a static ip but that defeats the point of running a dhcp server..

Or set the lease time for each address issued to a LONG time, therfore the same addy should be issued to the same client for the lease duration

OR RTFM ;) https://blog.monotok.org/setup-raspberr ... cp-server/ * hint - look about 1/2 way down the page
Nope.

Editing dhcpcd.conf doesn't get the address from the dhcp server.
Long lease times don't guarantee a client gets the same address.
That tutorial is for the wrong dhcp server. And the correct "RTFM" would be

Code: Select all

man dnsmasq
in a terminal.
Thanks for putting me straight, tho
#1 true but it creates the desired result,
#2 in my limited experience a long lease will result in the same addy being issued for the lease duration, though I am happy to stand corrected..
#3 Whoops wrong link.. i intended to post a pi specific WAP walkthrough..
- not intending to start a flame war, its a mia culpa coming from this end, no intention to mislead..

User avatar
thagrol
Posts: 1334
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: How to get Rpi router to issue static ip addresses?

Fri Dec 28, 2018 11:39 pm

PhatFil wrote:
Fri Dec 28, 2018 5:27 pm
- not intending to start a flame war, its a mia culpa coming from this end, no intention to mislead..
Sorry if I caused offence that wasn't my aim. Long leases will probably work OK most of the time but I can think of a few potential edge cases where they won't.

And yeah, setting a static IP on the client has mostly the same effect, again except for some less usual cases (static IPs and dhcp assigned IPs in both in the dhcp asigned range - bad idea I know). I've also seen dns lookup for local machines fail when ip addresses were statically assigned in the config on the machine rather than via the dhcp server. Might have been due to my setup though.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

User avatar
thagrol
Posts: 1334
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: How to get Rpi router to issue static ip addresses?

Fri Dec 28, 2018 11:43 pm

rpdom wrote:
Fri Dec 28, 2018 5:11 pm
Interesting.

I've been using DNSMasq for many years and didn't know about the "read-ethers" option. Although the IPs on most of my systems are assigned by announced hostname in the dnsmasq conf file.
Haven't tried doing things that way. Mainly because I have a couple of kludged together machines with dual NICs on the same subnet. Bad practice, I know and I really must sort out the routing issue that caused this and do it properly.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

rdsk
Posts: 7
Joined: Thu Jan 28, 2016 8:34 pm

Re: How to get Rpi router to issue static ip addresses?

Sat Dec 29, 2018 10:07 pm

Thanks all for your replies.

@thagrol's solution was exactly what I needed. Very grateful to you.

:D

Return to “Advanced users”