How can I set a static IP, gateway, net mask, and dns using terminal / applescript - OS X 10.7.5

7,876

Create a second network location for the office (see the "Making new locations" section of [Apple's KB article #HT5289] (http://support.apple.com/kb/HT5289)). Each location is essentially a separate set of network settings, so you can have one set up for DHCP and the other for the office static IP, then switch between them using the Locations submenu under the Apple menu (note that this doesn't appear until you create a second location).

BTW, the literal answer to your question is the networksetup command (e.g. sudo networksetup Ethernet 10.0.0.50 255.255.255.0 10.0.0.1), but locations are a much better way to handle this.

Share:
7,876

Related videos on Youtube

ghaschel
Author by

ghaschel

Updated on September 18, 2022

Comments

  • ghaschel
    ghaschel almost 2 years

    I use my macbook at home and at work. At work I need to use a static IP, gateway, DNS and net mask. At home I use it in DHCP mode.

    Manually setting them every day really sucks.

    How can I set them on terminal / applescript?
    And how can I get back to DHCP via terminal / applescript?

    • ganesh
      ganesh about 11 years
      I have no OS X to check it with, but `ifconfig en0 mystatic_IP mask m.m.m.m' for the IP (set m.m.m.m to the actual desired mask, e.g. 255.255.255.0). DNS: Has OS X an /etc/resolv.conf? Gateway: see route (route add default gw ....)
    • Bert
      Bert about 11 years
      Have you looked into using the locations option in Network Preferences?
  • ghaschel
    ghaschel about 11 years
    Thank you! i almost couldn't find the location dropdown menu haha ;)