Posted by 西维蜀黍 on 2022-02-23, Last Modified on 2022-04-11


Alternative ip

$ brew install iproute2mac
$ ip link show
$ ip -s link 


List Devices with the Interface Number

$ networksetup -listnetworkserviceorder
(1) Ethernet
(Hardware Port: Ethernet, Device: en0)

(2) USB 10/100/1000 LAN
(Hardware Port: USB 10/100/1000 LAN, Device: en5)

(3) Wi-Fi
(Hardware Port: Wi-Fi, Device: en2)

(4) Bluetooth PAN
(Hardware Port: Bluetooth PAN, Device: en3)


View The Routing Table

$ netstat -nr
Routing tables


Destination     Gateway        Flags      Refs     Use     Netif Expire
default       UGSc       36       65      jnc0
default    UGScI      20       0       en1


Add a Static Route Temporarily

$ sudo route -n add -net

# A destination of default is a synonym for -net, which is the default route.

$ sudo route -v add -net -interface en0

# Run in test mode (does not do anything, just print):
$ sudo route -t add "destination_ip_address/24" "gateway_address"

To verify the route you added:

$ netstat -rn | grep 192.168.2.
192.168.2 UGSc en10
192.168.2/23 UGSc utun3

Run in test mode (does not do anything, just print):

$ sudo route -t add "destination_ip_address/24" "gateway_address"

Add a Static Route Permanently

$ networksetup -setadditionalroutes <networkservice> [ <dest> <mask> <gateway> ]*

// e.g.,
$ sudo networksetup -setadditionalroutes "USB 10/100/1000 LAN"

$ sudo networksetup -setadditionalroutes "Ethernet"

# route to direct to the interface
$ sudo networksetup -setadditionalroutes "Ethernet" ""

Delete Routes

# Delete a Static Route
$ sudo route -n delete

# Remove all routes:
$ sudo route flush


# Lookup and display the route for a destination (hostname or IP address):
$ sudo route get "destination"


Set Static IP

Set the TCP/IP configuration for network service to manual with IP address set to ip, Subnet Mask set to subnet, and Router address set to router. For example:

$ networksetup -setmanual "Ethernet"


Sets the TCP/IP configuration for the specified network service to use DHCP. The client ID is optional. Specify “Empty” for [clientid] to clear the DHCP client id. For example:

$ networksetup -setdhcp "Ethernet"



Specifies the IP addresses of servers you want the specified network service to use to resolve domain names. You can list any number of servers (replace dns1, dns2, and so on with the IP addresses of domain name servers). If you want to clear all DNS entries for the specified network service, type “empty” in place of the DNS server names.

$ networksetup -setdnsservers <networkservice> <dns1> [dns2]

$ networksetup -setdnsservers "Ethernet"



$ arp -nla
Neighbor                Linklayer Address Expire(O) Expire(I)    Netif Refs Prbs         (incomplete)      (none)    (none)         en8             88:c3:97:9b:51:60 1m36s     1m29s          en8    1           0:e0:4c:6a:56:1b  (none)    (none)         en8           8c:85:90:24:c7:dd 2m15s     2m16s          en8    1           ff:ff:ff:ff:ff:ff (none)    (none)         en8             1:0:5e:0:0:fb     (none)    (none)         en8         1:0:5e:7f:ff:fa   (none)    (none)         en0         1:0:5e:7f:ff:fa   (none)    (none)         en8


$ nettop