Hi all. Welcome back to the final part of the network configuration series.
In this blog I will try to provide an example script to configure all the options and to explain each line.
The end goal
The first thing you should do is sit down and work out exactly what you need to achieve. For our example we will be taking a fresh install and want the following goals:
- Replace the Automatic Network location with two new ones; Home that is unproxied and Office that will have all the proxy settings.
- The Office location should be the default for a fresh machine
- The Ethernet interface only should have the proxy setting
- The proxy server for HTTP and HTTPS is “proxy.example.com” port 8080
- There should be the standard exceptions in place (“*.local” and “169.254/16”) as well as “smtp.example.com”, “mail.example.com” and “jss.example.com”.
To achieve this, the example script will run the following in this order:
- Create a location called “Home” and auto-populate with the network interfaces
- Switch to “Home”
- Delete the “Automatic” interface
- Create a location called “Office” and auto-populate with the network interfaces
- Switch to “Office”
- Set the Ethernet HTTP proxy
- Set the Ethernet HTTPS proxy
- Set the Ethernet proxy exception
Now we have our goals and our task list, lets get scripting.
Section 1: Introduction
This first section should be used to describe what the script does and to set any variables for easy modification.
Section 3: Applying proxy settings to Ethernet
This third section is used to apply the Proxy Server settings as per goals 6 – 7:
Section 4: Applying proxy the Proxy Exceptions
This fourth section is used to apply the Proxy exception settings as per the final goal:
Section 5: Finishing up
This fifth and final section is used simply to exit the script:
Further work
There you have it, that’s the entire script. It should do the job but could also do with some additional tweaks. Off the top of my head, I can think of:
- Add a log file to leave a record of what happened.
- Introduce a lot more error checking to cover any possible variances in the client configuration and to cover any failures.
- Add a ‘for’ loop to simplify adding these settings to a list or all interfaces.
Feel free to attempt these yourself and let me know of any successes (or failures!) in the comments below.
For the complete series to date on Bash Scripting, click here