Set IP Address from the Mac Command Line

Sep 1, 2010 - 23 Comments

Terminal in OS X

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.

set ip address mac command line

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.

.

Related articles:

Posted by: David Mendez in Command Line, Mac OS, Tips & Tricks

23 Comments

» Comments RSS Feed

  1. Rocky says:

    Hi, so i am trying to change the manual ip to dhcp
    and do my work that is not secure and change back to manual.

    what would be the command for that. its for a work enviorment working on a secure lan line. Please advise the command.

    I appreciate your help

  2. Lawrie says:

    Worked well for me, thanks

  3. Carol says:

    This was the only thing to help! Thanks so much!

  4. David says:

    When I enter sudo ipconfig set en1 DHCP, I get password:[a key icon] Nothing entered shows up, despite typing. three times and you’re out. I have OS Sierra If you’re still monitoring, would appreciate a suggestion, thank you!

    • Paul says:

      Hey David, the terminal doesn’t allow you to see the password as you type it, this is a security precaution and default to all unix environments (Mac OS included) anytime you use ‘sudo’ or otherwise authenticate, whether for setting an IP address or otherwise. But once you get the password prompt, type it anyway and hit return, and it will work.

      A bit more is explained here on this matter:

      https://osxdaily.com/2015/02/04/terminal-wont-show-password-when-typed/

  5. Jack says:

    When I type the sudo command nothing happens. I don’t even get an error message.

  6. James says:

    So very helpful. Thank you. It says I am not connected and there is an issue with the WIFI but internet is working

  7. BooHoo says:

    Problems being complete loss of wifi symbol and internet UNLESS I run that command, each time I turn it on.

    How do I undo?

  8. BooHoo says:

    This has caused far more problems than it has solved – NOT recommended

  9. Matt says:

    I did this in order to try and fix the my IP address is being used by another computer. Doing this now has my wifi as self-assigned (I didn’t do the self assign step) and I can’t get it to go to my regular IP address. Renew won’t do anything the only way to get a connection is to now manually put in my IP address and change the last 2digits. I just want to go back to normal so it doesn’t say self – assigned ip

  10. aub says:

    I typed the command into terminal but now under my system preferences > network > advanced > TCP/IP > it says using DHCP .. but it does not state below which IPv4 address I am using.. why is this? is the permanent?

  11. Andrew Hutton says:

    I am trying to follow the above steps and get this”

    usage: set

    Can anyone tell me what to do please?

  12. sirio says:

    i get this problem with my MAC.. should i do that ..?? Another device on the network is using your computer IP address

  13. lakitu64 says:

    I get this message when I try to do use the “sudo ipconfig set en1 INFORM 192.168.0.104” command:

    WARNING: Improper use of the sudo command could lead to data loss
    or the deletion of important system files. Please double-check your
    typing when using sudo. Type “man sudo” for more information.

    To proceed, enter your password, or type Ctrl-C to abort.

  14. According to the Mac OS X man page, Using ipconfig with INFORM requires the use of an IP address and an explicit subnet mask. However, sadly, I’ve found that INFORM doesn’t work as advertised.

    Have you actually tried this out and found that it worked? Using ipconfig…INFORM, have you ever actually set an IP address statically and yet actually received DHCP option information, like DNS settings, that stuck?

    In my experience, at least on Mac OS X 10.6.5, using INFORM works exactly like setting MANUAL and doesn't actually use DHCP to set any of the other networking options. :(

    Also, what's with the "Renew DHCP Lease" button disappearing in the System Preferences Networking preference pane GUI when "Use DHCP with manual address" is selected? Grr….

  15. […] The other command line option is to use: ipconfig getifaddr en1 which reports back only your en1 (usually wireless) IP address. You can change this to en0 for wired/ethernet too. I have heard ipconfig is not supported in all versions of Mac OS X so I did not recommend this as the first choice. However, using ipconfig you can also set your IP address from the command line. […]

  16. […] a pain depending on your access to the router itself. If resetting the router is a no go, you can renew your DHCP lease in Mac OS X either through the command line (as the linked article shows) or through the Network settings […]

  17. eab3 says:

    ipconfig is a mac os x command-line utility for manipulating DHCP leases, including the DHCP with manual address (which is the INFORM option).

    /usr/sbin/networksetup will do all this and more. Think of networksetup as a command-line equal to Network Preferences.

  18. Borg says:

    Hi,
    ipconfig – it’s a command from the windows, or something I don’t know. Please correct me if I’m wrong ;)

  19. Ed says:

    “sudo ipconfig set en1 INFORM 192.168.0.150” – is this then permanent, i.e. the equivalent of manually setting it in the Network pref pane?

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site