The quickest way to set your IP address from the command line is to use the versatile and powerful ipconfig utility, which is bundled directly with Mac OS X. We’ll show you how to set an IP address with ipconfig by retrieving one from a DHCP server, and also demonstrate how to set a specific IP address in OS X if you wish to determine a static address for a Mac.

Starting with setting an IP address from a DHCP connection, issue the following command in the Terminal:

sudo ipconfig set en1 DHCP

This will renew your DHCP lease and you will be issued a new IP address from the DHCP server. FYI: en1 is generally wireless/airport, en0 is generally ethernet.

You can check that the IP is set by getting your current IP address from the command line with:

ipconfig getifaddr en1

Doing this before and after will insure you have a new IP.

How to Set a Specific IP Address via Terminal in OS X

You can specify an IP address to set via the command line with the following:

sudo ipconfig set en1 INFORM 192.168.0.150

This allows the user to set a determined static IP manually that won’t change, unless it has been overwritten by a new IP or a new IP has been specified.

Another approach is to bring the networking interface off and on again. This works to set an IP address from a DHCP server by bringing down the interface and starting it back up again, refreshing the IP:

sudo ifconfig en1 down ; sudo ifconfig en1 up

Note: for whatever reason, when you are setting the IP address manually via the command line the Mac OS X Network Preferences doesn’t necessarily catch up to the changes. Do not be surprised if the Network preference pane is telling you that you “Airport does not have an IP address and cannot connect to the Internet.” when in fact, you do have one and you are online. You can verify that you are connected to the LAN or internet by using the ping command.