Ubuntu – How to set a static IP in Ubuntu


I am a new with Linux, having years experience with Windows servers/desktops and am having issues setting a static IP. I am using a method used for previous versions of Ubuntu, which doesn't seem to work with 16.04

I have used the command sudo nano /etc/network/interface and added the following

iface enp0s25 inet static

I have rebooted the system and the Ethernet is pretty much dead, ping doesn't work at all. I have tried to modify /etc/NetworkManager/NetworkManager.conf and made the following changes

#dns=dnsmasq (comment out the dnsmasq)
managed=true (changed from false)

With this I can get Ethernet to work sporadically, however it eventually fails.

I have tried this configuration on two other machines plus a virtual machine as well and all have the same results. I can confirm these settings work fine when I install Windows on any of these machines.
As well when I let DHCP auto configure, everything works fine no issues.

I figure I am missing something here, setting up a static IP should not be difficult at all.

Best Answer

I had the same problem and this was my solution:

sudo nano /etc/network/interfaces

and paste (altering for your network) this under # The primary network interface:

auto enp0s25
iface enp0s25 inet static

You can get correct interface name using Terminal command ifconfig -a on ubuntu 16.04 or ip address on 18.04+

Shutdown your Virtual Machine and then!!! Go to network settings and click on refresh MAC address button a few times :)

enter image description here

and start your VM and you should get internet!

UPDATE 20.02.2019

For ubuntu 18.04+ you need to edit this file


            addresses: []
            dhcp4: no
              addresses: [,]
            optional: true
    version: 2
Related Question