Accessing the Command Line Interface
The primary method for managing VirtualBox network settings on macOS is through the terminal application. While the VirtualBox Manager GUI provides basic visibility into network adapters, it does not expose granular DHCP configuration options such as subnet masks, default gateways, or custom lease durations. The VBoxManage utility is installed automatically with the VirtualBox package and resides in your system path.
To begin, open the Terminal app located in your /Applications/Utilities folder. You do not need administrative privileges to view current settings, but you will require them to modify network configurations. Ensure that no virtual machines are currently running the specific HostOnly adapter you intend to modify, as some changes may require a restart of the virtual machine or the VirtualBox networking service to take effect.
Identifying Your HostOnly Network
Before modifying parameters, you must identify the exact name or UUID of the HostOnly network you wish to configure. VirtualBox typically creates a default HostOnly network named vboxnet0, but you may have created additional interfaces for specific projects. You can list all existing networks and their current states by running the following command:
VBoxManage hostonlyif ipconfig --list
This command outputs detailed information about each HostOnly interface, including its MAC address, IPv4 address, and whether the DHCP server is currently enabled. If you see multiple entries, note the name of the interface associated with the IP range you want to adjust. For most standard setups, vboxnet0 is the target. If the interface does not exist, you can create one using VBoxManage hostonlyif create, which will generate a new interface with default parameters.
Configuring DHCP Server Parameters
Once you have identified the interface, you can configure the DHCP server settings. The most common requirement is to define the pool of IP addresses that VirtualBox will assign to guest operating systems. By default, VirtualBox uses a small range, often starting at 192.168.56.101. You can expand this range or change the base address using the dhcpserver modify command.
VBoxManage dhcpserver modify --netname vboxnet0 \
--ip 192.168.56.1 \
--mask 255.255.255.0 \
--lowerip 192.168.56.100 \
--upperip 192.168.56.254 \
--enable
In this example, the gateway IP is set to 192.168.56.1, which is also the IP address of the HostOnly adapter on the host machine. The --lowerip and --upperip flags define the boundaries of the DHCP pool. Adjust these values based on your network requirements. If you need to disable the DHCP server entirely, replace --enable with --disable.
Setting Lease Times and Advanced Options
For environments where virtual machines are frequently started and stopped, default lease times might cause IP conflicts or exhaustion. You can customize the lease duration using the --lease-time parameter. This value is specified in seconds. A shorter lease time ensures that unused IPs are returned to the pool more quickly, while a longer lease reduces DHCP traffic overhead.
VBoxManage dhcpserver modify --netname vboxnet0 \
--lease-time 3600
This sets the lease time to one hour (3600 seconds). Additionally, you can specify domain names that will be sent to clients via the DHCP option. This is useful if your internal DNS requires specific suffixes for resolution within the isolated network.
VBoxManage dhcpserver modify --netname vboxnet0 \
--domain-name "local"
These settings persist across reboots of the host macOS system. However, changes to the DHCP server configuration do not affect already leased IPs in guest VMs. Guests will receive updated network parameters only after they renew their DHCP lease, which typically happens upon reboot or when you manually trigger a release and renew process within the guest OS.
Verifying Configuration and Troubleshooting
After applying changes, verify that the configuration was accepted correctly. Run the hostonlyif ipconfig command again to inspect the active settings. If the output shows unexpected values, ensure that there were no typos in the previous commands. Common errors include invalid IP formats or overlapping ranges.
If guests are not receiving IP addresses despite the DHCP server being enabled, check the firewall settings on your macOS host. While VirtualBox HostOnly adapters generally bypass standard firewalls, certain security software or strict macOS firewall rules might block UDP ports 67 and 68, which are used for DHCP communication. Restarting the VirtualBox networking service by toggling the adapter off and on in the VirtualBox Manager GUI can also resolve transient connectivity issues.
For users looking to secure connections within these isolated networks, understanding how to handle certificate authorities is crucial. You might encounter situations where internal services use self-signed certificates. In such cases, configuring trust anchors becomes necessary. For more details on handling unknown certificates in network tools, see our guide on establishing TLS connections with unknown CAs.
Frequently Asked Questions
Can I assign static IPs to VMs on a HostOnly network?
Yes, you can configure static IP addresses within the guest operating system itself, independent of the DHCP server. Even if the DHCP server is disabled, you can manually set an IP address, subnet mask, and gateway in the guest's network settings. This is useful for servers that require consistent addressing for internal routing.
What happens if I delete the HostOnly adapter?
Deleting the HostOnly adapter removes the network interface from the host and invalidates any DHCP reservations associated with it. Any virtual machines using that adapter will lose network connectivity until you recreate the adapter and reconfigure the network settings in both the host and the guest VMs.
How do I reset DHCP settings to defaults?
There is no direct "reset" command, but you can achieve this by disabling the DHCP server and then enabling it again with default parameters. Alternatively, deleting the HostOnly adapter and creating a new one will restore the factory default IP range and settings, though this will disconnect all currently attached VMs.
Is it possible to run multiple HostOnly networks simultaneously?
Yes, VirtualBox supports multiple HostOnly adapters, typically named vboxnet0, vboxnet1, and so on. Each adapter operates as a separate isolated network segment. You can configure distinct DHCP pools and settings for each, allowing you to segregate different groups of virtual machines.
Why are my VMs getting IPs outside the configured range?
This usually indicates that another DHCP server is present on the network, such as your physical router or a conflicting virtualization software. Since HostOnly networks are isolated, this is rare unless you have bridged the adapter incorrectly. Check your VM's network adapter type to ensure it is set to "Host-only Adapter" and not "Bridged Adapter."