How to persist IP of VM

Hi ,

i created a VM on my laptop using osboxes centos image 64 bit.
when i login ip link interfaces dont have any IP assigned.
when i do IP assignment to one of the interfaces which is UP , till the time i am logged in the IP is persistent.

what can i do to persist this IP? Any way even after restart of VM. i am using VM box.

rajiv

  1. make sure that there is a host-only network to connect to.
    To check if you already have one, start VirtualBox and then click on the Global Tools button and make sure you are on the Host Manager Network tab.

Take note of the IP Address of the network and the network mask. For example in the screenshot below, the IP Address is 192.168.99.1 with network mask of 255.255.255.0 which means you can assign IP addresses 192.168.99.2-254 statically

Screen Shot 2021-05-18 at 15.38.07

  1. Disable the DHCP server since you will assign IP addresses statically
  2. make sure that the VM is shut down
  3. in the VirtualBox app select the VM and click on the Settings button. Click on the Network tab. Adapter 1 should be your NAT adapter. Click on the Adapter 2 subtab, select Host-only Adapter and the name of the host-only network
    Screen Shot 2021-05-18 at 15.40.04
  4. Click OK and start up the VM. Log in as root through VirtualBox console. Run
$ ip addr
  1. Create a file called ifcfg-enp0s8 in /etc/sysconfig/network-scripts/ and give it the following contents:
DEVICE=enp0s8
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.99.10
NETMASK=255.255.255.0

Note:
Where NETMASK should match the settings for your host-only network as obtained above and IPADDR should be an available IP address in the host-only network

Finally, you can restart and find that your IP does not change

$ systemctl restart network
$ ip addr