macOS 使用 CLI 設定 SOCKS proxy

先列出有哪些網路介面可用

sam@liho ~ % networksetup -listallhardwareports

Hardware Port: Belkin USB-C LAN
Device: en1
Ethernet Address: 58:ef:68:xx:xx:xx

Hardware Port: Thunderbolt Bridge
Device: bridge0
Ethernet Address: 82:61:82:xx:xx:xx

Hardware Port: Wi-Fi
Device: en0
Ethernet Address: 8c:85:90:xx:xx:xx


VLAN Configurations
===================

然後建立好 ssh tunnel 後,用下列指令啟動 proxy 設定

sam@liho ~ % networksetup -setsocksfirewallproxy "Belkin USB-C LAN" localhost 8080

當要結束的時候可以用,下列指令終止

sam@liho ~ % networksetup -setsocksfirewallproxystate "Belkin USB-C LAN" off

下次要啟動,然後不改變設定可以用下列指令

sam@liho ~ % networksetup -setsocksfirewallproxystate "Belkin USB-C LAN" on

最後如果要清除之前的 proxy 設定值,用下列指令

sam@liho ~ % networksetup -setsocksfirewallproxy "Belkin USB-C LAN" "" ""