Virtualbox assign static ip to VM

Table of Contents

Virtualbox assign static ip to VM

How To Set Static IP To VirtualBox VM

SSH to your VM

sudo vim /etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      routes:
       - to: default
         via: 192.168.1.1     
      addresses: [192.168.1.21/24]
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

enp0s3: Your network can ping to host
addresses: [192.168.1.21/24]: Your VM static ip

Then

sudo netplan apply

WARNING **: 02:35:11.689: gateway4 has been deprecated

If you use gateway4 parameter like this:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      gateway4: 192.168.1.1
      addresses: [192.168.1.21/24]
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

Perhap you will get this WARNING:

** (generate:49261): WARNING **: 02:35:11.689: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

** (process:49259): WARNING **: 02:35:13.423: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

So you have to change gateway4 to:

routes:
       - to: default
         via: 192.168.10.1

Get gateway ip with netstat command in Linux

| Get gateway ip with netstat command in Linux

To get the network gateway, simply type netstat -rn into the terminal. The gateway will be displayed under the “Gateway” column. Netstat will display all of the active network connections and their status.

netstat -rn

image


  1. https://datmt.com/linux/how-to-set-static-ip-to-virtualbox-vm/
  2. https://unix.stackexchange.com/questions/681220/netplan-generate-gateway4-has-been-deprecated-use-default-routes-instead
  3. https://www.howtouselinux.com/post/linux-command-get-network-gateway

Leave a Reply

Your email address will not be published. Required fields are marked *