Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
VirtualBox Host-Only Adapter with Static IP

VirtualBox Host-Only Static IP

My typical setup for a development box in VirtualBox uses two NICs. The first uses NAT to allow the box to communicate with the outside world through my host computer’s network connection. (NAT is the default, so shouldn't require any setup.) The second is a "host-only" connection that allows my host and guest to interact.

To create a host-only connection in VirtualBox, start by opening the preferences in VirtualBox. Go to the "Network" tab, and addd a Host-only Network. Modify the host-only network, and disable DHCP. Make a note of the IP address. (Feel free to set the IP address as well, if you like.)

Next, assign this host-only adapter to the virtual machine. Select the VM and press "Settings". Go to the "Network" tab, and select "Adpater 2". Enable the adapter, set it to a "Host-only Adapter", and select the adpater you created above.


To get the static IP address working temporarily, access the termainal on the client, and enter the following to assign a static IP to eth1. (I'm assuming because that's VirtualBox's default. Make sure it matches the IP for your host-only adapter.)

# On GUEST: Temporarily assign a static IP to eth1
ifconfig eth1 netmask up


The last command should work until you have to restart the virtual machine. To make the change persistent, you'll need to modify /etc/network/interfaces

# On GUEST: Modify the configuration file
sudo nano /etc/network/interfaces

Add the following to configure eth1 to use a static IP address and come up when the system starts.

# The host-only network interface
auto eth1
iface eth1 inet static

Accessing the Guest from the Host

Finally, you'll probably want to add some names to your host machine's /etc/hosts file. Make sure to add each hostname you will use on your guest.

# On HOST: edit /etc/hosts
sudo nano /etc/hosts

Add a line that starts with the static IP address for the guest, followered by whitespace, then each of the hostnames that should point to your guest.

# Inside /etc/hosts on your HOST myguest.home.local


Copy link

Manjesh80 commented Dec 18, 2016

This is cool .. and works like a charm

Copy link

webian commented Feb 22, 2017

Nice tutorial, thank you!

Copy link

numberwhun commented Mar 24, 2017

Excellent, thank you!

Copy link

deglot commented Mar 31, 2017

It's important to bare in mind that if you specify the gateway (as the value taken from VirtualBox, when you are configuring the Host-Only Adapter) you may end-up with a non-internet connection. Just do not put any gateway information when configuring static IP Address and you should be find.

Copy link

JLudwig2552 commented Apr 6, 2017

Thanks for the instructions.
I had to deviate slightly for Windows 7 host and Ubuntu 16.04 guest. I didn't create the temporary eth1 adapter which may be why.

I used the host's IP of the "VirtualBox Host-Only network" for the network value, and added one to this for the address value.

The host's IP of the "VirtualBox Host-Only network" for me was so the address I used was

Thus my /etc/network/interfaces looked like this:

auto enp0s10
iface enp0s10 inet static
  • Note enp0s10 was used because it was present inside /sys/class/net/ - run ls /sys/class/net/ to see all your network adapters. One of them should represent the host-only network.

Copy link

mmorejon commented Apr 17, 2017

Thanks @JLudwig2552 !!!!

Copy link

dxramax commented Jun 14, 2017

after hours of searching, this is the only way it worked, from the first time.
Thanks a lot @pjdietz

Copy link

NarasimhaChinimilly commented Jul 7, 2017

Supreb !!! Works like a charm...

Copy link

jsami commented Jul 12, 2017

Nice!!! Thank you.

Copy link

liuxinjn commented Sep 27, 2017

thx so much.

Copy link

leoxs22 commented Oct 22, 2017

OMG, I was going crazy trying to fix the lost internet connection. Two days with that problem.
Thanks a lot!

Copy link

huoxiaoyao commented Nov 8, 2017

Adapter 2 does not always correspond with eth1 (might also be eth0). If you are running into problems, switching the settings from those interfaces might be your solution

Copy link

anvis2000 commented Dec 26, 2017

Thank you!! That solved my problem.

Copy link

sibagithub commented Jan 4, 2018

I am not getting a option to add a Host-only Network in VirtualBox-->preferences-->"Network" tab.
I am only getting a option to add new "NAT Network". How can I add a Host-only Network.

I have VirtualBox installed on my mac. I have installed ubuntu & centOS on VirtualBox.
(I am not getting eth0 or eth1 in ifconfig. I have enp0s3, enps08, lo & vibr0 under ifconfig.)

screen shot 2018-01-04 at 7 23 23 pm

Copy link

chaitanya9186 commented Jan 5, 2018

@sibagithub, I am also facing the same problem.

Copy link

KDCinfo commented Jan 7, 2018

@sibagithub @chaitanya9186 -- I'm using VirtualBox 5.2.4 on Win10 x64 (with Ubuntu 16.04 LTS x64 ISO running inside the VM), and I found the host-only network setting from the main VirtualBox interface (with no VM open) File->Host Network Manager->Create. Although, after I created one, I realized I didn't even see the one already sitting there (VirtualBox Host-Only Ethernet Adapter #2). Upon realizing that, and it was already assigned to my Host-only Adapter (in Settings->Network), I removed the new one I had just created, and moved on to the "make it permanent" part.

Unfortunately, the specifics of this guide didn't get me through, so I found and successfully used instructions from: Although I did not, however, go through the NAT part (all I needed was dev access from the host).

With just my settings below, I was able to hit Apache from my Win10 host at the address, and I could still access my Samba share (although slightly off-topic, I've also provided those settings below).

	VBox -> File -> Host Network Manager (Ctrl-W)
		Configure Adapter Manually
		IPV4 Address:
		IPv4 Mask:
		IPv6 Address:	fe80::grayed out
		IPv6 Prefix Ln:	64

	VBox -> Settings -> Network
		Attached to:	Host-only Adapter
		Name:		VirtualBox Host-Only Ethernet Adapter #2
		Adapter Type:	Intel PRO/1000 MT Desktop (82540EM)
		Promiscious:	Deny
		Cable:		Connected

	**Open VM**
	sudo vi /etc/network/interfaces
		source /etc/network/interface.d/*
		auto lo
		iface lo inet loopback
		auto enp0s3 inet static

	**Samba Share**
	sudo vi /etc/samba/smb.conf
		#This 'Code' section added at end of file.
		path = /var/www/html/
		available = yes
		valid users = yourubuntulogin
		read only = no
		browsable = yes
		public = no
		writable = yes
	sudo smbpasswd -a yourubuntulogin
	sudo service smbd restart

Copy link

sibagithub commented Jan 8, 2018

Thanks @KDCinfo.
Using file—>Host Network Manager, I could create a "Host-only Network”.
But I am not getting eth0 or eth1 using ifconfig command. I have enp0s3, enps08, lo & vibr0 using ifconfig.

Copy link

sibagithub commented Jan 10, 2018


After adding a 'Bridged Adapter', I got a new entry enps10 in ifconfig. And I could SSH into the inet IPAddr of enps10
screen shot 2018-01-10 at 9 29 23 am

Copy link

mohamma548 commented Jan 18, 2018

Thank you! problem solved

Copy link

shturec commented Apr 16, 2018

Thanks for the guide!
I used it with Ubuntu 17.10.01 server and one thing that bugged me was that ifup/down utilities were missing in the guest OS, so updating the /etc/network/interfaces was no good for bringing up the host-only adapter after restart. The ifconfig based, manual setup was working completely fine.
Therefore apt install ifupdown2 was necessary for me to complete the process successfully. Having this installed was probably an obvious prerequisite given that the interfaces file starts with the comment "... configuration file for ifup(8), ifdown(8)", but yeah, well, documentation... :-)
I hope that helps.

Copy link

saty9999 commented May 4, 2018

I went into preferences.I added on host only network .Given ip .but what about NAT NETWORKING should be disabled or what?what is the significance of NAT NETWORKING THERE ? I did what you all said stilll windows is not able to ping outside world .what to do .

Copy link

sagespidy commented Jun 13, 2018


Copy link

RumiLinux commented Nov 3, 2018

Hi inside my virtual box i have 2 vms of ubuntu. My virtual box is hosted on windows 10. I am trying to ping host from vms but not working. I tried setting NAT in both vm for adapter1. But still in vain. Can some1 explain in detail how to set it up and configure the NIC if needed?

Copy link

n6151h commented Nov 17, 2018

This all goes out the window if you're using Ubuntu 18.04 (bionic beaver) server, which now uses netplan. /etc/init.d/networking isn't there anymore, though /etc/network/interfaces still is (for reasons I cannot fathom.) Instead, you'll want to modify /etc/netplan/50-whatever.yaml to include your interface. This link describes what to modify and how:

Copy link

krsurajd commented Mar 1, 2019

Host only Network is moved in the versions in 5.2.0 .
If you are unable to find the host only network card in Virtual Box .
This tool is moved in 5.2.0. Look on the main UI toolbar, specifically the "Global Tools" split button on the right.

Copy link

ioana996 commented May 10, 2020

I've been searching for hours for a good alternative. Yours is simple, well explained and functional. Thank you! You spared me some serious time.

Copy link

JoergMittagLawo commented May 24, 2020

Please, do not use as a fixed IP address. By default, VirtualBox runs a DHCP server on the host-only network that hands out IP addresses from onwards. The range is free for static IPs. ( is the host itself.)

Copy link

granjerox commented Jan 5, 2022

Hello, one little TIP I havent found as a full example.
As long as the defautl behaviour for host-only network is the IP set by the internal DHCP server, wouldn't it better to setup static leases for our hosts?

1.- FindOut network name for dhcp server:

./VBoxManage list dhcpservers
NetworkName:    HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter
Dhcpd IP:
Enabled:        Yes
Global Configuration:
    minLeaseTime:     default
    defaultLeaseTime: default
    maxLeaseTime:     default
    Forced options:   None
    Suppressed opts.: None
Groups:               None
Individual Config:

2.- You need also the mac address of your VM's interface

PS C:\Program Files\Oracle\VirtualBox> ./VBoxManage list vms
"accadev-ubuntu20.04" {2a98947e-4b8c-4bc3-9441-2b556d0b33a1}
"accadev-ansible01" {1d261714-9b49-47e2-a634-bc0677f5b707}

PS C:\Program Files\Oracle\VirtualBox> ./VBoxManage showvminfo accadev-ubuntu20.04 | Select-String -Pattern 'MAC'

NIC 1:                       MAC: 0800275452FB, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82543GC, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 2:                       MAC: 08002703E954, Attachment: Host-only Interface 'VirtualBox Host-Only Ethernet Adapter', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none

3.- Setup Static Lease for that MAC.
./VBoxManage dhcpserver modify --ifname "VirtualBox Host-Only Ethernet Adapter" --mac-address=08:00:27:f8:31:fa --fixed-address=

4.- Restart DHCP server to apply changes
./VBoxManage dhcpserver modify --ifname "VirtualBox Host-Only Ethernet Adapter" --mac-address=08:00:27:f8:31:fa --fixed-address=

And that's it. You can do it not only for host-only networks but for any Vbox network with an DHCP server attached


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment