How to add a static ip address to a linux distribution such as Debian running as a VPS on VirtualBox

Ensure the VM is powered off

  1. Configure the Network

    Settings -> Network
     

  2. Ensure Adapter 1 is attached to NAT and Adapter 2 is attached to Host-only Adapter

     

  3. Ensure your host’s IP is set similar to the following

    network properties
     

  4. Get the names of your network interfaces, make a note of them

    ip addr
     

  5. Open the interface file in Nano

    su
    cd /etc/network
    nano interfaces
     

  6. Ensure the interfaces are configured as the following. Use your own interface names e.g in the following the interface names are enp0s3 and enp0s8.

        source /etc/network/interfaces.d/*
    
        # The loopback network interface
        auto lo
        iface lo inet loopback
    
        # Adapter 1
        allow-hotplug enp0s3
        iface enp0s3 inet dhcp
    
        # Adapter 2
        auto enp0s8
        iface enp0s8 inet static
        address 192.168.56.102
        netmask 255.255.255.0
        gateway 192.168.56.1
        nameserver 8.8.8.8
      

     

  7. Reboot Debian

    reboot