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

1

1

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?

ghaschel

Posted 2013-04-10T11:19:15.493

Reputation: 113

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 ....) – Hennes – 2013-04-10T11:22:29.837

1Have you looked into using the locations option in Network Preferences? – Bert – 2013-04-10T12:23:05.733

Answers

1

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.

Gordon Davisson

Posted 2013-04-10T11:19:15.493

Reputation: 28 538

Thank you! i almost couldn't find the location dropdown menu haha ;) – ghaschel – 2013-04-11T11:34:28.710