Linux OS Proxy

System-Wide Proxy Configuration in /etc/environment

sudo nano /etc/environment
http_proxy="http://proxy.example.com:8080"
https_proxy="http://proxy.example.com:8080"
ftp_proxy="http://proxy.example.com:8080"
no_proxy="localhost,127.0.0.1,::1"

Proxy for APT

sudo nano /etc/apt/apt.conf.d/proxy.conf
Acquire::http::Proxy "http://proxy.example.com:8080";
Acquire::https::Proxy "http://proxy.example.com:8080";
Acquire::ftp::Proxy "http://proxy.example.com:8080";

Proxy for NetworkManager (for GUI Applications)

If you're using a desktop environment with NetworkManager, you can configure a system proxy that GUI applications will use:

Go to Settings > Network.
Select Network Proxy and set the HTTP, HTTPS, FTP, and SOCKS proxies as needed.
After setting the proxy, apply it system-wide by clicking Apply System-Wide (available in some Ubuntu versions).
Verifying Proxy Settings
You can check if the proxy is set correctly by running:

echo $http_proxy
echo $https_proxy

Or test with a command like curl curl -I http://example.com

This setup ensures that your proxy configuration is respected by the entire OS, including both terminal-based and graphical applications.

Proxy for Maven

System-Wide Configuration: /etc/environment
For a system-wide configuration that affects all users, add MAVEN_OPTS to /etc/environment. This ensures that any user or process running Maven on the machine will use these settings by default. This approach is recommended if:

Multiple users on the system need the same Maven settings.
You want a global configuration without requiring each user to modify their shell profile.

sudo nano /etc/environment
MAVEN_OPTS="-Xmx1024m -Xms512m -Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=8080"

If you need MAVEN_OPTS only for a specific project, you can create a shell script in the project directory with the required MAVEN_OPTS settings. This approach is helpful if:

You’re working on multiple projects that require different configurations.
You want to avoid global or user-wide settings affecting unrelated projects.

#!/bin/bash
export MAVEN_OPTS="-Xmx1024m -Xms512m -Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=8080"
mvn "$@"

Proxy for Docker Daemon

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080"
Environment="HTTPS_PROXY=http://proxy.example.com:8080"
Environment="NO_PROXY=localhost,127.0.0.1"
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容