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?
Asked
Active
Viewed 1.4e+01k times
129
-
1I 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
-
If with the Linux community you mean the OSS community, they did they part with `iproute2mac` and the `iproute2` itself. The issue is that other Unix vendors don't even try to adopt it. Reasons they may have, but it is on their side. – carpinchosaurio Sep 07 '22 at 19:39
4 Answers
178
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
Sanghyun Lee
- 300
- 2
- 11
slm
- 9,959
- 10
- 49
- 57
10
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.)
Hennes
- 64,768
- 7
- 111
- 168
-
How I could install this ip command on Mac OS? I want some feature like add MAC-VLAN! – Aryan Dec 12 '13 at 08: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
-
2Also, ifconfig is deprecated: https://www.google.de/search?q=ifconfig+deprecated&oq=ifconfig+deprecated&aqs=chrome..69i57j69i60j69i59j69i61j69i60l2.5817j0j7&sourceid=chrome&ie=UTF-8 – oleiade Apr 02 '16 at 07: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
Andrei Sura
- 217
- 2
- 4
-
3This is the equvalent of `ip address show`, not `ip link` and its subcommands, which the OP asked for… – Raphael Schweikert Aug 05 '20 at 11:28
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}'"
Loke
- 1