在linux系统上ip命令很常用,但是在Mac系统上并没有这个命令,我们可以安装 iproute2mac 使用类似ip功能的命令。官方介绍:
iproute2mac
CLI wrapper for basic network utilities on Mac OS X inspired with iproute2 on Linux systems - ip and bridge commands.
Provided functionality is limited and command output is not fully compatible with iproute2.
Goal of this project is to make basic network configuration/debug tasks on Mac OS X easy for admins who already use Linux systems.
For advanced usage use netstat, ifconfig, ndp, arp, route and networksetup directly.
Installation
A) Using Homebrew:
# [Optional] Install Homebrew first - see http://brew.sh for more options $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # Install iproute2mac $ brew install iproute2mac
B) Manual installation:
$ curl --remote-name -L https://github.com/brona/iproute2mac/raw/master/src/ip.py $ curl --remote-name -L https://github.com/brona/iproute2mac/raw/master/src/bridge.py $ chmod +x ip.py bridge.py $ mv ip.py /usr/local/bin/ip $ mv bridge.py /usr/local/bin/bridge
Supported commands / Example usage
Goal of this utility is to provide compatible CLI with iproute2, supporting same command shortcuts and user experience.
Help
ip helpip link helpip addr helpip route helpip neigh helpbridge helpbridge link helpLink module (Interfaces)
List local interfaces
ip linkShow one interface
ip link show en0Shutdown interface
ip link set dev en0 downStart interface
ip link set dev en0 upSet custom MAC address
ip link set dev en0 address 00:12:34:45:78:90Set Random MAC address
ip link set en0 address randomSet Factory default MAC address
ip link set en0 address factorySet MTU
ip link set dev en0 mtu 9000Neighbour module (ARP/NDP)
Show all neighbours
ip neighShow all IPv4 (ARP) neighbours
ip -4 neighShow all IPv6 (NDP) neighbours
ip -6 neighShow all IPv4 (ARP) neighbours for a specific interface
ip -4 neigh show dev en0Show neighbours filtered by prefix
ip -4 neigh show 192.0.2.0/24IPv6 (NDP) neighbours cannot be currently shown for a specific interface
Flush all neighbours (IPv4 + IPv6) for a specific interface
ip neigh flush dev en0Flush all IPv4 (ARP) neighbours for a specific interface
ip -4 neigh flush dev en0IPv6 (NDP) neighbours are being flushed for all interfaces
Address module
List all addresses
ip addrList IPv4 addresses
ip -4 addrList IPv6 addresses
ip -6 addrAdd address to interface
ip addr add 10.0.0.5/24 dev en0Remove address to interface
ip addr del 10.0.0.5 dev en0Route module
List IPv4 addresses
ip routeList IPv6 addresses
ip -6 routeFlush route cache (no-op on MacOS)
ip route flush cacheFlush routes
ip route flush table mainGet route for destination
ip route get 8.8.8.8Add static route
ip route add 192.168.0.0/16 nexthop 10.0.0.1Add default route
ip route add default nexthop 10.0.0.1Replace static route
ip route replace 192.0.2.0/24 dev utun1Remove static route
ip route del 192.168.0.0/16Bridge module
List bridge interfaces
bridge linkList one bridged interface
bridge link show dev en2JSON output
List interfaces:
ip -j link showList addresses:
ip -j addr showList neighbours:
ip -j neigh showList routes:
ip -j route showList bridges (whith pretty print):
bridge -j -p link show
使用:
> ip -h
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
where OBJECT := { link | addr | route | neigh }
OPTIONS := { -V[ersion] |
-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.
> ip route
default via 192.168.31.1 dev en0
127.0.0.0/8 via 127.0.0.1 dev lo0
127.0.0.1/32 via 127.0.0.1 dev lo0
169.254.0.0/16 dev en0 scope link
192.168.31.0/24 dev en0 scope link
192.168.31.1/32 dev en0 scope link
192.168.31.142/32 dev en0 scope link
224.0.0.0/4 dev en0 scope link
255.255.255.255/32 dev en0 scope link
> ip -4 addr
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
inet 127.0.0.1/8 lo0
en0: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
ether 68:xx:oo:aa:25:01
inet 192.168.31.142/24 brd 192.168.31.255 en0参考:linux - ip command in Mac OS X terminal - Super User