Imagine you have an Apple device like a Macmini, MacBook, or an iMac in a remote location. You only have access to it via SSH and no Desktop GUI interaction is allowed.
What if you wanted to change the IP address of the device? For example, how do you assign a static IP address instead of DHCP?
Command line is your option in that case.
Let's see how to get it done...
To make changes like network interface configurations, you need to be a user with super user privileges.
First, get a list of all your network services.
That command will result in an output like below.
>networksetup -listallnetworkservices An asterisk (*) denotes that a network service is disabled. Apple USB Ethernet Adapter USB 10/100/1000 LAN Wi-Fi Bluetooth PAN Thunderbolt Bridge
Then use the desired service name in the following command:
networksetup -setmanual SERVICE IP SUBNET ROUTER
For example, to change the IP address of my Wi-Fi interface, I would use a command like this:
networksetup -setmanual Wi-Fi 192.168.1.2 255.255.255.0 192.168.1.1
In the above example,
192.168.1.2 is my new IP address.
192.168.1.1 is the address of the default gateway, which is the router most of the time.
To set it back to DHCP, use the following command:
networksetup -setdhcp SERVICE
To keep DHCP services but only use a manually designated IP address, then use the following command:
networksetup -setmanualwithdhcprouter SERVICE IP
Restart the device
sudo shutdown -r now and see if the new address persists.
If everything goes well, it should persist.