You are not logged in.
Hi!
I want to add an IP alias to a computer with a single network interface (wired LAN).
I'm using systemd-networkd, with a basic DHCP setup. My Router has static IP leases reserved for this interface (MAC address). Let's say that for an example, I want addresses .114 and .115 in my subnet for this host.
With DHCP the DHCP server will give only one IP address:
$ dog 20-wired.network
[Match]
Name=eno1
[Network]
DHCP=yes
And, AFAIK, the DHCP protocol does not allow more IP addresses to the same MAC address (if it did, I could configure everything on the router, which would simplify things).
Now I can add a secondary IP address by running:
ip addr add 192.168.66.114/24 dev eno1
However, this will not be persistent. I could put it into root crontab but I find it a bit hacky and dirty.
What would be the "right way" to make this persistent?
I managed to do this by adding to the .network file:
[Address]
Address=192.168.66.114/24
I can imagine this could randomly cause problems, in case my DHCP server on the router decides to serve the .114 address first (as it can not serve both .114 and .115). I should probably ditch using DHCP altogether?
Possibly, the implementation on the router will server the addresses "in order" on every boot - which will mean this setup will work, albeit a bit hacky.
I suppose having manually set multiple [Address] section and DHCP will not hurt - just in case I change my router configuration.I just always need to remember the static configuration on the router include the static ones on the client! If I add an IP on the router, it will just be an extra one.
Cheers!
p.s. in case the use case matters: the computer will run several game servers, and having multiple IPv4 addresses will simplify configuration (I will less likely run into port clashes, I don't need to invent 5 new port numbers for each server process instance etc...) - I just need to "copy" instances of port forwards on the router. I'm mentioning this just in case I'm trying a wrong approach, and hence finding the solution to the wrong problem.
Last edited by Wild Penguin (2023-06-14 10:04:51)
Offline
Ok,
I was making things a bit too complicated. This is (probably) a correct way to do it (there are probably others):
1. Set a DHCP address on the router, if you wish. A single rule will do (actually, don't make more - dhcp servers I've found can not give more than one address/MAC address).
2. Set static addresses on the device, which do not conflict with the dhcp range configured on the server (with anything - systemd.networkd in my example).
In point 2 make sure the router does not serve dhcp addresses on these addresses. Typically, dhcp servers only serve .100+ addresses (this is configurable but a common default configuration). I just somehow forgot the dhcp range is configurable, hence felt the need to add rules in the dhcp range for the static addresses. There is no need to make separate rules on the router for the static addresses, and a dhcp given IP address will work happily with the static ones.
Marking as [closed].
Last edited by Wild Penguin (2023-06-14 10:06:49)
Offline