Skip to content

Instantly share code, notes, and snippets.

@brennanfee
Last active February 13, 2018 09:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brennanfee/8476a83cc32d81d8d9bced3c943c250e to your computer and use it in GitHub Desktop.
Save brennanfee/8476a83cc32d81d8d9bced3c943c250e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# mac-set-hostname.sh - This script will set the local machines name and
# domain information. Two parameters are required: <machine name> <domain name>
# Bash "strict" mode
set -euo pipefail
IFS=$'\n\t'
if [[ $# -lt 2 ]]; then
echo "You must pass 2 parameters, the host name and the domain name."
fi
hostname=$1
domainname=$2
sudo scutil --set ComputerName $hostname
sudo scutil --set LocalHostName $hostname
sudo scutil --set HostName $hostname.$domainname
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $hostname
sudo domainname $domainname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment