Reputation: 1443
We can see default gateway and interface of MAC by using following command
route -n get default
I know that this is possible in linux and can be achieved by following commands
route change default -interface $INTF
route change 192.168.0.0/16 -interface $INTF
But these are not working in MAC. My objective is to change the Default Gateway and interface.
Upvotes: 1
Views: 8867
Reputation: 1
I recently had an instance where someone setup dual default routes
grant@dd08-mac:~[20220909-15:59][#8625]% netstat -rn
Routing tables
Internet:
Destination Gateway Flags Netif Expire
default 10.17.124.1 UGScg en0
default 10.1.78.1 UGScIg bridge0
10.1.78/24 link#16 UCS bridge0 !
10.1.78.1/32 link#16 UCS bridge0 !
10.1.78.1 link#16 UHLWIir bridge0 !
10.1.78.24 link#16 UHLWI bridge0 !
10.1.78.58/32 link#16 UCS bridge0 !
10.1.78.58 36.6a.e9.47.a5.80 UHLWIi lo0
10.1.78.255 ff.ff.ff.ff.ff.ff UHLWbI bridge0 !
-snip-
I reset the interface with networksetup - this deleted the extra route
grant@dd08-mac:~[20220909-16:04][#8885]% sudo networksetup -setmanual Ethernet 10.17.124.78 255.255.255.0 0.0.0.0
Password:
grant@dd08-mac:~[20220909-16:11][#8924]
and the extra route is gone
grant@dd08-mac:~[20220909-16:11][#8964]% netstat -rn
Routing tables
Internet:
Destination Gateway Flags Netif Expire
default 10.1.78.1 UGScg bridge0
10.1.78/24 link#16 UCS bridge0 !
10.1.78.1/32 link#16 UCS bridge0 !
10.1.78.1 link#16 UHRLWIir bridge0 19
10.1.78.58/32 link#16 UCS bridge0 !
10.1.78.58 36.6a.e9.47.a5.80 UHLWIi lo0
10.17.124/24 link#9 UCS en0 !
10.17.124.5 0:25:90:55:6d:e3 UHLWIi en0 1191
10.17.124.78/32 link#9 UCS en0 !
-snip-
Upvotes: 0
Reputation: 3698
The networksetup
utility should be able to do what you want.
For example, to manually set up the standard Ethernet interface with an IP of 192.168.100.100
, subnet of 255.255.255.0
and gateway of 192.168.100.1
:
networksetup -setmanual "Ethernet" 192.168.100.100 255.255.255.0 192.168.100.1
You might also be interested in the -setadditionalroutes
flag.
Upvotes: 2