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.