Skip to content

Instantly share code, notes, and snippets.

@refo
Last active January 23, 2023 17:05
Show Gist options
  • Save refo/1a5ce2e87200ed85064a76bb7760e69c to your computer and use it in GitHub Desktop.
Save refo/1a5ce2e87200ed85064a76bb7760e69c to your computer and use it in GitHub Desktop.
macOS proxy settings from terminal

macOS firewall settings

Set socks proxy

networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 7070

Get current socks proxy settings and state

networksetup -getsocksfirewallproxy Wi-Fi
Enabled: Yes
Server: 127.0.0.1
Port: 7070
Authenticated Proxy Enabled: 0

Set socks proxy state (enable/disable)

networksetup -setsocksfirewallproxystate Wi-Fi on
networksetup -setsocksfirewallproxystate Wi-Fi off
echo "Enabling proxy"
# Set macOS socks proxy to local proxy
networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 7070
# enable macOS socks proxy
networksetup -setsocksfirewallproxystate Wi-Fi on
# create a local socks proxy to remote host
ssh -D 7070 -NCq foo@remote.host
# proxy stays open until termination
echo ""
echo "Disabling proxy"
# disable macOS socks proxy upon closing the connection
networksetup -setsocksfirewallproxystate Wi-Fi off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment