When working with internal services through LAN, we have some problem that we cannot connect to the outside world which we normally connect by Wifi.
When going to internal server e.g. the ip 10.200.10.20
use LAN
Otherwise go through Wi-fi
See the interface in my machine with ifconfig
en0 Wifi
en5 LAN
We will config this behavior with route
command
Open System Preference > Network
Seeing the LAN tab.
sudo route -n add -host <target_host_ip> <gateway_ip>
// Example
sudo route -n add -host 10.200.10.20 10.175.30.40
sudo route add -host 10.200.10.20 -interface en5
OSX version of route
miss the command to see route.
It use netstat -nr
instead.
netstat -nr
...10.200.10.20 10.175.30.40 UGHS en5
...
Now when going to 10.200.10.20
it goes through correct gateway and correct interface (LAN en5
)
and for other i.e. default goes through Wifi (en0
)
default 172.24.200.1 UGSc en0
Bonus
For those with ip range, we can avoid tedious one by one adding with CIDR block range /16
, /24
etc.
sudo route -n add -net 172.16.0.0/16 192.168.1.49
Hope this help. Cheers !