Bash Scripting: Proxy Exceptions

Hi all. Welcome back to part 3 of the network configuration series.
In this blog I will advise how to apply some proxy exceptions to your network locations

Last time…

In the first blog, we created a new network location called “Home”, auto populated it with the available network interfaces, switched to it and deleted the “Automatic” location. We then created a location called “Office”.
In last month’s blog, we set the Ethernet proxy for HTTP and HTTPS to “” and the Wifi Proxy for HTTP and HTTPS to “”.
Now, let’s say that you still need to access two or three servers on the internal side of the network and these aren’t access through the proxy. Let’s set some proxy exceptions.

Adding Proxy Exceptions

The command used to add the proxy exceptions is “networksetup -setproxybypassdomains”. The man page for “networksetup” shows the following for “setproxybypassdomains”
adding proxy exceptions
The options translate to:

  • “networkservice” – This is the physical interface. For example “Wi-fi”, “Airport”, “Ethernet”, “Ethernet 2” and “Thunderbolt-Ethernet” are all valid examples.
  • “domain1” – This is the IP or DNS address that sound be added to the exception list.
  • “[domain2]” – This is the second address to add to the exception list. This is optional.
  • “[…]” – This is for any further addresses to add to the list.

Please Note: If the command is specified with no ‘bypass domains’ then it will remove all previously set proxy bypass domains.

Ethernet Exceptions

So we currently have the Ethernet Proxy set to an Amsys (fictional) proxy service but we need to add the following addresses to the exceptions list:


To set these exceptions on the Ethernet:

networksetup –setproxybypassdomains "Ethernet" "" "" "" ""

Please Note: This is all on one line with spaces between each address.

Wifi Exceptions

To set the same exceptions on Wifi, simply replace “Ethernet” with “Wi-Fi”:

networksetup –setproxybypassdomains "Wi-Fi" "" "" "" ""

Please Note: This is all on one line with spaces between each address.

Points to note

When running these commands, they work on the current network location, much like setting the actual proxy settings.
Also, as each proxy exception setting is tied to an interface, you will need to repeat your commands for each required physical or virtual interface.


I hope this mini-series provides you with all the information you require to configure network location and proxy settings from the command line, and then allow you to script them.
If you are still unsure on how to add these to a script, tune in next time where I’ll take you through an example.
Any hints, tips or opinions? Let us know in the comments below and I’ll try to respond to as many as I can.