How to change system proxy settings from the command line on Ubuntu desktop

Last updated on August 27, 2020 by Dan Nanni

Question: I often need to change system proxy settings on Ubuntu desktop, but I do not want to go through a chain of GUI menus: System SettingsNetworkNetwork proxy, which is cumbersome. Is there a more convenient way to change desktop's proxy settings from the command line?

In Ubuntu desktop, its desktop environment settings, including system proxy settings, are stored in DConf database, which is a simple key/value store. If you modify any desktop properties using System Settings menu, the changes are persisted in the DConf database backend. There are GUI-based or non-GUI-based ways to modify DConf database on Ubuntu. While System Settings or dconf-editor are graphical methods for accessing DConf database, gsettings or dconf are command-line tools that can modify the database.

Here is how to change system proxy settings from the command line using gsettings.

The basic usage of gsettings for reading and writing a particular Dconf setting is as follows.

To modify a DConf setting:

$ gsettings set <schema> <key> <value>

To read a DConf setting:

$ gsettings get <schema> <key>

Change System Proxy Setting to Manual from the Command Line

The following commands will change HTTP proxy setting to my.proxy.com:8000 on Ubuntu desktop.

$ gsettings set org.gnome.system.proxy.http host 'my.proxy.com'
$ gsettings set org.gnome.system.proxy.http port 8000
$ gsettings set org.gnome.system.proxy mode 'manual'

If you want to change HTTPS/FTP proxy to manual as well, use these commands:

$ gsettings set org.gnome.system.proxy.https host 'my.proxy.com'
$ gsettings set org.gnome.system.proxy.https port 8000
$ gsettings set org.gnome.system.proxy.ftp host 'my.proxy.com'
$ gsettings set org.gnome.system.proxy.ftp port 8000

To change Socks host settings to manual:

$ gsettings set org.gnome.system.proxy.socks host 'my.proxy.com'
$ gsettings set org.gnome.system.proxy.socks port 8000

All these changes above are limited to the current Desktop user only. If you want to apply the proxy setting changes system-wide, prepend sudo to gsettings command. For example:

$ sudo gsettings set org.gnome.system.proxy.http host 'my.proxy.com'
$ sudo gsettings set org.gnome.system.proxy.http port 8000
$ sudo gsettings set org.gnome.system.proxy mode 'manual'

Change System Proxy Setting to Automatic from the Command Line

If you are using proxy auto configuration (PAC), type the following commands to switch to PAC.

$ gsettings set org.gnome.system.proxy mode 'auto'
$ gsettings set org.gnome.system.proxy autoconfig-url http://my.proxy.com/autoproxy.pac

Clear System Proxy Setting from the Command Line

Finally, to remove manual/automatic proxy setting, and revert to no-proxy setting:

$ gsettings set org.gnome.system.proxy mode 'none'

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean