I am working with an embedded linux device, which we typically connect to by static IP address during development. However, on-site we have a requirement to connect using DHCP and so, I would like to setup a primary DHCP connection, with a fallback static IP address on a different network. Is this possible?
I can use nmcli to configure a DHCP connection (IPV4.method=manual) and can successfully add an additional static IP address. Both will exist when simultaneously when the DHCP server is present, however when there is no DHCP server, the connection is disabled including the static IP address.
I have also tried setting up multiple connections, assigned to eth0, i.e. one static and one DHCP, and can manually enable them using
nmcli con up ConnectionName
but this does not meet the requirement because of the need to manually enable them in the event of the other failing. I can, of course run a script to check the connection status and enable the other if required but thought this would be a realistic expectation of a network manager.
Is there a way to tell network manager to attempt one connection and if this fails try another?
I am using Ubuntu 18.04.
Thanks.
Use nmcli command line to create connection profile and linked to the interface.
create another connection profile and linked to the same interface but with higher priority.
Then check the connection created.
Use other commands such as below to troubleshoot, up/down connection, remove connection.
Always remember to remove the default connection, for my case is
or in the /etc/NetworkManager/system-connections it will be
You can solve this by creating two profiles (aka. connection).
In config files (e.g. /etc/NetworkManager/system-connections/*.nmconnection) :
The DHCP profile
The static profile
Note : by default, autoconnect=true when not specified, otherwise it wouldn't work.
I've also tried the same configuration on Ubuntu 18.04 - it just doesn't work (played with ipv4.addresses, connection.autoconnect, connection.autoconnect-retries, ipv4.dhcp-timeout, ipv4.method, ipv4.may-fail, etc.)
The only workable option was:
1) disable NetworkManager
2) /etc/network/interfaces.d/some_name
3) /etc/dhcp/dhclient.conf