Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a system-wide proxy on Ubuntu?

Tags:

proxy

ubuntu

I'm in a strange position where the apt-get update works and can connect to the internet although nothing else works in a Docker container.

I'm not sure if I have put the proxies in the wrong place or I am missing something else.

For the apt-get I add the following to the /etc/apt/apt.conf and it works.

Acquire::http::proxy  "http://user:[email protected].*.*:80/";
Acquire::ftp::proxy "ftp://user:[email protected].*.*:80/";
Acquire::https::proxy "https://user:[email protected].*.*:80/";

Although since also placing the credentials in the correct (I think) pattern / format in /etc/profile I cannot get commands such as curl or ping to work.

Is there something I might be missing?

like image 307
Jack Avatar asked Dec 10 '22 18:12

Jack


2 Answers

Type env | grep proxy, if it returns nothing then exporting proxies might help:

export https_proxy=https://user:[email protected].*.*:80
export http_proxy=http://user:[email protected].*.*:80
export ftp_proxy=ftp://user:[email protected].*.*:80
like image 51
Irshad Bhat Avatar answered Dec 13 '22 09:12

Irshad Bhat


If your user's default shell is bash or another Bourne compatible shell, then interactive login shells will read from the global /etc/profile and /etc/profile.d/*.sh and /etc/bash.bashrc files. Interactive non-login shells will also read from the global /etc/bash.bashrc file.

Creating a /etc/profile.d/proxy.sh file with the http_proxy, https_proxy, and ftp_proxy environment variables set should make those values available to most programs the next time you log in.

Here is an example proxy.sh file where the http, https, and ftp proxy is the same:

export http_proxy=http://my.local.proxy:port
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy

Some login methods might skip those files so if it doesn't work, you could try putting them in /etc/bash.bashrc so that each new interactive shell you open has those values set.

like image 25
jla Avatar answered Dec 13 '22 07:12

jla