network_dhcp_set_macos.sh - limehawk/rmm-scripts GitHub Wiki
network_dhcp_set_macos.sh
Configures primary network interface to use DHCP.
Overview
This script configures primary network interface to use DHCP. Toggles the interface off/on to ensure settings take effect. Supports both en0 and auto-detection of active interface.
Purpose
Configures a macOS network interface to use DHCP for automatic IP addressing. Toggles the network service off and on to ensure the new DHCP settings take effect immediately.
Prerequisites
- Root/sudo access required
- macOS 10.14 or later
- networksetup command available
Configuration
Required Inputs
- INTERFACE: Network interface to configure (default: auto-detect or en0)
- TOGGLE_DELAY: Seconds to wait between off/on toggle (default: 2)
Behavior
- Detects or uses specified network interface
- Gets the network service name for the interface
- Disables the network service
- Sets DHCP on the interface
- Re-enables the network service
- Verifies DHCP configuration
Security Notes
- No secrets exposed in output
- Runs with elevated privileges (sudo required)
- Temporarily disrupts network connectivity
Exit Codes
- 0 - Success
- 1 - Failure
Example Output
[ INPUT VALIDATION ]
--------------------------------------------------------------
Running as root : Yes
Interface : en0 (auto-detected)
Network Service : Wi-Fi
Toggle Delay : 2s
[ CURRENT CONFIGURATION ]
--------------------------------------------------------------
Current IP : 192.168.1.100
Current Config : Manual Configuration
[ OPERATION ]
--------------------------------------------------------------
Disabling network service...
Setting DHCP on en0...
Enabling network service...
[ RESULT ]
--------------------------------------------------------------
Status : Success
Configuration : DHCP Configuration
IP Address : 192.168.1.150
[ FINAL STATUS ]
--------------------------------------------------------------
DHCP has been configured on Wi-Fi (en0).
If IP shows 'Acquiring...', wait a few seconds for DHCP lease.
[ SCRIPT COMPLETED ]
--------------------------------------------------------------
Version History
- 1.0.0 (November 2024) - Initial release
Links
- View Script Source
- Scripts - Back to script index