I connect my MacBook directly to my lab environment router, which is isolated from the Internet, using an Apple Thunderbolt to Gigabit Network Adapter. At the same time I have a Wi-Fi connection to access the Internet from my laptop. In my lab environment I need to access two different internal networks 172.16.11.0/24 and 172.17.11.0/24. The IP Address of my lab environment router is 192.168.2.1 and I assign the IP address 192.168.2.9 to my Thunderbolt Adapter without a router defined.
If I set the IP address of my router, I won’t be able to surf the Internet. Because the Wi-Fi connection has a router value set my computer attempts to reach the 172.16.11.0/24 and 172.17.11.0/24 networks over the Wi-Fi adapter.
To force my computer to use the Thunderbolt Adapter to access my internal lab networks I need to add static routes. This can be done with a single command.
sudo networksetup -setadditionalroutes "Thunderbolt Ethernet" 172.16.11.0 255.255.255.0 192.168.2.1 172.17.11.0 255.255.255.0 192.168.2.1
One the routes have been added you can use the command below to check your routing table and verify that the routes have been added.
netstat -rn