Linux: How to Use Curl Command With Proxy

This post will guide you how to use CURL command to access HTTP or HTTPS website with a proxy server in Linux system. How do I Set Proxy for Curl Command in Linux.

Set Proxy For Curl Command


If you want to user a proxy for a Linux command, and you need to set the environment variables http_proxy or https_proxy. And those two proxy variables are used by the most of all Linux command with proxy. such as: curl, wget, ssh, apt-get, yum and so on.

You need to export those variables in your bash shell, type:

$ export http_proxy="http://proxy_server_ip:PORT"
$ export https_proxy="https://proxy_server_ip:PORT"

If your proxy server need to use the username and password, you can type the following command to export Proxy variables:

$ export http_proxy="http://username:password@proxy_server_ip:PORT/"
$export https_proxy="https://username:password@proxy_server_ip:PORT/"

After exporting those variables, the curl command will perform the HTTP/HTTPS requests using the above proxy setting.

Or you can also pass all proxy setting to curl command, just use the -x option, just like below:

$ curl -x http://username:password@proxy_server_ip:prot  website_url

If you password contains special characters, you need to replace them with ASCII codes.

Unset Proxy Variables


If you want to diable proxy setting for your current server or your curl command, you can type the following commands:

$ unset http_proxy
$ unset https_proxy

 

You might also like:

Sidebar



back to top