Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Windows 10 / Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

March 16, 2024 Active DirectoryWindows 10Windows 11Windows Server 2019

Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

The WPAD (Web Proxy Auto-Discovery) protocol allows you to easily configure the proxy settings on the clients in your network. The idea behind WPAD is that a client can use DHCP and/or DNS to find a web server on your network that has a PAC configuration file with proxy settings (http://yourdomain/wpad.dat).

Contents:
  • Create Proxy Auto-Discovery File (wpad.dat)
  • Configuring WPAD Records in DHCP or DNS
  • How to Configure Browsers for WPAD

Create Proxy Auto-Discovery File (wpad.dat)

A special PAC (Proxy Auto Configuration) file describes the rules for using a proxy. The PAC file predefined name is wpad.dat. This file contains rules that determine whether the client must use a proxy server when connecting to a specific resource (HTTP, HTTPS, or FTP) or access it directly.

Javascript syntax is used in the wpad.dat file. You can set a default proxy server address, as well as different exceptions and rules for when a client should (or should not) use a proxy for connections.

Let’s look at a simple example of wpad.dat syntax:

function FindProxyForURL(url, host)
{
   if (shExpMatch(host, "127.0.0.1" )) {return "DIRECT";}
   if (shExpMatch(host, "*/localhost*" )) {return "DIRECT";}
   if (isInNet(host, "192.0.0.0", "255.0.0.0")) {return "DIRECT";}
   if (isInNet(host, "10.0.0.0", "255.0.0.0")) {return "DIRECT";}
   // Dedicated proxy for a specific IP network
   if (isInNet(myIpAddress(), "172.15.1.0", "255.255.255.0"))
   {return "PROXY prx2.woshub.com:8080";}
   if (dnsDomainIs(host, "*.corp.woshub.com")) {return "DIRECT";}
   // Local addresses to be accessed directly
   if (
    shExpMatch(url,"http://*.woshub.com") ||
    shExpMatch(url,"https://*.woshub.com") ||
    shExpMatch(url,"ftp://*.woshub.com")
    )
   return "DIRECT";
   // If the URL does not contain dots in the address, the client should access it directly.
   if (isPlainHostName(host)) {return "DIRECT";}
   if (shExpMatch(host,"bank.example.com")) {return "DIRECT";}
   // Use a separate proxy server to access a specific wildcard domain
   if (shExpMatch(url,"*.microsoft.com*")){return "PROXY prx2.woshub.com:8080";}
   //a default proxy server address
   return "PROXY proxy.woshub.com:3128";
}

Wpad.dat - proxy Auto-Configuration (PAC) file syntax

A PAC file typically consists of a single FindProxyForURL function that returns the proxy address to the client based on the requested URL. In this case, the return “DIRECT” directive indicates that a direct connection (without a proxy) should be used to access these IP addresses and domains. If the website a client is accessing doesn’t match any of the rules in the WPAD file, the default proxy server (PROXY proxy.woshub.com:3128) is used to access it.

You can use any of the popular proxy servers such as squid or 3proxy.

You can use the PAC file as a simple means of content filtering to deny access to certain websites or to prevent access to domains with advertisements.

proxy_empty = "PROXY 127.0.0.1:3128"; // a link to an non-existing proxy
if ( shExpMatch(url,"*://twitter.com/*")) { return proxy_empty; }
if ( shExpMatch(url,"*://spam.*")) { return proxy_empty; }
if ( shExpMatch(url,"*doubleclick.net/*")) { return proxy_empty; }

Different OS versions have restrictions on the maximum size of the PAC file. For Windows, the size of the wpad.dat file should not exceed 1 MB.

Put wpad.dat on an HTTP web server in your local network and allow all users to read it. You can use a Linux-based (nginx, apache, lighttpd) or Windows-based (IIS or a simple HTTP server based on PowerShell) web server.

In this example, I will publish wpad.dat on an IIS web server on a domain controller. Copy wpad.dat to C:\inetpub\wwwroot.

If there are non-domain clients on your network, grant IUSR and IIS APPPOOL\DefaultAppPool read-only permissions on the IIS folder.

Open the IIS Manager (inetmgr), select MIME Types in the IIS website settings, and add a new type:

  • File name extension: .dat
  • MIME type: application/x-ns-proxy-autoconfig

wpad.dat on IIS web server

Restart IIS.

Configuring WPAD Records in DHCP or DNS

Now you need to configure DHCP servers or DNS records for clients to discover the PAC file.

If you use a DHCP server, you can set a WPAD address for clients using option 252. In this example for DHCP running on Windows Server:

  1. Open the DHCP console (dhcpmgmt.msc), click the IPv4 section, and select Set Predefined Options;
  2. Click Add and add an entry with the following options:
    Name: WPAD
    Data type: string
    Code: 252
  3. Click OK and specify the address of your WPAD host (http://wpad.woshub.com). Add 252 WPAD option on DHCP server
  4. Then open the Scope Options and enable the 252 WPAD option for it (or configure the setting in the Server Options section). Configuring WPAD adress on DHCP (option 252)

Then create A or CNAME DNS records for wpad name in your domain.

If you are using Active Directory, note that by default the Microsoft DNS server blocks the use of wpad and isatap names. You can check this by running the command::

dnscmd mun-dc02 /info /globalqueryblocklist

Removing WPAD from Windows DNS block list

To allow these names to be used in DNS, run this command:

dnscmd mun-dc02 /config /enableglobalqueryblocklist 0

You can clear the list:

dnscmd /config /globalqueryblocklist

And add a record for isatap:

dnscmd /config /globalqueryblocklist isatap

Make the same changes to all DNS servers.

Then create an A record with the name wpad that points to your web server where the WPAD file is located. You can create an A record manually in the DNS Manager (dnsmgmt.msc) or by using the Add-DnsServerResourceRecordA PowerShell cmdlet:

Add-DnsServerResourceRecordA -Name wpad -IPv4Address 192.168.13.10 -ZoneName woshub.loc -TimeToLive 01:00:00

Creating a WPAD entry in DNS on Windows Server AD

How to Configure Browsers for WPAD

Now you need to configure your browsers to automatically receive a PAC file on startup. To do it, enable the Automatic Detect Settings option (Tools > Internet Options > Connections > LAN Settings) in the IE settings or in the Windows proxy settings in the Settings (MS-Settings quick URI command: ms-settings:network-proxy).

Windows: enable WPAD with Automatic Detect Settings option in Internet Options

You can enable this option centrally using the Group Policy option User Configuration -> Preferences -> Control Panel Settings -> Internet Settings –> New ->Internet Explorer 10.

Enable Web Proxy Autodiscovery Protocol (WPAD) via GPO

Learn more about how to configure proxy server settings using GPO.

Now the browsers on the client devices will look for a wpad entry in the DNS (or get it from DHCP) when they are loaded. If a host with WPAD is discovered in the network, a client will download file http://wpad.%domain%/wpad.dat, run the JavaScript code, and apply the proxy-server rules from the PAC file.

For example, Windows searches the wpad name in DNS first, then through Link-Local Multicast Name Resolution (LLMNR), and after that using NetBIOS (NBNS). If LLMNR and NetBIOS protocols are disabled, only DNS search is used.

You can check whether the browser uses the PAC file when accessing the Internet (for Chromium-based web browsers: Google Chrome, Opera, Microsoft Edge):

  1. Open a browser and go to chrome://net-export/
  2. Select Strip private information and click Start Logging to Disk;enable browser logging
  3. Then specify the JSON file name to save data;
  4. Click Stop Logging;
  5. Open your JSON file in any text editor and search for proxySettings. In this example, you can see that the browser is using the proxy settings from wpad.dat:
    "proxySettings":{"effective":{"pac_url":"http://wpad/wpad.dat"},"original":{"auto_detect":true,"from_system":true}}

check if browser uses wpad

If you want to deny the use of WPAD on a Windows computer, create a DWORD parameter called DisableWpad with a value of 1 in the registry key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp\.

Configuring proxy settings using the WPAD (PAC) file provides additional flexibility that cannot be achieved by setting the proxy through the Windows GPO. WPAD is also supported on Windows, Linux, MacOS, and other operating systems as well as mobile devices.

0 comment
3
Facebook Twitter Google + Pinterest
previous post
Send Emails with Microsoft Graph API and PowerShell
next post
Removing Azure Arc Setup Feature on Windows Server 2022

Related Reading

Configure NTP Time Source for Active Directory Domain

May 6, 2025

How to Cancel Windows Update Pending Restart Loop

May 6, 2025

View Windows Update History with PowerShell (CMD)

April 30, 2025

Change BIOS from Legacy to UEFI without Reinstalling...

April 21, 2025

Remove ‘Your License isn’t Genuine’ Banner in MS...

April 21, 2025

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMware
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025
  • How to Write Logs to the Windows Event Viewer from PowerShell/CMD

    March 3, 2025
  • How to Hide (Block) a Specific Windows Update

    February 25, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Configure Google Chrome Settings with Group Policy
  • Allow Non-admin Users RDP Access to Windows Server
  • How to Find the Source of Account Lockouts in Active Directory
  • How to Disable or Enable USB Drives in Windows using Group Policy
  • Get-ADComputer: Find Computer Properties in Active Directory with PowerShell
  • Adding Domain Users to the Local Administrators Group in Windows
  • Configure Windows LAPS (Local Administrator Passwords Solution) in AD
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top