How to add an IP alias on an ethernet interface

I need to add a secondary IP address (static) on an ethernet interface where primary IP address is received from a DHCP server.

Hi, thanks for your message. Could you please extend a bit more on your use case? What do you mean by primary and secondary IP addresses? An ethernet interface can only have one IP addressed assigned, be it DHCP or statically assigned.

Thank you for your response. In general, actually it is possible to give an IP address to an interface and add IP alias on the same interface which makes it possible to access to different networks using the same network interface.

Hey there, have you tried creating an alias with the ipconfig command manually first? It will be lost on reboot but it might be a good way to verify you get the behaviour you are looking for before making the changes persist between boots.

Example: ifconfig eth0:0 192.168.5.12 netmask 255.255.255.0 up

If this works for you, then you could try to persist those changes with a new connection profile, or by running your container as privileged with network: host and create the alias on app startup.

Thank you for your response. I’m actually doing it this way for now but need to provide persistance. I can add static IP addresses with the below configuration but what I need is to set address1 as auto (from dhcp). Thanks for your time :

[connection]
id=test-ethernet
type=ethernet
interface-name=eth0
permissions=
secondaries=

[ethernet]
mac-address-blacklist=

[ipv4]
address1=192.168.1.15/24
address2=192.168.99.124/24
dns=8.8.8.8;8.8.4.4;
dns-search=
method=manual

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto

Hi there, have you tried creating a new connection (e.g. my-ethernet) as per this doc and placing it into the resin-boot/system-conections folder in the balenaOS .img file? This is a FAT partition and can be mounted on most desktop operating systems. If you then flash that image to the device, your custom ethernet profile should become the default.

Actually you can setup your connection to support DHCP and static IPs. It’s a bit non-obvious, but here is an example:

[connection]
id=static-ethernet
type=ethernet
interface-name=enp88s0
permissions=
secondaries=

[ethernet]
mac-address-blacklist=

[ipv4]
address1=auto
address2=10.5.36.162/24,10.5.36.1
dns=10.2.24.21;10.5.132.10;8.8.8.8;8.8.4.4;
dns-search=
method=auto

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto

There is a caveats that I’ve noticed.

Balena VPN will use the first connection established (This WILL be a static assignment)

Other than that, the device is reachable via SSH on any connection and services will use either connection.

In my case nmcli reports:

enp88s0: connected to static-ethernet
        "enp88s0"
        ethernet (igc), XX:XX:XX:F0:94:91, hw, mtu 1500
        ip4 default
        inet4 10.5.36.162/24
        inet4 192.168.98.127/24
        route4 10.5.36.0/24
        route4 192.168.98.0/24
        route4 0.0.0.0/0
        inet6 fe80::58cd:20c8:ee13:ac6f/64
        route6 fe80::/64
        route6 ff00::/8

Hope this helps.

Thank you clawcock. It works.
I’ve created the file: /mnt/boot/system-connections/static-ip

[connection]
id=static-ethernet
type=ethernet
interface-name=eth0
permissions=
secondaries=

[ethernet]
mac-address-blacklist=


[ipv4]
address1=auto
address2=10.0.0.153/24
dns-search=
method=auto


[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto

It behaves as expected.
But I’ve encountered the question:

How can I turn the settings back?
I’ve tried to remove the file and reboot the device, but still have it available on both IP addresses: DHCP and static.
img-1

Hi,

I assume you removed the file in /mnt/boot/system-connections/.
There’s probably another one in /mnt/state/root-overlay/etc/NetworkManager/system-connections, which is being used.
On boot, the files are copied from the /mnt/boot to the /mnt/state directory.

1 Like

Thank you TJvV. It is working.