Skip to content

Instantly share code, notes, and snippets.

@williamcaban
Last active May 28, 2022 12:53
Show Gist options
  • Save williamcaban/15aae8493208975228b0e30f68888808 to your computer and use it in GitHub Desktop.
Save williamcaban/15aae8493208975228b0e30f68888808 to your computer and use it in GitHub Desktop.

Static routes in MacOS

  • Find the name of the network adapters
# List network interface name
networksetup -listallnetworkservices

An asterisk (*) denotes that a network service is disabled.
USB 10/100/1000 LAN
Wi-Fi
Thunderbolt Bridge

# List network interface name with number
networksetup -listnetworkserviceorder

An asterisk (*) denotes that a network service is disabled.
(1) USB 10/100/1000 LAN
(Hardware Port: USB 10/100/1000 LAN, Device: en7)

(2) Wi-Fi
(Hardware Port: Wi-Fi, Device: en0)

(3) Thunderbolt Bridge
(Hardware Port: Thunderbolt Bridge, Device: bridge0)
  • Add permanent route
# usage
networksetup -setadditionalroutes <networkservice> [ <dest> <mask> <gateway> ]

# adding network route 198.18.0.0/16 with gateway 192.168.1.130
networksetup -setadditionalroutes "Wi-Fi" 198.18.0.0 255.255.0.0 192.168.1.130

# validating the route is installed
netstat -rn | grep 198.18.0.0
198.18.0/16        192.168.1.130      UGSc              en0
  • Remove permanent route
# To remove permanent route
sudo networksetup -setadditionalroutes <interface-name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment