1

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!

  • Please can you edit your question and add the output from ip addr when eth0 has two ip addresses? – Ingo Mar 15 '18 at 14:16
  • You are using jessie which is oldstable and you want to use deprecated debian networking mixed up with dhcpcd. As you was already told this is very sophisticated. I never understand it. If you are willing to migrate do modern systemd-networkd I could present you a very simple solution. But that would'nt be an answer to your question. You are asking for dhcpcd. – Ingo Mar 15 '18 at 19:20
  • @Ingo, I edited my question: other solutions (systemd-networkd) are welcome too! – Olivier Mar 26 '18 at 8:47
0

There are two uncertainty factors for this answer.

  1. The question is for Raspbian Jessie but I've tested it with Raspbian Stretch. But Raspbian Jessie started with systemd-networkd so it should work.

  2. There are two wifi connections at the same time. I can't test it because I have only one wifi. The configuration suggestion for this here is theoretical.

With systemd-networkd the default configuration file for eth0 looks like this:

rpi3 ~$ cat /etc/systemd/network/04-eth0.network
[Match]
Name=eth0
[Network]
DHCP=yes

For additional ip addresses you only add additional lines:

[Match]
Name=eth0
[Network]
DHCP=yes
Address=10.166.247.2/24

How it works? Follow these instructions to migrate your networking to systemd-networkd. It's a little effort. You only need
Step 1: Preparation
Step 2: Setup ethernet interface
Step 3: Setup wlan interface - two times. Second time replace wlan0 with wlan1
Step 5: Clean up
( Bonding is not needed here ).

At least your configuration files should look like this:

rpi3 ~$ cat >/etc/systemd/networkd/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
DHCP=yes
Address=10.166.247.2/24
EOF

rpi3 ~$ cat >/etc/systemd/networkd/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
DHCP=yes
EOF

rpi3 ~$ cat >/etc/systemd/networkd/12-wlan1.network <<EOF
[Match]
Name=wlan1
[Network]
DHCP=yes
EOF

Have in mind that you also have to setup
/etc/wpa_supplicant/wpa_supplicant-wlan0.conf and
/etc/wpa_supplicant/wpa_supplicant-wlan1.conf.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.