I'm using Raspbian Jessie.
I would like to have 2 ip addresses on my raspberry eth0 interface.
- One dynamic, dhcp assigned,
- One static, configured either in /etc/network/interfaces, either in /etc/dhcpcd.conf
I tried changing the file /etc/network/interfaces like this:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto eth0:0
iface eth0:0 inet static
address 10.166.247.2
netmask 255.255.255.0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
It works fine, but after a while, the dynamic ip address disappears. It seems the lease isn't renewed.
I've read a lot of advises to leave /etc/network/interfaces untouched and rather use /etc/dhcpcd.conf to setup a static ip address, but is it possible to ask dhcpcd to setup both a static and a dynamic ip address at the same time?
Other solutions (systemd-networkd) are welcome too! (as long as I don't need a gui)
Thanks!
edit: Since a lot of people is interested in this question, I'm sharing my workaround. Maybe it will help you too. I tried a few possible solutions but none was stable enough. The reason why I would have wanted this was that I wanted 2 raspberry pi based devices to be able to talk together in a network that I was not controlling, but these would also need to have internet access, so one dhcp ip for the default routing, and one fix ip in a different range for the internal connection. That was working but eventually the dhcp was not renewing the lease. I finally managed to solve my problem using the mdns "hostname.local" address to communicate without having to know the ip of the machines. It's also a cleaner solution in my opinion.
ip addr
when eth0 has two ip addresses? – Ingo Mar 15 '18 at 14:16hostname
.local" address to communicate without having to know the ip of the machines. – Olivier Apr 03 '20 at 22:52