6

I need to change my connection, from staic assigned to DHCP using nmcli (invoked from a Python script) I've tried like this:

nmcli con mod "CONNECTION NAME" ipv4.method auto
nmcli con down "CONNECTION NAME"
nmcli con up "CONNECTION NAME"

But after the connection has gone up again, my old Ip is still there, if i show info for the conenction i see someting like that

....
ipv4.addresses:                         192.168.1.10/24  <-THIS IS THE BAD ONE 
....
IP4.ADDRESS[1]:                         192.168.1.10/24  <-THIS IS THE BAD ONE
IP4.ADDRESS[2]:                         10.0.2.15/24
....

How can i solve this?

Ubuntu version 16.04

Python version 3.5.2

3 Answers3

4

Not having a linux system in front of me, but if I remeber correctly, you can try to reset the IP addresses before the down/up:

nmcli con mod "CONNECTION NAME" ipv4.address ""
nmcli con mod "CONNECTION NAME" ipv4.method auto
nmcli con down "CONNECTION NAME"
nmcli con up "CONNECTION NAME"
nirebu
  • 56
  • 3
3

After updating method (from manual to auto) i need to set gateway and ipaddrerr to "", like that

nmcli con mod "CONNECTION NAME" ipv4.method auto
nmcli con mod "CONNECTION NAME" ipv4.gateway ""
nmcli con mod "CONNECTION NAME" ipv4.address ""
nmcli con down "CONNECTION NAME"
nmcli con up "CONNECTION NAME"

Thanks to Nicolò Rebughini for the solution

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • Don't write SOLVED, mark the answer as accepted by clicking on the checkmark in its top-left corner, once it'll be enabled – Andrea Ligios Mar 13 '20 at 10:12
0

Sorry i have no Linux macchine right here but if i'm not wrong remebering, you have to create a profile before you edit connection

nmcli connection add type ethernet con-name "connection-name" ifname interface-name <-- this Is the interface name

After that you can edit profile configuration, so ADD a profile with whatever name bound to interface name.

Dichado
  • 37
  • 10