176

How do I make curl ignore the proxy? Setting $NO_PROXY doesn't seem to work for me.

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
ksuralta
  • 16,276
  • 16
  • 38
  • 36
  • 1
    It would help people answer you if you provided some more information. What platform are you on? Where is curl getting the proxy settings from? What protocol (HTTP, FTP)? What kind of proxy (HTTP, SOCKS)? Is it a transparent proxy? Can you show an exact set of commands that exhibit your problem, along with their output? – Brian Campbell Apr 29 '09 at 04:18

14 Answers14

379

If your curl is at least version 7.19.4, you could just use the --noproxy flag.

curl --noproxy '*' http://www.stackoverflow.com

From the manual.

Ed Randall
  • 6,887
  • 2
  • 50
  • 45
Scott Offen
  • 6,933
  • 3
  • 21
  • 24
  • 5
    curl: option --noproxy: is unknown – Roger Ng Apr 10 '13 at 04:39
  • 5
    @RogerNg, if the manual or usage has changed since I answered the question, feel free to update the answer or write your own. Nevertheless, at the time of writing, this answer was accurate for the question asked. If your installation isn't behaving according to the specifications, that is another issue entirely. – Scott Offen Apr 22 '13 at 17:26
  • @RogerNg, having taken a look at some of your recently posted questions here on stackoverflow, you might be confusing curl with PHP cUrl, which is not the same thing. – Scott Offen Apr 22 '13 at 17:29
  • @ScottOffen I know the difference between curl and PHP cUrl. I have figured out the way to solve my PHP cUrl issue by by-passing the proxy. – Roger Ng Apr 25 '13 at 02:44
  • 3
    curl --noproxy stackoverflow.com http://www.stackoverflow.com This is the correct commend. – arulraj.net May 01 '14 at 01:25
  • 2
    I assume that `--noproxy` option is not available for older curl versions (e.g. those that are used at Centos/RHEL 5.x) – Dmitriusan May 12 '14 at 16:07
  • 3
    Based on the documentation, the only way this could've ever worked with `--noproxy 127.0.0.1` was if stackoverflow.com was running on localhost. – dannysauer Oct 17 '16 at 17:36
  • curl: (3) malformed – niken Jun 13 '17 at 15:54
  • 1
    What the purpose of `127.0.0.1` here? This should be host which will not use proxy. So `'www.stackoverflow.com'` for mentioned example. Or `'*'` for all hosts (the quotes are mandatory here). See [this answer](https://stackoverflow.com/a/17710829/758991). – Ruslan Stelmachenko Oct 17 '17 at 14:11
88

I ran into the same problem because I set the http_proxy and https_proxy environment variables. But occasionally, I connect to a different network and need to bypass the proxy temporarily. The easiest way to do this (without changing the environment variables) is:

curl --noproxy '*' stackoverflow.com

From the manual: "The only wildcard is a single * character, which matches all hosts, and effectively disables the proxy."

The * character is quoted so that it is not erroneously expanded by the shell.

Chris Pick
  • 570
  • 4
  • 7
wisbucky
  • 33,218
  • 10
  • 150
  • 101
  • 13
    note for furture users: Bash expands the local files if I don't quote the * so `curl --noproxy "*" stackoverflow.com` – Adam Nov 04 '13 at 19:15
  • Very useful & worth noting that this also appears to ignore the (SOCKS) proxy I have set in my .curlrc file – MatzFan Aug 19 '16 at 09:19
  • 1
    This is the answer that has worked for me using curl version 7.22.0 – xpereta Oct 05 '16 at 08:14
70

I assume curl is reading the proxy address from the environment variable http_proxy and that the variable should keep its value. Then in a shell like bash, export http_proxy=''; before a command (or in a shell script) would temporarily change its value.

(See curl's manual for all the variables it looks at, under the ENVIRONMENT heading.)

Petah
  • 45,477
  • 28
  • 157
  • 213
Anonymous
  • 49,213
  • 1
  • 25
  • 19
  • 28
    Or simply `unset http_proxy` – joelittlejohn Sep 12 '13 at 10:24
  • One note: there are other *_proxy env variables like `ftp_proxy`. I think, here is a full list https://wiki.archlinux.org/index.php/proxy_settings . – Dmitriusan May 12 '14 at 16:04
  • If you don't want to override the http_proxy on a case-by-case basis, you can configure the domains to ignore with $no_proxy, and then alias your curl: alias curl='curl --noproxy $no_proxy' – Sir4ur0n Apr 28 '16 at 16:51
  • 1
    @jdebon That doesn't work if you have a wildcard in that environment variable, for the reasons described below (https://stackoverflow.com/a/17710829/2189128). – Jeff Hammond Jun 12 '17 at 15:21
  • @Jeff It's not my case, but nice spot, it could cause some problem to other persons. Thanks! – Sir4ur0n Jun 12 '17 at 18:25
  • Setting `no_proxy` doesn't work for `jfrog` either, and after `export http_proxy=''`, everything works well. – Corey Feb 25 '19 at 07:01
29

This works just fine, set the proxy string to ""

curl -x "" http://www.stackoverflow.com
ericcurtin
  • 1,499
  • 17
  • 20
20

Add your proxy preferences into .curlrc or _curlrc (windows)

proxy = 1.2.3.4
noproxy = .dev,localhost,127.0.0.1

This make all dev domains and local machine request ignore the proxy.

See man page proxy and noproxy on same page.

Clemens Tolboom
  • 1,872
  • 18
  • 30
9

Long shot but try setting the proxy to "" (empty string) that should override any proxy settings according to the man page.

lsl
  • 4,371
  • 3
  • 39
  • 54
  • 4
    It's not a "long shot" - it's the proper way to do it. According to my curl's man page (7.15.5, which does not show a '--noproxy' option), -x/--proxy ...This option overrides existing environment variables that sets proxy to use. If there's an environment variable setting a proxy, you can set proxy to "" to override it. – Rob Cranfill Mar 19 '13 at 20:31
  • 8
    In '09, everything was a long shot. – lsl Mar 19 '13 at 22:27
  • 7
    +1, -x "" does it. --noproxy with wildcard does not work with my bash even if i quote the "*" – Eugene Apr 03 '14 at 12:44
  • @Eugene: It is working in bash 4.3.11, and it must be quoted. – karatedog May 11 '16 at 14:08
8

You should use $no_proxy env variable (lower-case). Please consult https://wiki.archlinux.org/index.php/proxy_settings for examples.

Also, there was a bug at curl long time ago http://sourceforge.net/p/curl/bugs/185/ , maybe you are using an ancient curl version that includes this bug.

Dmitriusan
  • 11,525
  • 3
  • 38
  • 38
7

I have http_proxy and https_proxy are defined. I don't want to unset and set again those environments but --noproxy '*' works perfectly for me.

curl --noproxy '*' -XGET 172.17.0.2:9200
{
  "status" : 200,
  "name" : "Medusa",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "1.5.0",
    "build_hash" : "544816042d40151d3ce4ba4f95399d7860dc2e92",
    "build_timestamp" : "2015-03-23T14:30:58Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}
prayagupa
  • 30,204
  • 14
  • 155
  • 192
  • It does not work for me. I have curl 7.79.1 on Windows. I issue `curl --noproxy '*' -X GET http://localhost:8080/myapi/v1/cars -H "Content-Type: application/json" -H "My-Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIi..." | json` and I get GATEWAY_TIMEOUT error because of my HTTP_PROXY and HPPTS_PROXY settings. Before I added these 2 variables, it worked just fine. – pixel Apr 07 '22 at 15:20
6

First, I listed the current proxy setting with

env | sort | less

(should be something like http_proxy=http://wpad.local.machine.location:port number)

Then I tried setting

export http_proxy=";" 

which gave this error message:

curl: (5) Couldn't resolve proxy ';'

Tried

export http_proxy="" && curl http://servername:portnumber/destinationpath/ -d 55

and it worked!

PS! Remember to set http-proxy back to its original settings with

export http_proxy=http://wpad.local.machine.location:port number
5

In case of windows: use curl --proxy "" ...

VISHAL DAGA
  • 4,132
  • 10
  • 47
  • 53
  • I'm so glad to finally have tried out this. Works like a charm. Thanks. My environment is using a corporate proxy and the other options did not work for me. – Leon Mar 10 '21 at 02:05
2

Lame answer but: Remember to make sure no proxy is set in a ~/.curlrc file (...).

jtlz2
  • 7,700
  • 9
  • 64
  • 114
  • 1
    Thank You. I had been scratching head why curl is not respecting the local env vars. And then I looked up the .curlrc and there was some additional configs. Added no_proxy there and it worked! – n3o Jan 29 '20 at 12:01
1

In my case (macos, curl 7.54.0), I have below proxy set with ~/.bash_profile

$ env |grep -i proxy |cut -d = -f1|sort
FTP_PROXY
HTTPS_PROXY
HTTP_PROXY
NO_PROXY
PROXY
ftp_proxy
http_proxy
https_proxy
no_proxy

With unknown reason, this version of curl can't work with environment variables NO_PRXY and no_proxy properly, then I unset the proxy environment variables one by one, until to both HTTPS_PROXY and https_proxy.

unset HTTPS_PROXY
unset https_proxy

it starts working and can connect to internal urls

So I would recommend to unset all proxy variables if you have in your environment as temporary solution.

unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY
BMW
  • 42,880
  • 12
  • 99
  • 116
0

ive been so sick to get rid of CURL randomly connect to localhost 3128 but sometime its jut normal.

ive done with clear iptables, disable firewall, edit environment, edit curlrc, with --noproxy optin etc.. everyting not work...

then i just realize that curl error only when its runing or executed by root user.

then i check under my root previlege :

nano ~/.curlrc

and that the problem because on that file contain curl proxy config to root with 127.0.0.1 3128!

so, if you want to force curl no proxy, first time delete config in main user :

user@pc:~/.curlc

and root user :

root@pc:~/.curlc
mobagenie
  • 31
  • 4
-1

My curl was not ignoring the proxy on Ubuntu 12.04 until I set the "no_proxy" (lowercase) environment variable. The --noproxy option was not available.