76

I use the command ip link in Linux. Now I want it on Mac OS X, but the Mac OS X terminal doesn't have ip. What should I use instead?

  • I think if the Linux community wants 'ip' to replace 'ifconfig' then it would be helpful for 'ip' to be available on both Unix and Linux. – Scott Skiles Jul 18 '19 at 13:00
108

You can use brew to install iproute2mac. It's actually a Python wrapper that provides a very similar API that you'll likely find very familiar to the ip tool included with iproute2 on Linux.

Installation

$ brew install iproute2mac
==> Installing iproute2mac from brona/homebrew-iproute2mac
==> Downloading https://github.com/brona/iproute2mac/archive/v1.0.3.zip
######################################################################## 100.0%
🍺  /usr/local/Cellar/iproute2mac/1.0.3: 4 files,  24K, built in 2 seconds

Usage

Once installed you'll be given a command line tool that for all intent purposes mimics the ip command on Linux.

$ ip
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip -V
where  OBJECT := { link | addr | route | neigh }
       OPTIONS := { -4 | -6 }

iproute2mac
Homepage: https://github.com/brona/iproute2mac
This is CLI wrapper for basic network utilities on Mac OS X inspired with iproute2 on Linux systems.
Provided functionality is limited and command output is not fully compatible with iproute2.
For advanced usage use netstat, ifconfig, ndp, arp, route and networksetup directly.

Examples

Show IP addresses on interface en0.

$ ip addr show en0
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 54:46:12:fc:45:12
    inet6 fe80::3636:3bff:fecf:1294/64 scopeid 0x4
    inet 192.168.1.5/24 brd 192.168.1.255 en0

Show details about link en1.

$ ip link show en1
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    options=60<TSO4,TSO6>
    ether 72:00:08:81:d2:10
    media: autoselect <full-duplex>
    status: inactive

References

| improve this answer | |
7

Use the normal command for unix like systems: ifconfig.

(Linux also uses ifconfig, but some of the tools have newer versions. ip is one of these which one day will replace the old ifconfig.)

| improve this answer | |
  • How I could install this ip command on Mac OS? I want some feature like add MAC-VLAN! – Aryan Dec 12 '13 at 8:25
  • I am not sure you can. The whole world (well, except windows which uses ipconfig and some modern linuxes who use both ip and ifconfig) uses ifconfig. This includes OS X. I have no mac to test with, but I would look at the commands vconfig add n0 42 (configure VLAN 42 for the network interface EN0) followed by something like ifconfig en0.5 1.2.3.3 netmask 255.255.128.0 broadcast 1.2.3.255 up. – Hennes Dec 12 '13 at 18:13
  • 1
    ifconfig outputs quite many unnecessary lines. If IP is everything you need use ifconfig | grep inet instead. – Akseli Palén Nov 21 '15 at 15:09
  • Also, ifconfig is deprecated: google.de/… – oleiade Apr 2 '16 at 7:45
3

There is a simpler way without installing any tools:

$ which ifconfig
/sbin/ifconfig

$ ifconfig en0 | grep inet | grep -v inet6 | cut -d ' ' -f2
10.16.45.123
| improve this answer | |
0

There is no ip command in Mac. Get it from brew or use:

ifconfig en0| grep "inet[ ]" | awk '{print $2}'

You can create an alias in ~/.bash_profile as follows:

alias ip-addr="ifconfig en0| grep \"inet[ ]\" | awk '{print \$2}'"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.