I have a Macbook Pro running macOS Sierra 10.12.6
I'm using Wifi to connect to a server using SSH. My iPhone is also connected to my laptop and both Wifi and iPhone USB have the green circle next to them in Network settings. How can I configure my network so that it uses my iPhone USB for Internet and Wifi for SSH?
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 34:36:3b:ce:3e:88
inet 192.168.1.247 netmask 0xffffff00 broadcast 192.168.1.255
media: autoselect
status: active
en4: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 22:3c:ae:94:e7:84
inet6 fe80::18a5:b2ff:226e:8492%en4 prefixlen 64 secured scopeid 0xf.
inet 172.20.10.7 netmask 0xfffffff0 broadcast 172.20.10.15
nd6 options=201<PERFORMNUD,DAD>
media: 100baseTX <full-duplex>
status: active
Best Answer
There are at least two ways! First make sure that the iPhone is above WiFi in the network service order; that makes it the default for all traffic. Then you can either:
Use SSH's
-b <ip>
flag to bind SSH to your desired IP. So if your WiFi IP is111.111.111.111
, ssh as per usual withssh -b 111.111.111.111
.Add a static route to your remote host routing through the desired IP. If your desired IP to connect from is
111.111.111.111
and your remote host is222.222.222.222
:$ sudo route add 222.222.222.222 111.111.111.111
. then SSH normally. When you're done, tear down the route with$ sudo route delete 222.222.222.222 111.111.111.111
.