11

Hi there is anyone familiar with the non-gui version of ubuntus network Manager?

I'd like to set up a static IP with it in virtualbox without touching the file /etc/network/interfaces.

  • IP: 192.168.56.101
  • Gateway: 102.168.1.1
  • Netmask: 255.255.255.0

Additionally I'd like to set up a second network interface with a dynamic IP to get connected to the internet with the Vbox.

5

You need to use Network Manger from the command line, this is nmcli.

First, you can list the available connections Network Manager knows about with the following, this is important to find the name, as the device id isn't used:

# nmcli con show

This will give you something like:

NAME                UUID                                  TYPE            DEVICE 
Wired connection 1  7a3b674a-f346-3cfb-8b30-ff70e6db1b60  802-3-ethernet  enp0s3

You can then modify the connection with the following:

nmcli con mod "Wired connection 1"
  ipv4.addresses "HOST_IP_ADDRESS/IP_NETMASK_BIT_COUNT"
  ipv4.gateway "IP_GATEWAY"
  ipv4.dns "PRIMARY_IP_DNS,SECONDARY_IP_DNS"
  ipv4.dns-search "DOMAIN_NAME"
  ipv4.method "manual"

When you enter the above use one line, I've just split it into separate lines to make it more clear.

If you want to set the connection to use DHCP, you can use the following:

nmcli con mod "Wired connection 1"
  ipv4.addresses ""
  ipv4.gateway ""
  ipv4.dns ""
  ipv4.dns-search ""
  ipv4.method "auto"

You need all the empty quotes as they remove any settings they previously have.

To add a network, use:

nmcli con add ...

With similar parameters.

To make the settings active, reboot. (I tried re-starting Network Manager, but that didn't seem to activate the changes, but a reboot did.)

  • The type flag wasn't obvious to me. I set up eth1 as the Internal Network interface using static IP. sudo nmcli con add type "ethernet" ifname "eth1" con-name "intnet" autoconnect "yes" ip4 "192.168.0.1/24" gw4 "192.168.0.2" – Jack Miner Ewes Dec 7 '18 at 23:57
5

For those who want the NetworkManager approach, I just went through this, taking the tack mss suggested. There's a touch of information on the Debian wiki and full documentation of the options at the GNOME developer site. (From the RHEL7 docs, it does look like their version of nmcli has add support, so hopefully that'll make it in.)

The dynamic IP is pretty simple (just doing the network config, mind, not the VBox side):

[802-3-ethernet]
auto-negotiate=true
mac-address=XX:XX:XX:XX:XX:XX

[connection]
id=Wired connection 1
uuid=xxx-xxxxxx-xxxxxx-xxxxxx-xxx
type=802-3-ethernet
timestamp=0

[ipv6]
method=disabled

[ipv4]
method=auto

Use uuidgen (package uuid-runtime) to make the uuid, and of course fill the MAC address properly. (Usually better to do that than to specify a device name.)

For the static IP (note the semicolon on the DNS array!):

[802-3-ethernet]
auto-negotiate=true
mac-address=XX:XX:XX:XX:XX:XX

[connection]
id=Wired connection 2
uuid=xxx-xxxxxx-xxxxxx-xxxxxx-xxx
type=802-3-ethernet
timestamp=0

[ipv6]
method=ignore

[ipv4]
method=manual
dns=8.8.8.8;8.8.4.4;
address1=192.168.56.101/24,192.168.1.1
  • 1
    This is the directory where the file lives show above /etc/NetworkManager/system-connections/ – Aaron Lelevier Feb 3 at 16:38
3

Normally I edit the file /etc/network/interfaces and mod the info to something like this:

iface eth0 inet static
address 192.168.56.101
netmask 255.255.255.0
gateway 192.168.56.1 (u had 102.168.1.1. So, I guessed it was a mistake)
  • 5
    The OP said, he didn't want to touch /etc/network/interfaces – guntbert Jan 23 '13 at 19:40
  • You're right I would like to do it trough network manager. But since the documentation of this lacks touching the interfaces file will be ok. – Josh Aug 7 '13 at 18:47
2

Since the question is specifically about NetworkManager: I never configured a NM connection from the cli and the nmcli tool doesn't seem to have an option to create a connection. But you might want to have a look what the GUI does when you declare a connection as a system connection. It creates a file in /etc/NetworkManager/system-connections but I don't know if the file format is documented anywhere.

You should be able to enable one of those connections via nmcli con up $name.

2

Edit:

To add another interface that can access the internet in Vbox use the network tab of the settings menu. Then enable an additional interface and set it to NAT (as that's the easiest way to get to the internet). And in the wirtual machine add another interface with dhcp like so: allow-hotplug eth1 and after a linebreak iface eth1 inet dhcp

(For some reason my formatting went bad.)

And this way you can access the net using the host OS's connection.


The commandline "client" of network-manager is confusing and pretty much useless when compared to the standard way of managing interfaces under Linux (and most other unixes). Normally you would first take down the already enabled network-interface (if its enbled) {run ifconfig to find out}:

ifconfig eth0 down #note: I assume you want to configure eth0, replace it if not

After that edit the /etc/network/interfaces file (I prefer to use nano):

sudo nano /etc/network/interfaces

And add a section along the lines of:

allow-hotplug eth0
iface eth0 inet static
address 192.168.56.101
netmask 255.255.255.0
gateway 192.168.56.1

Also be aware that you need to remove every other presence of eth0 from the file othervise the system won't be able to parse the file correctly and you won't have a network connection. And finally you'll need to re-enable the interface:

ifup eth0

And this should cause your ubuntu to automatically set up the interface with your desired parameters whenever it detects that the "cable is connected".

Also if you really want to avoid editing the interfaces file you can use:

ifconfig eth0 192.168.56.101 netmask 255.255.255.0 gateway 192.168.56.1 up

I think that this way the changes won't be permanent (you'll lose them between reboots, etc.), but I hadn't tested that myself.

  • You could have told about the command ip - ifconfig is on the decline. – guntbert Jan 23 '13 at 19:42
2

Currently Ubuntu versions has Network Manager enabled.

You can get the connection name with the command:

nmcli con show

You can modify your static ip address from command line:

sudo nmcli con mod "Connection name" ipv4.addresses xxx.xxx.xxx.xxx/24

Note: /24 defines the network mask to 255.255.255.0

File /ect/network/interfaces is ignored if you have the property managed=false on /etc/NetworkManager/NetworkManager.conf

[ifupdown]
managed=**false**
0

assuming you meant 192.168.1.1 instead of 102.168.1.1. 192.168.56.101 and 192.168.1.1 are on different networks and will not talk without help. what you need is this:

iface eth0 inet static
address 192.168.56.101
netmask 255.255.255.0
gateway 192.168.56.1

assuming you have a box(router/ layer3 switch, etc) with an ip of 192.168.56.1 to answer.

With a /24 (255.255.255.0) you need to have the first three octets match on the host and the default gateway, 192.168.56.X or 192.168.1.X.

  • 1
    The OP said, he didn't want to touch /etc/network/interfaces. – guntbert Jan 23 '13 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.