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?
4 Answers
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
######################################################################## 100.0%
🍺 /usr/local/Cellar/iproute2mac/1.0.3: 4 files, 24K, built in 2 secondsUsage
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:
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 en0Show 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: inactiveReferences
0Use 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.)
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 1 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}'"