How To Set Static IP To VirtualBox VM

So you’ve installed a new VM on VirtualBox and everything went smoothly. When you boot up the VM and type

ip a

and here is what you got:

You noticed that there isn’t any IP address that begins with 192.168! On your host machine, you type


for Windows, or


For Linux/Mac, you got something like this:

You may even try to ping the VM’s address but no luck!

Well, I’ll show you how to fix that.

How to change network settings so you can ping the VM

The first thing you do is going to Machine->Settings and click on Network then set the settings as below:

virtualbox VM change network settings to bridge mode


Attached to -> Bridge Adapter

Promiscuous Mode -> Allow All

Check Cable Connected.

Then click OK.

Wait for up to 1 minute for the VM to apply the changes. When you type

ip a

again, you should see there is one IP of the VM begins with 192.168

Default IP after applying new network settings.

And you can ping from the host machine to the VM:

That’s great, however, the IP can be changed without you knowing it. That’s usually not a good thing. Next, I’m going to show you how to set a static (fixed) IP for the VM. No worries, it’s pretty quick!

How to set static IP for VirtualBox’s VM

Noticed that when you typed ip a, you see the network interface of your IP (begins with 192.168) is something like enp0s3 (yours could be different). You need to know this for the next step.

Next, type:

sudo touch /etc/netplan/01-netcfg.yaml

Since your VM is new, the file shouldn’t be available yet. The command above creates the file.

Next, use your favorite editor the put the following text in the file:

  version: 2
  renderer: networkd
      dhcp4: no
      addresses: []
        addresses: [,]

Replace enp0s3 with your VM’s network interface and with your favorite IP address and save the file.

Here, I set the IP to to make it different from what it currently is:

Now, type:

sudo netplan apply


ip a

You should see the IP updated as in the config:

Now you have a static IP that you can ping from the host and other VM on your PC.

5 thoughts on “How To Set Static IP To VirtualBox VM”

  1. Thank you for this article. My NAT settings occasionally fail and this is the only way I’ve found to reset it. After establishing a connection in Bridged Mode I can go back and set it to NAT again and it works.

  2. Hi,
    thanks for this manual, as of march 2023, “gateway4:” is deprecated (manual an warning) one should use “default routes ”
    but now I’m out, could you update your manual to the new procedure to “noob understanding” form to cover the new situation? Thanks in advance

    Sorry wrong formatting …

  3. Thanks for the tutorial. However, I encountered the problem that I couldn’t connect external network (ex. ping after following the steps.

    Here’s how I solve the problem. We cannot set the “favorite IP address” to any address. The first 3 part of the address should be the same as the gateway. For example, the gateway is, then we can only set favorite IP address to 192.168.1.X. We cannot set it to, for example,

    Please enlighten me if I’m wrong.


Leave a Comment