3

How do I assign static IP addresses to interfaces in Ubuntu (17.04) without rebooting the machine? This is pretty straightforward on a Unix machine, but I'm having trouble on this one.

Please don't mark this as duplicate (just yet). I've read a number of other posts, but the instructions don't seem to work.

I'm configuring a bunch of routers and switches and I need to be able to:

  • Permanently (survives a reboot/crash) change the the IP of an interface
  • Permanently (survives a reboot/crash) change the interface back to DHCP (or BOOTP, or whatever)
  • Make these changes without X (and with, from an xterm).

I've already tried editing /etc/network/interfaces and running /etc/init.d/networking restart as mentioned here. This failed to change anything until I rebooted.

The machine was originally set up with DHCP. I'd like to be able to go back and forth quickly. The machine has several interfaces, and because it's used to configure other people's networks, I need to be able to switch them with as little fuss as possible.

If I boot it with a static IP, what do I need to do the get a DHCP address?

If I boot with DHCP and switch to static, will I have to kill off dhclient? What about other DHCP controlled interfaces?

Thanks.
-E

2 Answers2

3

Network manager is service manager networking on your Linux , This service contain some interfaces to work with it . nmcli is one of the richest interface to manager networking .

If you want set static IP to your Linux via nmcli try following command :

$ nmcli connection modify eth0 ipv4.address x.x.x.x/y

With above command you permanently add IP to your interface . ( replace eth0 with your interface name ) .

Than run following comand :

$ nmcli connection up eth0

To active your connection without rebooting .

  • Cool beans. Thanks @Ali. So what is /etc/network/interfaces for? And what happens if it conflicts with, for example, /etc/NetworkManager/system-connections/ethernet-ens1? I don't know how to get a newline in the comment, but here is what I did: nmcli connection add type ethernet ifname ens1 ; nmcli connection edit ethernet-ens1 ; nmcli -p con up ifname ens1 – Erik Bennett Aug 16 '17 at 20:12
  • Also, I notice the nmcli differs between Ubuntu versions. I only mention it for future explorers. -E – Erik Bennett Aug 16 '17 at 20:15
  • Well all NIC have configuration file which you can find under etc but it's not recommended to edit them by hand . In most case you need to rebooting machine to be cared of by newtork manager . That why we use command like nmcli and nmtui . – Ali Ghasempour Aug 17 '17 at 02:09
  • To add up you should set a connection profile in new network manager . Every NIC can have a different profile but only one profile can be active on the time . – Ali Ghasempour Aug 17 '17 at 02:14
  • Good pointers. I didn't know about the different profiles. – Erik Bennett Aug 18 '17 at 01:01
0

I found NetworkManager to be too unpredictable for my use. The answers, in my case were to be found in the interfaces(5) man page. More discussion on NetworkManager may be found here. This is not an indictment of NetworkManager, but rather a note that it didn't work for me. Everytime I would unplug the interface from the switch and move it to a different port, NetworkManager would go to work reconfiguring the interface on my machine.