A cross-platform bash script to automatically update VMware Workstation IP addresses in your system's hosts file. Works seamlessly across Windows (Git Bash/MSYS), WSL, Linux, and macOS with customizable .env configuration.
- 🔄 Cross-platform compatibility - Windows, WSL, Linux, macOS
- 🎯 Interactive IP input - Prompts for IP address with validation
- ⚙️ Environment configuration - Customize defaults via .env file
- 🚫 Duplicate prevention - Ensures no duplicate entries in hosts file
- 💾 Automatic backups - Creates backup before modifications
- ✅ IP validation - Real-time validation of IP address format
- 🎨 Colored output - Easy-to-read status messages
- 🔐 Permission handling - Automatic sudo/admin rights management
# Download the script
curl -O https://gist.githubusercontent.com/weehong/e3cb7b12ddda0fbe53485622275f17b0/raw/56a6e826e53fb1675bc404ad11ba6dfe5ee4a8bf/host.sh
# Make executable
chmod +x update_vmware_ip.sh
# Create sample configuration file
./update_vmware_ip.sh -c
# Copy and customize .env file
cp .env.example .env
# Edit .env with your preferred defaults
# Run in interactive mode (recommended)
./update_vmware_ip.sh -i
# Execute directly from URL with custom IP and domain
curl -fsSL https://gist.githubusercontent.com/weehong/e3cb7b12ddda0fbe53485622275f17b0/raw/56a6e826e53fb1675bc404ad11ba6dfe5ee4a8bf/host.sh | VMWARE_IP=192.168.1.1 VMWARE_DOMAIN=ipvon.server bash
# Or use with arguments
curl -fsSL https://gist.githubusercontent.com/weehong/e3cb7b12ddda0fbe53485622275f17b0/raw/56a6e826e53fb1675bc404ad11ba6dfe5ee4a8bf/host.sh | bash -s -- 192.168.1.1 ipvon.server
# Interactive mode remotely
curl -fsSL https://gist.githubusercontent.com/weehong/e3cb7b12ddda0fbe53485622275f17b0/raw/56a6e826e53fb1675bc404ad11ba6dfe5ee4a8bf/host.sh | bash -s -- -i
Create a .env
file in the same directory as the script to customize default values:
# VMware IP Address Updater Configuration
VMWARE_IP=192.168.170.133
VMWARE_DOMAIN=dev.vernon.personal
# Examples:
# VMWARE_DOMAIN=vm.company.local
# VMWARE_DOMAIN=workstation.dev
# VMWARE_DOMAIN=vmware.local
If no .env
file exists, the script uses these defaults:
- IP:
192.168.1.100
- Domain:
vmware.local
# One-liner execution with environment variables
curl -fsSL https://gist.githubusercontent.com/weehong/e3cb7b12ddda0fbe53485622275f17b0/raw/56a6e826e53fb1675bc404ad11ba6dfe5ee4a8bf/host.sh | VMWARE_IP=192.168.170.133 VMWARE_DOMAIN=dev.mycompany.local bash
# With direct arguments
curl -fsSL https://gist.githubusercontent.com/weehong/e3cb7b12ddda0fbe53485622275f17b0/raw/56a6e826e53fb1675bc404ad11ba6dfe5ee4a8bf/host.sh | bash -s -- 192.168.170.133 dev.mycompany.local
# Interactive mode from remote
curl -fsSL https://gist.githubusercontent.com/weehong/e3cb7b12ddda0fbe53485622275f17b0/raw/56a6e826e53fb1675bc404ad11ba6dfe5ee4a8bf/host.sh | bash -s -- -i
# Create sample .env configuration
./update_vmware_ip.sh -c
# Show help and current configuration
./update_vmware_ip.sh --help
# Interactive mode - uses .env defaults, prompts for IP
./update_vmware_ip.sh -i
# Interactive with custom domain
./update_vmware_ip.sh -i vm.custom.domain
# Use .env file values (or built-in defaults)
./update_vmware_ip.sh
# Update IP only
./update_vmware_ip.sh 192.168.170.133
# Update both IP and domain
./update_vmware_ip.sh 192.168.170.133 vm.example.com
The script follows this priority order:
- Command line arguments (highest priority)
- Interactive input
- .env file values
- Built-in defaults (lowest priority)
Perfect for scenarios where you need to:
- Quick VM setup: One-liner remote execution for instant IP updates
- CI/CD pipelines: Automated VMware IP configuration in build scripts
- Team onboarding: Share a single command for consistent environment setup
- Update VMware Workstation IP addresses across multiple environments
- Sync IP changes between Windows host and WSL instances
- Manage development environments with changing VM IPs
- Maintain team consistency with shared .env configurations
- Avoid manual hosts file editing and potential errors
- Prevent duplicate host entries
VMware IP Address Updater
==================================
[INFO] Loading configuration from .env file...
[INFO] Loaded IP from .env: 192.168.170.133
[INFO] Loaded domain from .env: dev.vernon.personal
Current configuration:
Domain: dev.vernon.personal
Current IP: 192.168.170.133
Existing hosts entry found:
192.168.170.100 dev.vernon.personal
Enter new IP address (or press Enter to use 192.168.170.133): 192.168.170.150
Configuration:
Target: 192.168.170.150 dev.vernon.personal
Detected platform: wsl
Hosts file: /mnt/c/Windows/System32/drivers/etc/hosts
[INFO] Creating backup: /mnt/c/Windows/System32/drivers/etc/hosts.bak
[INFO] Updating existing entry for dev.vernon.personal...
[✅] Hosts file updated successfully:
192.168.170.150 dev.vernon.personal
[✅] Single entry confirmed - no duplicates detected
[INFO] Note: Changes will affect both Windows and WSL
[INFO] You may need to flush DNS cache: ipconfig /flushdns
- Automatic backups: Creates
.bak
files before any modification - Duplicate detection: Scans and removes duplicate entries
- Validation: Ensures IP addresses are properly formatted
- Permission checks: Verifies write access before attempting changes
- Platform detection: Uses appropriate commands for each OS
- Safe .env parsing: Validates configuration values before use
Platform | Hosts File Location | Sudo Required |
---|---|---|
WSL | /mnt/c/Windows/System32/drivers/etc/hosts |
Yes |
Windows (Git Bash) | /c/Windows/System32/drivers/etc/hosts |
Admin Rights |
Linux | /etc/hosts |
Yes |
macOS | /etc/hosts |
Yes |
- Windows: Run terminal as Administrator
- WSL/Linux/macOS: Script will use
sudo
automatically - Bash: Compatible shell environment
- Optional:
.env
file for custom defaults
After updating hosts file, you may need to flush DNS cache:
# Windows
ipconfig /flushdns
# macOS
sudo dscacheutil -flushcache
# Linux (systemd-resolved)
sudo systemctl restart systemd-resolved
your-project/
├── update_vmware_ip.sh # Main script
├── .env # Your configuration (optional)
├── .env.example # Sample configuration
└── hosts.bak # Automatic backup (created when script runs)
Found a bug or have a feature request? Feel free to:
- Report issues in the comments
- Suggest improvements
- Fork and enhance the script
This script is provided as-is under MIT License. Use at your own risk and always backup your hosts file before making changes.
💡 Pro Tips:
- Remote execution: Use
curl -fsSL url | VMWARE_IP=x.x.x.x VMWARE_DOMAIN=hostname bash
for instant setup - Use
./update_vmware_ip.sh -c
to create sample configuration - Use interactive mode (
-i
) for the best experience with validation and feedback - Keep your
.env
file in version control (without sensitive IPs) for team consistency - The script automatically handles platform differences - just run it anywhere!