Ultimate Guide to Setting Up Proxies on CentOS: Global Configuration and Troubleshooting
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.
Related Contents
Resolving PHP "could not find driver" Error: Ultimate Guide to Missing PDO Database Drivers
Duration: 00:00 | DP | 2026-07-04 08:03:00Resolving Nginx Permission Denied (13) Errors for WebP Images Generated by PHP Imagick
Duration: 00:00 | DP | 2026-07-05 21:17:00How to Fix Mac mini Not Receiving SMS Messages and iCloud Sync Stuck
Duration: 00:00 | DP | 2026-07-06 22:07:00Ultimate Guide to Fixing Nginx [warn] conflicting server name Warning
Duration: 00:00 | DP | 2026-07-21 09:02:28Fixing 'Unable to locate package openjdk-17-jdk' in PHP 8 Docker (Debian Trixie)
Duration: 00:00 | DP | 2026-07-25 09:23:18The Ultimate 'Connection Refused' Guide: A PHP PDO & Docker Debugging Saga of a Forgotten Port
Duration: 00:00 | DP | 2025-12-03 09:03:20Git Pull Failed? Easily Fix the 'Your local changes would be overwritten' Error
Duration: 00:00 | DP | 2025-12-25 20:40:00Decoding the 99% I/O Wait: The Ultimate Post-Mortem Guide for CentOS Server 'Freezes'
Duration: 00:00 | DP | 2025-12-31 23:50:00Mastering Clash Rules: A Complete Guide to YAML Configuration
Duration: 00:00 | DP | 2026-02-19 15:11:43Recommended
Modular Nginx Configuration: How to Elegantly Manage Multiple Projects with Subdomains
00:00 | 138Say goodbye to bloated nginx.conf files! This guid...
getElementById vs. querySelector: Which One Should You Use? A Deep Dive into JavaScript DOM Selectors
00:00 | 117When manipulating the DOM in JavaScript, both getE...
From Concept to Cron Job: Building the Perfect SEO Sitemap for a Multilingual Video Website
00:00 | 80This article provides a comprehensive guide to des...
From Repetitive to Reusable: Elegantly Refactoring Your JavaScript Markdown Renderer
00:00 | 122In front-end development, handling multiple Markdo...