Skip to content

Instantly share code, notes, and snippets.

@anyulled
Created February 7, 2026 13:53
Show Gist options
  • Select an option

  • Save anyulled/49a7795feff6157bc4d4c3582edb00dc to your computer and use it in GitHub Desktop.

Select an option

Save anyulled/49a7795feff6157bc4d4c3582edb00dc to your computer and use it in GitHub Desktop.
Renew DHCP - Mac OS
#!/bin/bash
# Renew DHCP on all active network services
# Works on macOS Tahoe 26.2+
echo "🔄 Renewing DHCP leases on active services..."
# List all enabled network services
services=$(networksetup -listallnetworkservices | grep -v '\*')
for service in $services; do
# Skip irrelevant services (customize if needed)
if [[ "$service" == "Bluetooth PAN" || "$service" == "Thunderbolt Bridge" ]]; then
continue
fi
echo "- $service:"
# Check current IP config
info=$(networksetup -getinfo "$service" 2>/dev/null)
if [[ $? -eq 0 && "$info" =~ "IP address" ]]; then
# Gentle renew via scutil (no disconnect, like GUI button)
echo " add State:/Network/Service/$service/DHCP/RefreshConfiguration temporary" | sudo scutil
sleep 2 # Brief pause for response
# Fallback: ipconfig set DHCP (releases/renews)
device=$(networksetup -listallhardwareports | awk -F': ' "/Hardware Port: $service/{getline; print \\$2}" | head -1)
if [[ -n "$device" ]]; then
sudo ipconfig set "$device" DHCP
fi
else
echo " (inactive or no DHCP)"
fi
done
echo "✅ Done. Check System Settings > Network for new IPs."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment