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"
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容