Release/renew IP address via Terminal in OS X

127,717

Solution 1

sudo ipconfig set en0 BOOTP
sudo ipconfig set en0 DHCP

Should do it.


Sources:

Solution 2

I find that the commands

ipconfig set <interface> BOOTP 
ipconfig set <interface> DHCP

do accomplish releasing the interfaces IP, but won't renew it. This behavior might be explained because I'm working on a MACBook Air. However, I've also tried this on a MacBook Pro with the same outcome. A quick perusal of networksetup's man page reveals two sister commands to the ones for ipconfig. These commands are

networksetup -setbootp <network service name>
networksetup -setdhcp <network service name>

where is the name seen in the network settings status pane. If you open the network settings you can watch this command work by watching the "Configure IPv4" option change. Note, to save on typing I excluded the sudo from all my commands, and of course if your system requires elevated priveleges to execute commands you should use "sudo" on the front of the commands listed in this answer. Hope this saves someones the hair pulling and fuming I experienced looking for such a simple command.

Solution 3

If you need to do this without having sudo privileges, then the easiest way is to create a new location, let's call it "DHCP", and then change to it, and back again… This also causes Mac OS X to reconfigure the networking. The commands needed are:

scselect DHCP
scselect Automatic

You can create a new network location from the network preference setting panel, select the dropdown at the top that says "Automatic" and then "Create New…".

Share:
127,717

Related videos on Youtube

Peter Mortensen
Author by

Peter Mortensen

Updated on September 17, 2022

Comments

  • Peter Mortensen
    Peter Mortensen over 1 year

    I am looking to release and renew my IP address in OS X 10.4 (Tiger) using Terminal. Essentially, I need the OS X equivalent of Windows':

    C:\\> ipconfig /release  
    C:\\> ipconfig /renew
    

    However, I need the interface to remain active during this process, so using ifconfig down/up will not work.

    I believe I can clear the IP address with ifconfig <interface> delete, but I'm not sure how to get the DHCP client to reassign the address. An article from 2002 suggests using set dhcp, but Apple's ifconfig man page does not include this information.

  • David Graham
    David Graham over 9 years
    To view a list of the <network service names> you can use networksetup -listnetworkserviceorder
  • Peter Mortensen
    Peter Mortensen over 9 years
    Is this an answer or a question?
  • hmj6jmh
    hmj6jmh over 9 years
    It's yet another way to accomplish the same thing so it is an answer. I just commented on my complete experience with it.
  • molson504x
    molson504x about 6 years
    This was perfect. When doing it via ipconfig it was renewing DHCP and I did have internet connectivity, though the computer thought differently. With using networksetup it seems to have fixed all of that.