DEV Community

xiaoran
xiaoran

Posted on

Ubuntu Set System Network Proxy

Install agent tools such as trojan and configure startup to obtain the port number

for example

10.10.1.10:8080
Enter fullscreen mode Exit fullscreen mode

System Agent Settings

We will add a shell script file under/etc/profile.d/proxy.sh, which will ensure that the settings are applicable to all logged in users:

sudo vim  /etc/profile.d/proxy.sh
Enter fullscreen mode Exit fullscreen mode

Write the following content in the document:

# set proxy config via profie.d - should apply for all users
export http_proxy="http://10.10.1.10:8080/"
export https_proxy="http://10.10.1.10:8080/"
export ftp_proxy="http://10.10.1.10:8080/"
export no_proxy="127.0.0.1,localhost"
# For curl
export HTTP_PROXY="http://10.10.1.10:8080/"
export HTTPS_PROXY="http://10.10.1.10:8080/"
export FTP_PROXY="http://10.10.1.10:8080/"
export NO_PROXY="127.0.0.1,localhost"
Enter fullscreen mode Exit fullscreen mode

Add execution permissions for this file:

sudo chmod +x  /etc/profile.d/proxy.sh
Enter fullscreen mode Exit fullscreen mode

Activate the file to start using proxy settings, or log out and log in again:

source /etc/profile.d/proxy.sh
#Check the environment variables to confirm if they are effective
env | grep -i proxy
Enter fullscreen mode Exit fullscreen mode

Clear Network Proxy when you don't need it any more.

unset http_proxy

unset https_proxy

unset HTTP_PROXY

unset HTTPS_PROXY
Enter fullscreen mode Exit fullscreen mode

Top comments (0)