Smartproxy Linux Setup Guide: How to Use Residential Proxies with curl, wget, and Python
A beginner-friendly tutorial for configuring Smartproxy residential proxies on Linux. Learn to authenticate, set environment variables, route curl and wget traffic, integrate with Python requests, and rotate IPs for privacy or scraping.
Overview
Smartproxy provides residential and datacenter proxies with HTTP and SOCKS5 support. This guide shows you how to configure Smartproxy on Linux for command-line tools and Python scripts. You'll learn to set system-wide proxy environment variables, authenticate with your credentials, test the connection, and rotate IPs for privacy or web scraping. This tutorial uses residential proxies, but the steps apply to datacenter proxies as well.
Prerequisites
- A Smartproxy account (free trial or paid plan). If you don't have one, you can sign up on the Smartproxy website.
- A Linux system (tested on Ubuntu 22.04, but works on other distributions).
- Basic familiarity with the terminal.
curl,wget, and Python 3 withrequestsinstalled. Install with your package manager if needed.
Step 1: Get Your Smartproxy Proxy Credentials
- Log in to your Smartproxy dashboard.
- Navigate to the "Residential" or "Datacenter" section and locate your proxy endpoint (e.g.,
gateway.smartproxy.com) and port (e.g.,7000). - Note your proxy username and password. Smartproxy uses authentication via username/password or IP whitelisting. For username/password, your username may include additional parameters for session control (e.g.,
user-session-abc123). Check the dashboard for the exact format. - (Optional) If you prefer IP whitelisting, add your current public IP to the allowed list in the dashboard.
Step 2: Configure Environment Variables for System-Wide Proxy
Environment variables are the easiest way to route CLI tools through a proxy.
- Open your shell configuration file (e.g.,
~/.bashrcor~/.zshrc) in a text editor. - Add the following lines, replacing placeholders with your actual credentials and endpoint:
For SOCKS5, use theexport HTTP_PROXY="http://username:[email protected]:7000" export HTTPS_PROXY="http://username:[email protected]:7000" export ALL_PROXY="socks5://username:[email protected]:7000"socks5://scheme. Note that not all tools respectALL_PROXY; many useHTTP_PROXYandHTTPS_PROXYeven for HTTPS traffic. - Save the file and reload it:
source ~/.bashrc - Verify the variables are set:
echo $HTTP_PROXY
Step 3: Test Your Proxy with curl
- Run a simple request to check your IP:
You should see a JSON response with an IP different from your own.curl -x http://username:[email protected]:7000 https://httpbin.org/ip - To use SOCKS5, specify the proxy scheme:
curl --socks5 username:[email protected]:7000 https://httpbin.org/ip - If you set environment variables, you can omit the
-xflag:curl https://httpbin.org/ip
Step 4: Route wget Through the Proxy
- Create or edit
~/.wgetrcand add:
wget does not support SOCKS5 natively; use HTTP proxy for wget.use_proxy = on http_proxy = http://username:[email protected]:7000 https_proxy = http://username:[email protected]:7000 - Test with:
wget -qO- https://httpbin.org/ip
Step 5: Use Smartproxy with Python Requests
- Install the
requestslibrary if you haven't:pip install requests - Use the following Python snippet to route requests through Smartproxy:
import requests proxy_url = "http://username:[email protected]:7000" proxies = { "http": proxy_url, "https": proxy_url, } response = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=10) print(response.json()) - For SOCKS5, install
requests[socks]and use:proxies = { "http": "socks5://username:[email protected]:7000", "https": "socks5://username:[email protected]:7000", }
Step 6: Rotate IPs and Use Sticky Sessions
Smartproxy residential proxies rotate IPs per request by default when using the rotating endpoint. To maintain the same IP for multiple requests (sticky session), you can add a session identifier to your username.
- In your dashboard, check the format for session control. Typically, you append
-session-<id>to your username. - For a sticky session, use:
Replacecurl -x http://username-session-abc123:[email protected]:7000 https://httpbin.org/ipabc123with any alphanumeric string. The same session ID will use the same IP for a period (usually up to 10–30 minutes). - To rotate IPs, simply omit the session ID or use a new session ID for each request.
Troubleshooting
- 407 Proxy Authentication Required: Double-check your username and password. Ensure special characters are URL-encoded.
- Connection refused or timeout: Verify the endpoint and port. Check your firewall settings. Some networks block non-standard ports.
- SSL certificate errors: Ensure you are using
https://for HTTPS targets and that your proxy supports CONNECT (HTTP proxies do). For SOCKS5, SSL is handled end-to-end. - DNS leaks: When using HTTP proxy, DNS resolution may happen locally. To prevent leaks, use SOCKS5 with remote DNS (
socks5h://in curl) or a tool likeproxychains. - Slow speeds: Residential proxies can be slower. Try a different endpoint or region if available.
Summary
You've configured Smartproxy on Linux for curl, wget, and Python. You can now route traffic through residential or datacenter proxies, authenticate securely, and rotate IPs for privacy or web scraping. Remember to keep your credentials safe and check Smartproxy's dashboard for advanced features like geo-targeting and session control. For browser-based tasks, consider Smartproxy's browser extension for a simpler setup.