- wget is not using environment variable based proxy settings
- 2 Answers 2
- How to set up proxy using http_proxy & https_proxy environment variable in Linux?
- What is Proxy Server?
- Check current proxy configuration status (https_proxy/https_proxy)
- Set up proxy server using http_proxy environment variable
- Set up proxy without username and password
- Set up proxy with username and password
- Set up proxy with domain, username and password
- Special character (@) handling
- Set up proxy permanently using /etc/environment
- Set up proxy permanently using /etc/profile.d
- Related Posts:
- 4 thoughts on “How to set up proxy using http_proxy & https_proxy environment variable in Linux?”
- HTTP_PROXY and HTTPS_PROXY environment variables are not respected #506
- Comments
- new-mikha commented Oct 26, 2017 •
- All proxy environment variable windows
- Answered by:
- Question
- Answers
- Are HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables standard?
- 2 Answers 2
wget is not using environment variable based proxy settings
I have a windows nano server and try to set the proxy settings. The nano server is only in command mode no GUI. I have run in PowerShell
and the IP address from google was shown, so there is some connection. But when I try to run
then I have set the proxy in the PowerShell environment with
but the same problem. When I call wget directly with the proxy settings it works:
How can I get it work that wget uses the global proxy settings? Or are the settings not correctly set? Or need I to install some windows features, that it is working?
I use wget to test the connection later any web request for any program should work.
2 Answers 2
Pretty sure your issue here is that you are not setting environment variables and getting mixed up between cmd exe’s and PowerShell cmdlets. As we read from the (what I hope is) the documentation for wget concerning proxy information:
The standard way to specify proxy location, which Wget recognizes, is using the following environment variables:
Which is exactly what you tried to do here which was a successful operation (no error) but did not work as expected.
Problem is that if you run that in PowerShell set is an alias for Set-Variable . See Get-Alias set .
You are also having an issue with wget as that is an alias of Invoke-WebRequest . That would only be an issue if you had at least PowerShell version 3.0 which you appear to have. In your working example you are using cmdlet syntax ( -Proxy . ).
In both cases ( set and the non-working wget ) the command was ambiguous and PowerShell had to try to match it up to something.
So what we are seeing here is about_Command_Precedence coming into play
If you do not specify a path, Windows PowerShell uses the following precedence order when it runs commands:
Native Windows commands is last on the list! Really though if you are in PowerShell doing this you might as well use PowerShell cmdlets to get your environment variables set (if you insist on using wget ). The only thing I am not sure of is which method you should use the first here should not persist the session where the second method is permanent. Sure the first would suffice but use the second if you want to keep these set on the computer between sessions.
- $env:http_proxy = «ipaddress:8080»
- [Environment]::SetEnvironmentVariable(«http_proxy», «ipaddress:8080», «Machine»)
You can read more on this from TechNet. Also watch your spelling of «address»
If you are going to be using cmd utilities make sure you append .exe and if you don’t specify the full path to the resource then ensure its directory is part of the path environment variable.
How to set up proxy using http_proxy & https_proxy environment variable in Linux?
Table of Contents
In this article I will share the steps to set up proxy server using https_proxy and https_proxy environment variable.
What is Proxy Server?
A proxy server is a dedicated computer or a software system running on a computer that acts as an intermediary between an endpoint device, such as a computer, and another server from which a user or client is requesting a service. The proxy server may exist in the same machine as a firewall server or it may be on a separate server, which forwards requests through the firewall.
Check current proxy configuration status (https_proxy/https_proxy)
This variable will show if there is a proxy server configured on the system:
If these variables are empty it would mean that there are no proxy servers configured on the system level.
Set up proxy server using http_proxy environment variable
The http_proxy and https_proxy environment variable is used to specify proxy settings to client programs such as curl and wget .
Set up proxy without username and password
Execute the below command with valid SERVER_IP and PORT on the terminal. This will enable proxy configuration for the current session but these values will not be persistent across reboot.
Set up proxy with username and password
You can modify the earlier command to add the username and password value assuming a valid authentication is required to enable the proxy server configuration. But again this command will also enable proxy server for the current session only and will not be persistent across reboots.
Set up proxy with domain, username and password
Assuming you are also required to add domain detail while setting up proxy configuration on your system then use the below command
Special character (@) handling
With more complex and robust handling of special characters in username or password follow How to setup http or https proxy with special characters in username and password
When the username or password uses the @ symbol, add a backslash (\) before the @ — for example:
Set up proxy permanently using /etc/environment
Now as I have highlighted above the above commands will work only for the current active session but will not be available across reboots. So to make these changes persistent define the environment variables in /etc/environment file:
Set up proxy permanently using /etc/profile.d
For bash and sh users, add the export line given above into a new file called /etc/profile.d/http_proxy.sh file:
For csh and tcsh users, use the following command to set the http_proxy variable in a new file called /etc/profile.d/http_proxy.csh file:
The extension of these files determines which shell will read them. The commands are not interchangeable.
Lastly I hope the steps from the article to setup proxy using http_proxy and https_proxy environment variable in Linux was helpful. So, let me know your suggestions and feedback using the comment section.
Related Posts:
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
4 thoughts on “How to set up proxy using http_proxy & https_proxy environment variable in Linux?”
Your example «Set up proxy permanently using /etc/environment» should use a double redirect (>>) to APPEND instead of a single redirect (>) to OVERWRITE the environment file. If someone were to copy/paste your example, they would overwrite any other existing environment settings in their /etc/environment file!
# echo «http_proxy=http://proxy.example.com:3128/» >> /etc/environment
That’s a good point, thanks. I have updated the article.
I would like to set up a proxy in debian10 via environment file.
The username, password, however, includes a comma (,)
How does that affect the phrasing?
HTTP_PROXY and HTTPS_PROXY environment variables are not respected #506
Comments
new-mikha commented Oct 26, 2017 •
In a scenario when HTTP_PROXY and/or HTTPS_PROXY environment variable are set in the system, the Git itself works correctly. However, operations that involve Git Credential Manager for Windows might not work well because it seems that it doesn’t check these variables at all.
The test case looks like this:
- System works behind a proxy, and there is no way to by bypass it.
- HTTP_PROXY environment variable set to the proxy.
- Nothing else tells that there is a proxy, e.g. http.proxy and https.proxy config parameters are NOT set.
- A git operation on remote repo starts, e.g. ‘git pull’
- GitHub credentials window pops up, credentials entered, OK pressed, the window disappears.
- The git operation hangs for quite a while (20 seconds?), then it writes:
fatal: TaskCanceledException encountered. A task was canceled. - then Git suggests to enter user name and password in command prompt, and all goes well.
- next time a git operation runs over the same remote repo, the credentials window does not pop in, but the operation still waits 20 seconds, and then again offers to enter credentials in the command line.
- deleting credentials from Windows Credentials applet resets the problem, i.e. next time the GitHub cred window pops up again.
Setting up http.proxy parameter in Git config helps. But it’s hard to find out that this needs to done, because the error message listed above is very generic. It’s even hard to find out that the problem is with the Git Credential Manager for Windows at all — the error message in the Git log just does not provide enough details (created a separate issue #507 for that)
The text was updated successfully, but these errors were encountered:
All proxy environment variable windows
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
Answered by:
Question
I set no proxy for the IP addresses 169.254.169.254 and 127.0.0.1.
The two IP addresses are separated by a «;», is it correct?
If I have a script that uses «http://169.254.169.254», because I have an environment variable 169.254.169.254. Will the script bypass proxy for http://169.254.169.254?
Answers
I would agree with Bill, and no_proxy t his variable should contain a comma-separated list of domain extensions proxy should not be used for. For instance, if the value of no_proxy is ‘ .mit.edu ’, proxy will not be used to retrieve documents from MIT.
You could check the below article for some reference regarding the set environment variables :
Are HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables standard?
It seems that a lot of programs are designed to read these environment variables to decide what proxy to go through in order to connect to a resource on the internet. Those programs may also have their own, individual proxy settings, but if those are not set, they’ll happily use these environment variables.
I just want to know:
- Are these environment variables standard?
- Is there a written specification (may be by the OS manufacturers?) that recommends the use of these environment variables?
2 Answers 2
I agree with BillThor’s statement that This is more a convention than a standard.
I don’t know the origin of these variables but in case of HTTP on *nix many conventions seem to originate from behavior of libcurl HTTP library and curl command line program.
At https://curl.haxx.se/docs/manual.html there’s description of environment variables related to using HTTP proxy which libcurl/curl understands:
Curl reads and understands the following environment variables:
http_proxy, HTTPS_PROXY, FTP_PROXY
They should be set for protocol-specific proxies. General proxy should be set with
ALL_PROXY
A comma-separated list of host names that shouldn’t go through any proxy is set in (only an asterisk, ‘*’ matches all hosts)
NO_PROXY
If the host name matches one of these strings, or the host is within the domain of one of these strings, transactions with that node will not be proxied.
Please notice that http_proxy is spelled lowercase as the only one among these variables. Some libraries/programs look for lowercase names of these variables whereas others look for upppercase names. To be safe one should define both lowercase and uppercase versions of each variable.
Another issue is that cited description of how host names are matched against NO_PROXY is not precise and does not answer the following questions:
- Should values be fully qualified domain names (FQDN) thus ending with a dot like foo.example.com. or not?
- Should foo.example.com match only this one domain or should it also match any subdomain like bar.foo.example.com ? If the latter then should it also match any subdomain in any subdomain like bar.baz.foo.example.com ?
- Is .foo.example.com (dot at the beginning) allowed and if so then what should it match ?
- Is asterisk ( * ) allowed as part of value ( *.example.com , *example.com ) and if so then how is it treated?
Lack of formal specification leads to confusion and bugs. Here one has to mention libproxy library which aims to provide correct and consistent support for proxy configuration. From project’s home page:
libproxy exists to answer the question: Given a network resource, how do I reach it? It handles all the details, enabling you to get back to programming.