18

I am familiar with the route add default gw command in Linux to add a default gateway, but this doesnt work on Mac OS. I cant find any appropriate example in the route manual. Can anyone help me the command.

1
  • 1
    Or how to make the IP address of one interface the default gateway?
    – SThomas
    Jul 21, 2011 at 22:10

3 Answers 3

26
$ route delete default
$ route add default 192.168.0.1

or

$ route change default -interface $INTF
$ route change 192.168.0.0/16 -interface $INTF
2
  • is it possible to bind a route to a network environment ?
    – rwenz3l
    Nov 28, 2014 at 12:23
  • Can this also be reset to default afterwards?
    – lony
    Jan 3, 2019 at 16:59
12

Go to System Preference >> Network, and you can "Set Service Order" of the network interfaces and effectively change the default route order in the routing table.

change default route ordering

1
  • Man, you are the best! That exactly I need :)
    – skivan
    Jun 15, 2021 at 19:29
3

If you are intent on using route the man page for route will show you it's the same as most BSD route commands. You may need ip6config (and man page) as well if you care about IPv6 routing.

The "mac" way is to set it from the System Preference pane under network and is preferred over using unix commands since it honors location changes and other events such as a reboot.

manual TCP/IP configuration

4
  • But in that very screenshot, you will get an error message if you press "OK" since this method also require you to set a manual IPv4 Address, which might not be desirable.
    – Fuzzy76
    Apr 14, 2015 at 12:28
  • @Fuzzy76 Yes - if you manually set an unworkable network, your network will not work. The Router here is fine though since that is the default gateway equivalent to the answer on how to change things from the command line.
    – bmike
    Apr 14, 2015 at 13:16
  • What if you have multiple routes? Eg one straight to the internet and one via a VPN - How would you tell it to route all traffic over the VPN?
    – Basic
    Jun 20, 2016 at 13:24
  • @Basic Set the VPN interface to be the default route. Then traffic to subnets that have other interfaces will still go elsewhere, but by default - everything else goes to the VPN. If you need everything to be VPN, disable the other network interfaces.
    – bmike
    Jun 20, 2016 at 13:39

You must log in to answer this question.