How to "refresh" DHCP Address via the Terminal?

Posted:
in macOS edited January 2014
Hey everyone!



When using Windows, one can release/refresh a machine's DHCP address by opening up a cmd-shell and entering "ipconfig /release" and "ipconfig /renew".



Is there any way to accomplish this via the MacOS X Terminal?



Greetings to everyone!

durandal

Comments

  • Reply 1 of 10
    johnqjohnq Posts: 2,763member
    If physically plugged into a network:

    sudo ipconfig set en0 DHCP



    If you are wireless:

    sudo ipconfig set en1 DHCP



    Now this assume you've set up the root user. If so, sudo will ask for your password.



    You can alias this command to whatever you like.



    Ask if you have further questions about the above.
  • Reply 2 of 10
    Quote:

    Originally posted by johnq

    If physically plugged into a network:

    sudo ipconfig set en0 DHCP





    nope, that's it - thanks a bunch

    durandal
  • Reply 3 of 10
    bungebunge Posts: 7,329member
    johnq,



    Is there a way to reset an AirPort Base Station from the command line? Mine craps out far too often.
  • Reply 4 of 10
    johnqjohnq Posts: 2,763member
    Not sure myself but www.macosxhints.com is a good place to check.
  • Reply 5 of 10
    I'm sure you'll be happy to hear that in Panther there's actually a button for this in the Network system prefs panel.
  • Reply 6 of 10
    scottscott Posts: 7,431member
    Quote:

    Originally posted by bunge

    johnq,



    Is there a way to reset an AirPort Base Station from the command line? Mine craps out far too often.




    Good question. My comcast is always blinking out on me and requires a refresh. With a base station it would be even more of a pain in the ass.
  • Reply 7 of 10
    johnqjohnq Posts: 2,763member
    You guys should have a cable modem linked to a multi-port router (I like NetGEAR) then do a branch to 1. the Airport base station and 2. to an ethernet wire so you can have the option to have high connection speeds (3 and 4 could be say, XBOX and PS2 or another Mac or PC). (You can also go Ethernet from the Airport but it's more limiting IMHO plus the hole is tight for most cables).



    The point is, you can then get to the router via a web interface and configure/reset/manage it all you want. Airport (I believe; from my experience) can configure itself based on what it is sent via the router.



    Airport for me has never needed manipulation aside from initial setup and occasional user blocking (when roomates don't pay their share )



    Not a guru, but I know what I have works great



    For example: network.jpg
  • Reply 8 of 10
    A fast and easy way to do this is to use the control panel. Change the TCP/IP setting to configue Manually. Hit apply. Then change back to configure Using DHCP and hit Apply again.
  • Reply 9 of 10
    scottscott Posts: 7,431member
    An even faster way to do that is set up locations to do the same thing.
  • Reply 10 of 10
    Quote:

    Originally posted by fatmac84

    A fast and easy way to do this is to use the control panel. Change the TCP/IP setting to configue Manually. Hit apply. Then change back to configure Using DHCP and hit Apply again.



    Jap, I know. But I wanted to automate this via AppleScript - and using some shell command for it results in a simple one-liner:



    do shell script "sudo ipconfig set en0 DHCP" with administrator previliges password "[your password here]"



    thanks anyway

    durandal
Sign In or Register to comment.