15

For every new session in OS X terminal, I have to make my proxy settings again. I do this by entering the command

export http_proxy="username:password@ip address:port number"

Is there a way to make these proxy settings once for all?

bmike
  • 226,393
  • 78
  • 398
  • 871
curio17
  • 253
  • 1
  • 2
  • 5

3 Answers3

20

Your http proxy (just for some web sites not https ones and not for the rest of the internet) can be set for each terminal session by adding the line

export http_proxy="username:password@ip address:port number"

to your ~/.bash_profile file if using bash (the default from Panther to Mojave) or for later macOS the default shell is zsh and the file to use is ~/.zshrc

Note this will only affect command line programs.

mmmmmm
  • 28,660
  • 17
  • 84
  • 140
14

Set system-wide HTTP proxy

To globally set an http proxy system-wide on MacOS (not just for a terminal session) you can use:

networksetup -setwebproxy wi-fi localhost 8080
networksetup -setwebproxystate wi-fi on

This assumes your network interface is called wi-fi (or Wi-Fi), and that your proxy is running on localhost on port 8080.

To disable the proxy:

networksetup -setwebproxystate wi-fi off

This is equivalent to setting the proxy via mac system settings > Network > wi-fi > Advanced > Proxies > Web proxy.

Set system-wide SOCKS5 proxy

networksetup -setsocksfirewallproxy wi-fi localhost 1080
networksetup -setsocksfirewallproxystate wi-fi on

To disable the socks proxy use:

networksetup -setsocksfirewallproxystate wi-fi off

Getting the correct network interface name

All the commands above assume your netowork interface is wi-fi. If you are connected via ethernet then most likely the interface will be en<SOME_NUMBER> e.g. en0 and you'll need to use that instead of wi-fi.

To find the active network interface see what comes as the first non-disabled interface when you type:

networksetup -listnetworkserviceorder

Alternatively, you can use ifconfig or networksetup -listallhardwareports. See more.

If you need a GUI wrapper for setting the HTTP/SOCKS/PAC proxies then check out this answer. The bitbar script linked in the answer also contains the commands for setting a SOCK5 or PAC proxy. Update: Bitbar has been renamed to xbar — it's an open-source GUI for text-mode scripts written in bash/applescript/node/golang/etc.

ccpizza
  • 2,573
  • 3
  • 33
  • 36
-1

I'm assuming you mean aliases, not proxys.

Add it to ~/.bashrc and ~/.bash_profile. See this guide for more depth. I don't believe OS X supports a ~/.bash_aliases file.

JMY1000
  • 5,009
  • 2
  • 18
  • 31
  • 1
    No bash directly supports ~/.bash_aliases you call it from ~/.bashrc (which you probably should call from ~..bash_profile as well) – mmmmmm Feb 08 '16 at 01:27
  • @Mark Fair, but (to my limited knowledge) some systems do so automagically which makes it easy. – JMY1000 Feb 08 '16 at 03:36