How to configure static IP to Ubuntu on VM

  • First, check, what network interface has your virtual machine. For that, use
    ip link
    or 
    ifconfig -a
    in my case, it's  ens18.
  • After that edit file
    sudo mcedit /etc/network/interfaces

    with params like 
    # /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
    # Generated by debian-installer.
    
    # The loopback interface
    auto lo
    iface lo inet loopback
    
    auto ens18
    iface ens18 inet static
    address 185.22.155.111
    netmask 255.255.255.0
    gateway 185.22.155.1
    dns-nameservers 46.17.40.200 46.17.46.200
    
    
    Change ens18 to your network interface and also change address, netmask, gateway and dns-nameservers to IPs, that given to you by your provider.
  • Save file and flush old IP:
    sudo ip addr flush enp0s25
  • And restart networking service:
    sudo systemctl restart networking.service
  • Check applied network settings:
    ifconfig -a
    
    
    ens18: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 185.22.155.111  netmask 255.255.255.0  broadcast 185.22.155.255
            inet6 fe80::34fb:18ff:fe34:d4d4  prefixlen 64  scopeid 0x20<link>
            ether 36:fb:18:34:d4:d4  txqueuelen 1000  (Ethernet)
            RX packets 16558  bytes 1069982 (1.0 MB)
            RX errors 0  dropped 764  overruns 0  frame 0
            TX packets 198  bytes 24923 (24.9 KB)
            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 100  bytes 7732 (7.7 KB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 100  bytes 7732 (7.7 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0