Ultimate Guide to Setting Up Proxies on CentOS: Global Configuration and Troubleshooting

Published: 2026-07-27
Author: DP
Views: 0
Category: Linux
Content
In daily Linux server administration, it's common to encounter internal servers that cannot access the internet directly. This article (compiled by DP@lib00) details various methods for configuring proxies on CentOS systems, along with a comprehensive troubleshooting guide when proxies fail to work. ## Part 1: Proxy Configuration Methods on CentOS Setting up a proxy in CentOS can be categorized into **temporary environment variables**, **permanent environment variables**, and **application-specific configurations**. ### 1. Temporary Command-Line Setup This method is only valid for the current terminal session: ```bash export http_proxy=http://ProxyServerIP:Port export https_proxy=http://ProxyServerIP:Port export no_proxy="localhost,127.0.0.1,wiki.lib00.com" ``` *If the proxy requires authentication:* `export http_proxy=http://Username:Password@ProxyServerIP:Port` ### 2. Global Permanent Setup Write the configuration to system files to make it effective for all users and new sessions: 1. Edit the file: `vi /etc/profile` 2. Add the following at the end of the file: ```bash export http_proxy=http://ProxyServerIP:Port export https_proxy=http://ProxyServerIP:Port export no_proxy="localhost,127.0.0.1,wiki.lib00.com" ``` 3. Apply immediately: `source /etc/profile` ### 3. Proxy for Yum/DNF Package Managers Even with global proxies set, Yum/DNF sometimes requires independent configuration to download dependencies like `lib00-packages`: 1. Edit the config file: - CentOS 7: `vi /etc/yum.conf` - CentOS 8/Stream: `vi /etc/dnf/dnf.conf` 2. Add the following lines: ```ini proxy=http://ProxyServerIP:Port # If authentication is needed proxy_username=YourUsername proxy_password=YourPassword ``` ### 4. Specific Setup for Curl/Wget - **Curl**: Create or edit `~/.curlrc` and add `proxy = http://ProxyServerIP:Port` - **Wget**: Edit `/etc/wgetrc` or `~/.wgetrc` and add: ```text http_proxy = http://ProxyServerIP:Port https_proxy = http://ProxyServerIP:Port use_proxy = on ``` ### 5. Verifying the Proxy Use `curl` to test external connectivity: ```bash curl -I https://wiki.lib00.com # Or check your current public IP curl ifconfig.me ``` *To unset the proxy:* `unset http_proxy https_proxy` --- ## Part 2: Troubleshooting Guide for Proxy Issues If the proxy doesn't work after configuration, follow these steps from basic to advanced to troubleshoot: ### 1. Check Network Connectivity First, confirm if your local machine can reach the proxy server's port. * **Command:** `telnet ProxyServerIP Port` or `nc -vz ProxyServerIP Port` * **Result:** If the connection is refused or times out, it's a network layer issue (firewall blocking or proxy service is down). ### 2. Verify Environment Variables Ensure variables are correctly loaded into the current Shell session. * **Command:** `env | grep -i proxy` * **Note:** Some programs read `http_proxy` (lowercase), while others read `HTTP_PROXY` (uppercase). It is highly recommended to **set both**. ### 3. Check Proxy URL Format * **Protocol:** Ensure it includes `http://` or `https://`. * **Special Characters:** If your username or password contains special characters (like `@`, `:`, `#`), they must be **URL-encoded**. For example, `P@ssword` should be `P%40ssword`. * **SOCKS Proxy:** Ensure the format is `socks5://IP:Port`. ### 4. Check Firewall and SELinux * **Firewalld:** Try stopping it temporarily: `systemctl stop firewalld` * **SELinux:** Try setting it to permissive mode temporarily: `setenforce 0` ### 5. Rule out `no_proxy` Interference If the target address is in the `no_proxy` list, the request will bypass the proxy. Try clearing it temporarily with `unset no_proxy` and test again. ### 6. Tool-Specific Troubleshooting Some background daemons (like Docker) do not read system environment variables: * **Docker:** Needs to be configured separately in `/etc/systemd/system/docker.service.d/http-proxy.conf`. * **Curl Debugging:** Use `curl -v https://wiki.lib00.com` to view verbose connection logs and observe which proxy IP and port it attempts to connect to. ### 7. Packet Analysis (Advanced) If everything above seems fine, use `tcpdump` to trace the packets: ```bash tcpdump -i any port ProxyPort -nn ``` Observe if packets are being sent to the proxy server and if there are return packets. **Final Tip:** The fastest way to diagnose is using `curl -v -I https://wiki.lib00.com`. Through the verbose output (lines starting with `*`), you can clearly see whether the failure occurs during DNS resolution, TCP connection, or TLS handshake, allowing for precise fixes.