Skip to content

Instantly share code, notes, and snippets.

@signed-log
Created February 11, 2023 17:09
Show Gist options
  • Save signed-log/2568d978b325586b913f215745a1e65f to your computer and use it in GitHub Desktop.
Save signed-log/2568d978b325586b913f215745a1e65f to your computer and use it in GitHub Desktop.
[NetworkManager] Assign proxy to a specific wifi network

Assign proxy to a specific wifi network

Step 1.

Have connected at least once to the WiFi network... obviously

Step 2.

Create a Proxy Auto-Config File

For a basic, send-all, but local, scenario, we'll take the following as an example :

function FindProxyForURL(url, host) {
    // Exclude localhost
    if (
        isPlainHostName(host) ||
        isInNet(dnsResolve(host), "127.0.0.0", "255.255.255.0")
    )
        return "DIRECT";
    else return "PROXY 123.123.123.123:8080";
}

Save that into a known location with a file extension of .pac for better reference

Step 3:

There are two ways to tell NetworkManager about the Proxy config :

CLI

CLI

Step 4

Run :

    nmcli connection edit <wifi-network-name>

This will pop you into the NetworkManager editor shell

Step 5

We'll need to modify both the proxy.method and proxy.pac-script parameters

First, proxy.method needs to be set to auto, to allow for a PAC script

    set proxy.method auto

Step 6

Finally, proxy.pac-script need to be set

The format is file://<Absolute Path to the file>

For example : file:///home/example/example.pac (note the /// that represent an absolute path)

    set proxy.pac-script file:///home/example/example.pac

GUI

GUI

Step 4

Install nm-connection-editor if not already installed

Debian-based distros :

    sudo apt-get install network-manager-gnome

RPM distros :

    sudo <yum/dnf/zypper> install nm-connection-editor

Step 5

Open nm-connection-editor, either by the CLI, or the GUI (usually named Advanced Network Configuration)

In it, choose the wifi network

Step 6

  • Go to the Proxy menu
  • Put Method to Auto
  • And then select your file in Import script from file...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment