How to temporarly switch network to dhcp using nmcli?

I have a Fedora 34 server which recently got dns issues (cannot resolve anything anymore).
I try to debug by temporarily switching the server from a static ipv4 address to using dhcp.
Everything needs to be done headless, because the server does not have any graphical user interface.
So far I tried

nmcli connection edit enp3s0
   remove ipv4.method
   remove ipv4.dns
   remove ipv4.gateway
   remove ipv4.address
   set ipv4.method auto
   save temporary
   quit
nmcli device disconnect enp3s0; wait; nmcli device connect enp3s0

But nothing changed. The ip address stays the same. What I expect is that my connection drops (not a problem, inside a screen session, so all commands are executed nonetheless) and a new ip address is acquired which needs to be different from my static one, because that one is outside of the range of the dhcp server.

I already checked that NetworkManager.service is running and systemd-networkd.service is not. Any suggestions?

2 Likes

You can simply create another connection, using DHCP by default and replacing the active one:

sudo nmcli connection add type ethernet connection.id ethernet; \
sudo nmcli connection down id enp3s0; \
sudo nmcli connection up id ethernet
4 Likes

Thanks a lot, it fixes my dns issues as well :slight_smile:

1 Like

you can also temporarily change the configuration (without modifying the connection profile) with

nmcli device modify "$DEVICE" ipv4.method auto

then your profile on disk does not change.

You can then get rid of that change with

   nmcli device reapply "$DEVICE"

or simply

   nmcli connection up "$PROFILE"
2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.