Mac OS使用ip命令

在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 netstatifconfigndparproute 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 help

    • ip link help

    • ip addr help

    • ip route help

    • ip neigh help

    • bridge help

    • bridge link help

  • Link module (Interfaces)

    • List local interfaces ip link

    • Show one interface ip link show en0

    • Shutdown interface ip link set dev en0 down

    • Start interface ip link set dev en0 up

    • Set custom MAC address ip link set dev en0 address 00:12:34:45:78:90

    • Set Random MAC address ip link set en0 address random

    • Set Factory default MAC address ip link set en0 address factory

    • Set MTU ip link set dev en0 mtu 9000

  • Neighbour module (ARP/NDP)

    • Show all neighbours ip neigh

    • Show all IPv4 (ARP) neighbours ip -4 neigh

    • Show all IPv6 (NDP) neighbours ip -6 neigh

    • Show all IPv4 (ARP) neighbours for a specific interface ip -4 neigh show dev en0

    • Show neighbours filtered by prefix ip -4 neigh show 192.0.2.0/24

    • IPv6 (NDP) neighbours cannot be currently shown for a specific interface

    • Flush all neighbours (IPv4 + IPv6) for a specific interface ip neigh flush dev en0

    • Flush all IPv4 (ARP) neighbours for a specific interface ip -4 neigh flush dev en0

    • IPv6 (NDP) neighbours are being flushed for all interfaces

  • Address module

    • List all addresses ip addr

    • List IPv4 addresses ip -4 addr

    • List IPv6 addresses ip -6 addr

    • Add address to interface ip addr add 10.0.0.5/24 dev en0

    • Remove address to interface ip addr del 10.0.0.5 dev en0

  • Route module

    • List IPv4 addresses ip route

    • List IPv6 addresses ip -6 route

    • Flush route cache (no-op on MacOS) ip route flush cache

    • Flush routes ip route flush table main

    • Get route for destination ip route get 8.8.8.8

    • Add static route ip route add 192.168.0.0/16 nexthop 10.0.0.1

    • Add default route ip route add default nexthop 10.0.0.1

    • Replace static route ip route replace 192.0.2.0/24 dev utun1

    • Remove static route ip route del 192.168.0.0/16

  • Bridge module

    • List bridge interfaces bridge link

    • List one bridged interface bridge link show dev en2

  • JSON output

    • List interfaces: ip -j link show

    • List addresses: ip -j addr show

    • List neighbours: ip -j neigh show

    • List routes: ip -j route show

    • List 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

anzhihe 安志合个人博客,版权所有 丨 如未注明,均为原创 丨 转载请注明转自:https://chegva.com/6161.html | ☆★★每天进步一点点,加油!★★☆ | 

您可能还感兴趣的文章!

发表评论

电子邮件地址不会被公开。 必填项已用*标注