Skip to content

Instantly share code, notes, and snippets.

@stafot
Last active December 11, 2025 06:19
Show Gist options
  • Select an option

  • Save stafot/3aafd5abffd8547bd16db1e3fa0593ea to your computer and use it in GitHub Desktop.

Select an option

Save stafot/3aafd5abffd8547bd16db1e3fa0593ea to your computer and use it in GitHub Desktop.
Resets virtualbox DHCP leases to ensure that minikube will always take a specific IP.
#!/usr/bin/env bash
function minikube_reset_vbox_dhcp_leases() {
# Check OS version
case $OSTYPE in
darwin*)
VBOX_CONFIG_DIR=Library
;;
linux*)
VBOX_CONFIG_DIR=.config
;;
esac
# # Reset Virtualbox DHCP Lease Info
echo "Resetting Virtualbox DHCP Lease Info..."
kill -9 $(ps aux |grep -i "vboxsvc\|vboxnetdhcp" | awk '{print $2}') 2>/dev/null
if [[ -f ~/$VBOX_CONFIG_DIR/VirtualBox/HostInterfaceNetworking-vboxnet0-Dhcpd.leases ]] ; then
rm ~/$VBOX_CONFIG_DIR/VirtualBox/HostInterfaceNetworking-vboxnet0-Dhcpd.leases
fi
}
minikube_reset_vbox_dhcp_leases
@marcelser
Copy link

what about git bash with ostype "msys" and "cygwin" (those 2 are usually the same)?

@stafot
Copy link
Author

stafot commented Sep 25, 2019

Feel free to update accordingly, my use case is covered and unfortunately have not a msys env to test against.

@GPrimola
Copy link

Why not vboxmanage dhcpserver stop --interface=vboxnet0 at line 17?

Thank you by the way, your snippet helped me a lot! 😄

@stafot
Copy link
Author

stafot commented Dec 11, 2025

@GPrimola I think that back then when I initially created this was not that option, but it is so long ago so I can fully recall the details!

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