Mac change ip address from terminal

4

3

I want to change my ip address from terminal in mac. So i used the following commands.

ifconfig en1 192.168.110.1/16
route add default 192.168.110.1

if i change the ip here. It is getting reflected in the terminal but the change is not reflected in the gui. As a result of which i am not even able to ping the gateway.

Is there some other way of changing ip address via terminal?

Julius Canute

Posted 2010-11-14T13:51:38.737

Reputation:

Answers

8

In OS X, the network interfaces are managed by configd based on the configurations defined in /Library/Preferences/SystemConfiguration/*. If you change the "live" settings with ipconfig and such, it won't show up in System Preferences, and configd is likely to overwrite them back to what it thinks the settings should be. So, rather than changing the live config, you should change the system settings and let configd apply the change. The simplest way to do this is with the networksetup command:

networksetup -setmanual "Ethernet" 192.168.110.1 255.255.0.0 192.168.110.1

Note that you need to specify the interface to configure by its service name (the one System Preferences shows; "Ethernet" in my example) rather than the unix device name (e.g. "en0"). Also, networksetup doesn't seem to understand CIDR notation ("/16"), so you need to give the full subnet mask.

Gordon Davisson

Posted 2010-11-14T13:51:38.737

Reputation: 28 538

4

sudo ifconfig en1 inet <desired IP address>

rubayeet

Posted 2010-11-14T13:51:38.737

Reputation: 141