Ubuntu – Ubuntu 14.04: How to add an Ethernet connection from command line that’s editable in Network Manager GUI

14.04command lineethernetnetwork-manager

On Ubuntu 14.04, how can I add an Ethernet connection from the command line that's editable in the Network Manager GUI?

I have studied nmcli which is the command line tool for the Network Manager. Unfortunately:

  • If you compare the nmcli tool on Ubuntu 14.04 LTS and that on Ubuntu 15.10 documentation, you'll notice that 14.04 LTS doesn't support adding an Ethernet connection via the nmcli tool. The add command is added to nmcli's connection object since 15.10. It's not available on 14.04.

  • The nmcli on Ubuntu 14.04 LTS can connect to a wireless network (see the last example in its document), but I want to create an Ethernet connection.

  • Although I can edit the file /etc/network/interfaces to add the Ehternet interfaces, they are not visible in the Network Manager, and this is not what I prefer.

I'm doing this because I'm writing a shell script to configure the network, and I also want to allow the users to edit the configuration from the GUI when necessary.

Thanks in advance!

==========

UPDATE #1:

I forgot to mention nm-connection-editor: As far as I can see, it is still a GUI tool and requires the user interaction to create/edit a connection. Because I'm trying to automate the process in a script, I don't want to use any GUI stuff here.

Best Answer

You can edit/create a connection file in /etc/NetworkManager/system-connections. For instance I just created ethfix192

[802-3-ethernet]
duplex=full

[connection]
id=ethfix192
type=802-3-ethernet
autoconnect=false

[ipv6]
method=auto

[ipv4]
method=manual
address1=192.168.2.22/24,0.0.0.0

You will see how the lines in this file correspond to the settings in the GUI.

Note: Ensure that the file has permission '600', otherwise NetworkManager will ignore the file.

Afterwards you need to restart NetworkManager (IIRC on 14.04 it was with sudo service NetworkManager restart, or sudo service network-manager restart) and NetworkManager will recognize the connection.

Related Question