Assume that you want to set 127.0.0.1:10809 as HTTP proxy and 127.0.0.1:10808 as SOCKS proxy.
How to set a proxy for CMD/Powershell/Terminal/Git
CMD / PowerShell Using netsh
Configure the proxy server manually using netsh command
Tunnel all your internet traffic through a HTTP proxy
netsh winhttp set proxy 127.0.0.1:10809 bypass-list="localhost"
Tunnel all your internet traffic through a SOCKS proxy
netsh winhttp set proxy proxy-server="socks=127.0.0.1:10808" bypass-list="localhost"
View the current proxy settings:
netsh winhttp show proxy
Clear all proxy settings:
netsh winhttp reset proxy
CMD / PowerShell Using Env. Variables
Set
set http_proxy=http://127.0.0.1:10809
set https_proxy=http://127.0.0.1:10809
Unset
set http_proxy=
set https_proxy=
To delete variables for future cmd instances, do this:
setx http_proxy ""
setx https_proxy ""
PowerShell Using Env. Variables
$env:HTTPS_PROXY="http://127.0.0.1:10809"
$env:HTTP_PROXY="http://127.0.0.1:10809"
$env:all_proxy="socks5://127.0.0.1:10808"
Bash
export https_proxy=http://127.0.0.1:10809
export http_proxy=http://127.0.0.1:10809
export all_proxy=socks5://127.0.0.1:10808
Git
Set
git config --global http.proxy http://127.0.0.1:10809
git config --global https.proxy http://127.0.0.1:10809
git config --global http.proxy socks5://127.0.0.1:10808
git config --global https.proxy socks5://127.0.0.1:10808
Show
git config --get --global http.proxy
git config --get --global https.proxy
git config --get --global http.proxy socks5
git config --get --global https.proxy socks5
Unset
git config --global --unset http.proxy
git config --global --unset https.proxy
git config --global --unset http.proxy socks5
git config --global --unset https.proxy socks5
- Set proxy through windows command line including login parameters
- Set HTTP(s) Proxy in Windows Command Line / Mac Terminal
- Enable and Configure proxy using CMD
- Configuring proxy from CMD (Windows)
- Configure device proxy and Internet connectivity settings
- Windows: Show Proxy Settings – CMD & PowerShell
- Using the WinHTTP Proxy Configuration Utility
- Remove proxy settings from the windows command prompt
Set proxy through windows command line including login parameters
Once the variable HTTP_PROXY is set, all our subsequent commands executed at
windows command prompt will be able to access internet through the proxy along
with the authentication provided. Additionally if you want to use ftp and
https as well to use the same proxy then you may like to the following
environment variables as well.
netsh winhttp set proxy SERVER:PORT
netsh winhttp set proxy user:[email protected]:PORT
set HTTP_PROXY=http://proxy_userid:[email protected]_ip:proxy_port
set FTP_PROXY=%HTTP_PROXY%
set HTTPS_PROXY=%HTTP_PROXY%
netsh winhttp set proxy proxy-server="socks=localhost:9090" bypass-list="localhost"
netsh winhttp show proxy
netsh winhttp reset proxy
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d name:port
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyUser /t REG_SZ /d username
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyPass /t REG_SZ /d password
netsh winhttp import proxy source=ie
Set HTTP(s) Proxy in Windows Command Line / Mac Terminal
Windows Command Line. In Windows Command Line environment (NOT powershell),
you can use below commands to set http and https proxy. set
http_proxy=protocol://ip:port set https_proxy=protocol://ip:port. For example,
if you have a local socks 5 proxy (such as ShadowSocks), commands will be as
below.
set http_proxy=protocol://ip:port
set https_proxy=protocol://ip:port
set http_proxy=socks5://127.0.0.1:1086
set https_proxy=socks5://127.0.0.1:1086
echo %http_proxy%
echo %https_proxy%
set http_proxy=
set https_proxy=
export http_proxy=socks5://127.0.0.1:1086 # Set HTTP Proxy
export https_proxy=socks5://127.0.0.1:1086 # Set HTTPS Proxy
export all_proxy=socks5://127.0.0.1:1086 # Set HTTP & HTTPS Proxy
unset http_proxy
unset https_proxy
Enable and Configure proxy using CMD
On Windows, one can modify the network settings via commandline by using the
netsh command. For example, changing the proxy works as follows: netsh winhttp
set proxy myproxy or in your scenario: netsh winhttp set proxy
10.10.10.10:1111 Have a look at the detailed documentation here, and at this
superuser thread
netsh winhttp set proxy myproxy
netsh winhttp set proxy 10.10.10.10:1111
Configuring proxy from CMD (Windows)
If you need to access the proxy low level configuration, you will need to use
a CMD Window as Local Administrator and use the netsh interface and use the
following: 1 2 3. netsh winhttp show proxy — to show the current
confiuguration netsh winhttp reset proxy — to delete the current settings
netsh winhttp set proxy <proxyName>:<port> — to set a
1
2
3
netsh winhttp show proxy - to show the current confiuguration
netsh winhttp reset proxy - to delete the current settings
netsh winhttp set proxy <proxyName>:<port> - to set a new configuration
1
2
set HTTP_PROXY=http://[username:[email protected]]proxyserver:port
set HTTPS_PROXY=https://[username:[email protected]]proxyserver:port
Configure device proxy and Internet connectivity settings
Right-click Command prompt and select Run as administrator. Enter the
following command and press Enter: netsh winhttp set proxy <proxy>:<port> For
example: netsh winhttp set proxy 10.0.0.6:8080. To reset the winhttp proxy,
enter the following command and press Enter: netsh winhttp reset proxy
<server name or ip>:<port>
For example: http://10.0.0.6:8080
netsh winhttp set proxy <proxy>:<port>
netsh winhttp reset proxy
HardDrivePath\MDEClientAnalyzer.cmd
C:\Work\tools\MDEClientAnalyzer\MDEClientAnalyzer.cmd
Testing URL : https://xxx.microsoft.com/xxx
1 - Default proxy: Succeeded (200)
2 - Proxy auto discovery (WPAD): Succeeded (200)
3 - Proxy disabled: Succeeded (200)
4 - Named proxy: Doesn't exist
5 - Command line proxy: Doesn't exist
Windows: Show Proxy Settings – CMD & PowerShell
Proxy settings in Windows can be configured system-wide (for all users of the
same computer) or per-user. In this note i will show how to display system-
wide and user-specific proxy settings in Windows from the command-line (CMD)
and PowerShell. Cool Tip: Check if TCP port is opened in PowerShell! Read more
→. Show Proxy Settings in Windows
C:\> netsh winhttp show proxy
PS C:\> Get-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
C:\> reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Using the WinHTTP Proxy Configuration Utility
The WinHTTP proxy configuration utility, proxycfg.exe, configures WinHTTP to
access HTTP and HTTPS servers through a proxy server. Because the
ServerXMLHTTP object depends on WinHTTP proxy settings, an administrator can
use the proxycfg.exe utility as part of the deployment and installation
process of an application that uses WinHTTP.
proxycfg -d -p itgproxy "<local>"
proxycfg -p itgproxy
proxycfg -p "http=http_proxy https=https_proxy" "<local>;*.microsoft.com"
Remove proxy settings from the windows command prompt
set http_proxy= set https_proxy= From an elevated command prompt (CMD or PS)
type: netsh winhttp reset proxy. This should produce:
C:\Windows\system32>netsh winhttp reset proxy Current WinHTTP proxy settings:
Direct access (no proxy server). This command will reset your proxy settings
and as you can see by the output, they will be set to «no
set http_proxy=
set https_proxy=
npm config delete proxy http
npm config delete proxy https
Configuring an HTTP proxy for command-line tools in Windows is vital in environments with restricted internet access or strict routing policies. It ensures applications like curl and wget always funnel requests through the specified proxy, maintaining reliable connections and adhering to network rules.
Environment variables offer a direct way to set proxy configurations system-wide on Windows. Recognizing these variables allows PowerShell, Command Prompt, and other terminal-based tools to apply uniform network settings, reducing per-application overhead and minimizing errors.
Reliable proxy management remains crucial for IT professionals who handle complex enterprise environments. Consistent application of HTTP and HTTPS proxies saves time, avoids manual configuration, and contributes to an organized, policy-compliant network infrastructure.
-
Ensure a functioning HTTP proxy or server is available.
-
Open Command Prompt or PowerShell.
-
Define the HTTP proxy by setting the http_proxy environment variable with the server address and port.
# setx http_proxy http://proxyserver:8080 SUCCESS: Specified value was saved.
-
Define the HTTPS proxy by setting the https_proxy environment variable with the secure proxy server address and port.
# setx https_proxy https://proxyserver:8080 SUCCESS: Specified value was saved.
-
Verify the proxy configuration by echoing the environment variables.
# echo %http_proxy% http://proxyserver:8080
-
Test the settings using a command-line tool like curl.
# curl http://example.com [Output showing connection through proxyserver]
-
For temporary session-based proxy settings, use set instead of setx.
# set http_proxy=http://proxyserver:8080
Use setx for persistent user-level variables in Windows, and set for variables that revert after closing the session.
-
Remove proxy settings by clearing the environment variables.
# setx http_proxy "" SUCCESS: Specified value was saved. # setx https_proxy "" SUCCESS: Specified value was saved.
Restart the terminal session or log off and on again to ensure changes to environment variables take effect.
Discuss the article:
Comment
anonymously. Login not required.
Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!
We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!
Learn from Guru Rajesh Kumar and double your salary in just one year.
Get Started Now!
Setting the proxy configuration in Linux and Windows
If you use a proxy server or firewall, you may need to set the http_proxy environment variable in order to access some url from command-line.
Windows Command line
set http_proxy=http://your_proxy:your_port
set http_proxy=http://username:password@your_proxy:your_port
set https_proxy=https://your_proxy:your_port
set https_proxy=https://username:password@your_proxy:your_port
Windows GUI
1. Open the Control Panel and click the System icon.The System Properties dialog is displayed.
2. On the Advanced tab, click on Environment Variables. The Environment Variables dialog is displayed.
3. Click New in the System variables panel. The New Sytem Variable dialog is displayed.
4. Add http_proxy with the appropriate proxy information
Windows Registry
IE can set username and password proxies, so maybe setting it there and import does work
reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyEnable /t REG_DWORD /d 1
reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyServer /t REG_SZ /d name:port
reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyUser /t REG_SZ /d username
reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyPass /t REG_SZ /d password
netsh winhttp import proxy source=ie
Command to enable proxy usage:
reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyEnable /t REG_DWORD /d 1 /f
Command to disable proxy usage:
reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyEnable /t REG_DWORD /d 0 /f
Command to change the proxy address:
reg add “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v ProxyServer /t REG_SZ /d proxyserveraddress:proxyport /f
Linux
export http_proxy=http://your_proxy:your_port
export http_proxy=http://username:password@your_proxy:your_port
export https_proxy=https://your_proxy:your_port
export https_proxy=https://username:password@your_proxy:your_port
export https_proxy=https://%username%:%password%@your_proxy:your_port
FAQ
1. How to escape if password has a @ character
Ans – try %40 instead of @
2. What is the file name where it stroed the proxy in Ubantu
Ans – /etc/environment
3. How to set proxy inforamtin in Apt?
Ans – Adding following line to /etc/apt/apt.conf has solved the problem:
Acquire::http::proxy “http://10.1.3.1:8080/”;
If file does not exist, create it. Do not confuse it with apt.conf.d directory.
4. How to set proxy inforamtin in linux Profile?
5. Why manual export failed to affect apt-get with the proxy info?
Ans – The reason your manual export failed to affect apt-get is because sudo ignores that environment variable by default (i.e. it doesn’t pass it on to the command). For one-off runs, you could do sudo env http_proxy=http://10.1.3.1:8080 apt-get update. Otherwise, you could configure sudo to allow http_proxy to fall through.
Certification Courses
DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:
- DevOps Certification — Learn the fundamentals and advanced concepts of DevOps practices and tools.
- DevSecOps Certification — Master the integration of security within the DevOps workflow.
- SRE Certification — Gain expertise in Site Reliability Engineering and ensure reliability at scale.
- MLOps Certification — Dive into Machine Learning Operations and streamline ML workflows.
- AiOps Certification — Discover AI-driven operations management for next-gen IT environments.
Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.
- Setting proxy with GPO
- Windows 10 proxy settings
- Computer proxy settings
- Proxy settings for WinHTTP API
- Setting proxy using system environment variables
- Prevent user from changing browser settings
- Powershell and proxy settings
As of June 2022 Internet Explorer browser reached end of support in Windows OS, and users are advised to use Microsoft Edge in IE compatibility mode. Especially if they have legacy apps running only on IE. Many of the settings we will explain here, related to proxy, are based on usage of Internet Explorer. Despite it, we will address all aspects of configuring proxy settings even it will become “deprecated”.
I took a big byte with this one because I wanted to cover all aspects of working with proxy settings, but it wared me out to check all details. I didn’t want to copywrite things but i wanted really to check what is going on with ceratin settings and how they work. In short, I didn’t wont to give false or deprecated info, but exact and tested information. I don’t know if I succeeded. Please comment and correct me if I am wrong somewhere.
If you read part I , you realize there are two dll-s you can use for Internet access and proxying , with different capabilities. As explained WinINET is user interactive based proxy engine and it has certain capabilities that modern browsers doesn’t have. For example ftp protocol. If you type ftp address in IE you will open ftp site but if you use Microsoft Edge, you will get prompt to open another app for browsing ftp site. In next video you can see that behavior with IE as ftp app.
There is lot of ways how to configure proxy settings on your PC or server. In this article we will explain how to set proxy with GPO, registry or netsh command. Also we will explain some specific situations and bypassing it.
Setting proxy with GPO
We will start with configuring proxy settings with GPO. We will create GPO and link it to OU.
Note
In previous versions of Internet Explorer (6, 7, and 9) to configure Internet Explorer settings you needed to use the following section in the Group Policy Editor console: User configuration > Policies > Windows Settings > Internet Explorer Maintenance. In Internet Explorer 10 (firstly appeared on Windows Server 2012 and Windows
the Internet Explorer Maintenance (IEM) section was removed from GPO Editor.
After that we edit created GPO. Navigate to User Configuration > Preferences > Control Panel Settings > Internet Settings and create new Internet Explorer 10 policy (it works for IE 11 also). Navigate to Connections and go to LAN settings
Enter setting for your proxy server in picture. Check box Use a proxy server for your LAN, and then enter IP address and port. Check also Bypass proxy server for local addresses.
There is one thing that you probably noticed on picture. There are green and red lines under different settings presented. Green means that setting is on and will be applied, and red means it is disabled. To toggle this settings use function keys
- F6 – enable selected option
- F7 – disable selected option
- F5 – enable all options on selected tab
- F8 – disable all options on selected tab
Bypass proxy settings for local addresses
This is very misunderstood setting. It means if you type http://intranet in your browser it will not use proxy to access web site. Local addresses are all URLs that doesn’t have domain suffix.
Regarding bypass, if you type http://intranet.contoso.com or http://192.168.0.34 it is not local address, and browser will try to use proxy to access it. That’s why it is usual to list your local domain and local addresses in exceptions on advanced tab. Use wildcards presented on picture example.
After GPO is applied, settings are presented in IE. If you have different proxy for different branch office-s aka LAN subnets you can use Item level targeting to use different proxy settings for different subnets. (I will not go into that area, but sometimes it is necessary. For example when using wpad or pac scripts for configuring proxy you will see it is common part of script configuration. We will talk about that in separate posts)
Windows 10 introduced new modern settings Control Panel where you can set up different computer settings. But still, it is just presentation pane. If you enter manually proxy settings here, you will have new entries in registry user path we talk about in next chapter. If you use GPO, proxy settings will be presented here because it will be read from the same location in registry. You can see words in red “some settings are managed by your organization“, if GPO is applied. Just to explain Microsoft Edge is using these settings, despite it is using WinHTTP API for accessing Internet. It is that setting in browser “Use system proxy settings” you can see in Chrome, Mozilla and similar browsers.
Setting proxy -registry settings
What happens when GPO is applied? It change registry settings. If you browse to registry key on picture, you will see all the same settings you configured on GPO
It means that you can also set user proxy settings by editing/adding registry keys. For example you can run this PowerShell script and set proxy settings for user. If keys doesn’t exist, please use New-ItemProperty instead of Set-ItemProperty.
$reg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" Set-ItemProperty -Path $reg -Name ProxyEnable -Value 1 Set-ItemProperty -Path $reg -Name ProxyServer -Value "10.0.40.50:9090" Set-ItemProperty -Path $reg -Name ProxyOverride -Value '*.contoso.com;<local>' Set-ItemProperty -Path $reg -Name AutoDetect -Value 0
It is possible to create same registry settings with GPO also. Navigate to GPP section in GPO and create same registry keys from script. Location of settings is User Configuration > Preferences > Registry. Add next values to HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings registry path
- ProxyEnable (REG_DWORD) = 00000001;
- ProxyServer (REG_SZ) = 10.0.40.50:9090;
- ProxyOverride (REG_SZ) = *.contoso.com;<localhost>
Computer proxy settings
All settings we talked about are user proxy settings. If you need to setup proxy to computer object and all users logging into that computer, you need to configure two additional GPO settings. First one is Make proxy settings per-machine (rather than per user). It is located at Computer Configuration > Administrative Templates > Windows Components > Internet Explorer. When you enable this policy all users using that computer will have same proxy settings. Second setting need to override any user GPO policies it has in place. You need to enable Configure user Group Policy loopback processing mode located at Computer Configuration > Policies > Administrative Templates > System > Group Policy.
Make proxy settings per machine policy can be turned on also by registry setting . You will need to add next key on location in script.
$reg = "HKLM\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings" New-ItemProperty -Path $reg -Name ProxySettingsPerUser -Value 0
For non domain-joined computers you can also use Make proxy settings per-machine GP locally. What is interesting is that you need to setup proxy settings in that way that you run IE but Run as Administrator. After that go to internet options in IE and configure all settings needed. What happens is that from that moment on, any user of that PC can change proxy settings, but if she/he open that window again proxy settings you entered as administrator will remain.
I checked what is happening in registry settings and what I discovered that somehow all Internet settings for proxy are changed in registry with entered values, but I didn’t catch a process that is changing all the values in registry. In any case result of this setting is also that if you try to change proxy setting as normal user setting is not changed. Wathc the video
Proxy settings for WinHTTP API
As we already mentioned in part I there are two different API-s used for accessing Internet over proxy. One of them WinHTTP API need its own separate proxy settings . Settings we talked about in chapters before This service also has add-on WinHTTP WPAD service that is used for configuring proxy settings using wpad script.
For system-wide proxy settings that is using this API you can use netsh command. This setting will affect all applications including Windows services which use WinHTTP API with default proxy. For example Windows Update service will not work if you are behind proxy and didn’t set this up. Syntax of this command, that you run in command shell is:
netsh winhttp set proxy 10.90.112.50:9090 "*.contoso.com;<local>" netsh winhttp show proxy
After you run this command you will see proxy settings with show proxy command and it will look like this.
<local>
this entry correspond to Bypass proxy server for local addresses setting
These settings will be saved in the WinHttpSettings parameter under the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections.
You can set this proxy setting with GPO using registry wizard. Open new GPO nad navigate to Computer Configuration > Preferences > Windows Settings > Registry > New > Registry Wizard.
Select Local computer and specify the path to the WinHttpSettings parameter. Select setting and click finish. It will copy registry binary setting from your local PC to group policy entry.
Just to clarify that there is also two same settings under Connections Key with differnet names DefaultConnectionSettings and SavedLegacySettings among different registry keys. On this link you can find more about using this keys, and some help in quickly changing binary for turning on or off some common proxy setting values . For example If “Manual proxy” is checked – 9th byte value is “03“
Setting proxy using system environment variables
With new .NET Core cross platform language and general Windows love Linux attitude, you can now use environment variables for setting proxy. I first discovered this possibility when i tried to debug why certain web application is using proxy when it shouldn’t. For all apps that are using Linux like http_proxy, https_proxy entries you can now set it up. This change came with .NETcore 3.0. You can check when it all started on this link . If I am wrong please correct me. I didn’t had to much time to investigate
The environment variables used for DefaultProxy
initialization on Windows and Unix-based platforms are:
- HTTP_PROXY: the proxy server used on HTTP requests.
- HTTPS_PROXY: the proxy server used on HTTPS requests.
- ALL_PROXY: the proxy server used on HTTP and/or HTTPS requests in case HTTP_PROXY and/or HTTPS_PROXY are not defined.
- NO_PROXY: a comma-separated list of hostnames that should be excluded from proxying.
New apps are using these environment variables first, and if they don’t exist user proxy settings are used. Please check this link for more details. What is interesting that PowerShell 7 is also using this feature.
If you see entries on the picture in your Windows installation check with you development team 🙂
Prevent user from changing browser settings
Even if GPO is applied to IE, netsh or any other proxy settings, users can change any of the proxy settings. Whatever change is, GPO will still overwrite user changed settings, because GPO’s are applied on regular bases in every domain.
You can prevent users from changing user proxy settings utilizing GPO “Prevent changing proxy settings”. This parameter is present in both the user and computer GPO sections under next locations
- Computer Configuration > Policies > Administrative Templates > Windows Components – Internet Explorer
- User Configuration > Policies > Administrative Templates > Windows Components Internet Explorer
Settings in the Computer Configuration section take precedence over user settings.
Powershell and proxy settings
When using PowerShell there is some recommendation what proxy settings should be used/configure. This is table about recommended proxy settings taken form this Microsoft link
Platform | Recommended Proxy Settings | Comment |
---|---|---|
Windows PowerShell 5.1 | System proxy settings | Do not suggest setting HTTP_PROXY/HTTPS_PROXY environment variables. |
PowerShell 7 on Windows | System proxy settings | Proxy could be configured by setting both HTTP_PROXY and HTTPS_PROXY environment variables. |
PowerShell 7 on macOS | System proxy settings | Proxy could be configured by setting both HTTP_PROXY and HTTPS_PROXY environment variables. |
PowerShell 7 on Linux | Set both HTTP_PROXY and HTTPS_PROXY environment variables, plus optional NO_PROXY | The environment variables should be set before starting PowerShell, otherwise they may not be respected. |
To find out what proxy settings is using PowerShell you can use this command
[System.Net.WebProxy]::GetDefaultProxy()
For some more info please check this link
I next part I will cover configuring proxy settings using WPAD/PAC scripts. i hope it will not be long and daunting task like this one. See you