0

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
0

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:

  1. Use SSH's -b <ip> flag to bind SSH to your desired IP. So if your WiFi IP is 111.111.111.111, ssh as per usual with ssh -b 111.111.111.111.

  2. 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 is 222.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.

  • Of course your IPs will likely change; try this out and once it's working you can script it so that you don't have to manually input your IPs every time. I would personally write a bash script and utilize probably sed, awk, grep, ifconfig, and cut. If you're better than me on the command line, you could probably do it just with ifconfig and awk. – Harv Dec 8 '17 at 8:18
  • The iPhone USB is not above Wifi in settings. How can I do that? – Amir Amini Dec 8 '17 at 8:31
  • Click the gear icon, "set service order" and drag it above WiFi. – Harv Dec 8 '17 at 8:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .