How do I use a static IP in Ubuntu 17.10 and newer?

I changed config from dhcp to static (192.168.0.17), but still getting a dhcp assigned (192.168.0.141) IP. I don't know where else to check... any idea?

ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.141  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe87:6981  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:87:69:81  txqueuelen 1000  (Ethernet)
        RX packets 43080139  bytes 55213169928 (55.2 GB)
        RX errors 0  dropped 1  overruns 0  frame 0
        TX packets 17923871  bytes 1406116280 (1.4 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 56350  bytes 6166732 (6.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 56350  bytes 6166732 (6.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

nmcli d

DEVICE  TYPE      STATE      CONNECTION
ens33   ethernet  unmanaged  --
lo      loopback  unmanaged  --

/etc/network/interfaces

# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
# Generated by debian-installer.

# The loopback interface
auto lo
iface lo inet loopback

#The primary network interface
auto ens33
iface ens33 inet static
address 192.168.0.17
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 192.168.0.1

/etc/NetworkManager/NetworkManager.conf

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=false

[device]
wifi.scan-rand-mac-address=no

uname -a

Linux server 4.13.0-16-generic #19-Ubuntu SMP Wed Oct 11 18:35:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Solution 1:

Networking is handled by netplan by default in Ubuntu Server 17.10. I suggest that you edit the /etc/netplan/01-netcfg.yaml file to read:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.0.17/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [8.8.8.8,192.168.0.1]

Exit and save your changes by running the command:

sudo netplan apply

Please note and follow the spacing and indentation.

Comment out all the ens33 stanzas in /etc/network/interfaces. Reboot.

Any improvement?