Ubuntu – How to update a Network Manager connection from the command line

command linenetwork-managernetworking

I have a bunch of Ubuntu machines on my work ethernet LAN and I need to modify the default gateway.

I'd rather not traipse round, interrupt people's work, to right click an applet, preferring instead to ssh in, which can be automated 🙂

I know I can change the default live gateway with ip route replace default via 1.2.3.4 but this does not update NM's stored connection.

In my case each machine will only have one stored wired connection.

How can I update the stored gateway IP from the command line?

Best Answer

  • All configuration from Network Manager are in /etc/NetworkManager/system-connections/

    On this please you will find Wired connection 1 witch is probably configuration file of you lan connection. You can edit it

    sudo nano /etc/NetworkManager/system-connections/Wired connection 1

    [802-3-ethernet]
    duplex=full
    mac-address=00:22:64:4E:6F:70
    
    [connection]
    id=Wired connection 1
    uuid=57a2a340-c113-406f-9abc-eb816e58b3db
    type=802-3-ethernet
    timestamp=1430138708
    
    [ipv6]
    method=auto
    
    [ipv4]
    method=manual
    dns=xxx.xxx.xxx.243;8.8.8.8;
    dns-search=eunet.rs;
    address1=xxx.xxx.47.5/24,xxx.xxx.47.254
    

    You can change ip, network mask or gateway. After change you made, save and restart NM with command

    sudo service network-manager restart