6

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?

1
  • There's no easy way to do it using tools that Network Manager provides (at least, not in 14.04). You'll have to edit the appropriate file in /etc/NetworkManager/system-connections. Changes should be automatically detected and loaded.
    – muru
    Apr 28, 2015 at 9:27

2 Answers 2

4

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
1

I accepted 2707974's answer (great name) but here for anyone wanting to automate this stuff with a one-liner to change from 1.2.3.4 to 5.6.7.8

sudo find /etc/NetworkManager/system-connections/ -type f -name "Wired*" \
 | while read c ; do sudo sed -i 's/1\.2\.3\.4/5.6.7.8/g' "$c" ; done ;  \
 sudo service network-manager restart

Of course this assumes that 1.2.3.4 is only found in the files in relation to the appropriate thing - so for me it was the default gateway and so the IP address only occurred once.

1
  • 1
    Better use -exec/-execdir: sudo find /etc/NetworkManager/system-connections/ -type f -name "Wired*" -execdir sed -i 's/1\.2\.3\.4/5.6.7.8/g' {} + ;
    – muru
    Apr 28, 2015 at 9:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .