Menu
User

DropVPS Team

Writer: Cooper Reagan

How to set proxy for cURL in Ubuntu?

How to set proxy for cURL in Ubuntu?

Publication Date

03/08/2025

Category

Articles

Reading Time

3 Min

Table of Contents

cURL is a powerful command-line tool used for transferring data with URLs. It supports various protocols and can be configured to use a proxy server for its requests. In this guide, we’ll show you how to set up cURL to use a proxy in Ubuntu.

Step 1: Identify Your Proxy Server

Before configuring cURL, you need to know your proxy server’s details, including the IP address and port number. The common format for a proxy server is:

http://username:[email protected]:port

If your proxy does not require authentication, you can simply use:

http://proxyserver.com:port

Step 2: Using cURL with Proxy

You can specify the proxy directly in the cURL command using the -x or --proxy option. Here’s how to do it:

For HTTP Proxy

If your proxy server uses HTTP, you can run the following command:

curl -x http://proxyserver.com:port http://example.com

For HTTPS Proxy

If you need to use an HTTPS proxy, the command is similar:

curl -x https://proxyserver.com:port https://example.com

With Authentication

If your proxy requires authentication, include your username and password in the command:

curl -x http://username:[email protected]:port http://example.com

Example Command

Here’s a complete example of using cURL with a proxy:

curl -x http://myproxy.com:8080 http://example.com

Or, with authentication:

curl -x http://user:[email protected]:8080 http://example.com

Step 3: Setting Environment Variables (Optional)

If you frequently use a proxy with cURL, you might want to set environment variables to avoid specifying the proxy each time. You can do this by adding the following lines to your ~/.bashrc or ~/.bash_profile file:

export http_proxy="http://proxyserver.com:port"
export https_proxy="http://proxyserver.com:port"

If your proxy requires authentication:

export http_proxy="http://username:[email protected]:port"
export https_proxy="http://username:[email protected]:port"

After adding these lines, run the following command to apply the changes:

source ~/.bashrc

Now you can use cURL without specifying the proxy each time:

curl http://example.com

Step 4: Testing Your Configuration

To verify that cURL is using the proxy, you can make a request to an external service that returns your IP address. For example:

curl -x http://proxyserver.com:port http://httpbin.org/ip

This command will return the IP address seen by the target server, which should be the IP of your proxy server if configured correctly. By following these steps, you have successfully configured cURL to use a proxy in Ubuntu. This setup is beneficial for situations where direct internet access is restricted or when you want to enhance your privacy while making web requests. For more tips and tutorials, keep visiting DropVPS.com!

Linux VPS
U
Loading...

Related Posts