Ubuntu

How to Change System Proxy Settings from the Command Line on Ubuntu Desktop?

Changing the proxy on the Ubuntu server is useful since it helps you improve the network performance of the system. Further, it helps you control internet usage, prevent server crashes, and provide better security and faster page loading time. Although it is very easy to change the proxy settings for Ubuntu desktop using the GUI method while using the terminal if a user wants to change the proxy settings it might become an uncomfortable situation to close the terminal and switch to GUI just to change the proxy.

This article will present you with the command line method to change proxy settings on the Ubuntu desktop.

Change Ubuntu Desktop Proxy Settings from the Command Line

To change the system proxy setting in Ubuntu by using the command line, we will use the gsettings. The gsettings is a command line tool which is used in Ubuntu to modify the database settings. gsettings in Ubuntu enable users to monitor or set keys for changes; It is used to manage applications’ settings

To change the proxy settings on the Ubuntu system, use the below-mentioned command to run the gsettings tool:

gsettings

Once the gsetting tool is started, you can easily change the proxy settings by following the syntax of the below-mentioned commands:

gsettings set org.gnome.system.proxy. host '<host server name or IP>'
gsettings set org.gnome.system.proxy.<proxy name> port <port number>

Now I will use the above commands to change the proxy settings for each; HTTP, HTTPS, FTP and Socks.

For “HTTP” Proxy

HTTP proxy is used to identify suspicious web content that is coming from a non-trusted source. It is required in Ubuntu to protect the HTTP server from miscellaneous attacks. To set up the HTTP proxy settings, run the below-mentioned commands to determine the host (server name or IP) and port for HTTP:

gsettings set org.gnome.system.proxy.http host '192.168.18.67'

Note: Here, I have used the IP address as host but that is just an example IP.

The below-mentioned command determines the port for http proxy:

gsettings set org.gnome.system.proxy.http port 8000

To verify that the http proxy is changed/updated successfully;

echo "$http_proxy"

For “HTTPS” Proxy

Hypertext Transfer Protocol over Secure Socket (HTTPS) is basically a request protocol between server and clients to provide a secure transaction and communication for users. To determine the host for https proxy, run the below-mentioned command:

gsettings set org.gnome.system.proxy.https host '192.168.18.67'

After that determine the port for HTTPS by using the below-mentioned command:

gsettings set org.gnome.system.proxy.https port 8000

Then verify by using the below-mentioned command:

echo "$https_proxy"

For “FTP” Proxy

FTP proxy acts as a bridge/relay to transfer files between source and destination. Its performance is better for larger files than HTTP. To change the FTP proxy, run the below-mentioned commands to determine both the host and port on the Ubuntu system:

gsettings set org.gnome.system.proxy.ftp host '192.168.18.67'

gsettings set org.gnome.system.proxy.ftp port 8000

Then verify, by using the below-mentioned echo command

echo "$ftp_proxy"

For “Socks” Proxy

SOCKS proxy facilitates communication between servers by using a firewall, it supports routing any type of traffic generated by any program or protocol. Similar to all of the above, the socks proxy can also be changed with the gsetting tool and for that, use the below-mentioned commands:

gsettings set org.gnome.system.proxy.socks host '192.168.18.67'

gsettings set org.gnome.system.proxy.socks port 8000

For example;

echo "$all_proxy"

How to Change System Wide Proxy Settings?

All the above-mentioned commands will change the proxy setting for the current user, but if you want to imply same proxy changes system-wide then run all the commands with sudo to have administrative permission to change the system proxy:

sudo gsettings

Just to quote the example; here I have only changed the “http” proxy setting for the whole system. You can change your desired proxy settings for the complete system by following the same commands mentioned in the previous section just remember to use “sudo” with them:

sudo gsettings set org.gnome.system.proxy.http host '192.168.18.67'

sudo gsettings set org.gnome.system.proxy.http port 8000

How to Switch the Proxy Mode?

There are three proxy setting modes in the Ubuntu system and those are:

1: “Auto” mode

Run the below-mentioned commands to switch the proxy mode to “auto mode”, this is useful if you are using PAC (Proxy Auto-Config) in Ubuntu.

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

Switch to auto mode through the following command:

gsettings set org.gnome.system.proxy mode 'auto'

2: “Manual” mode

The manual mode is used if you want to manually change each proxy settings as we did in the first two sections of this article.

gsettings set org.gnome.system.proxy mode 'manual'

3: None

If you do not want any proxy changes being applied to your system then you can clear all proxy settings by using the below-mentioned command:

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

Conclusion

To change the system proxy setting in Ubuntu through the command line, the gsetting tool is used. All the proxy settings can be modified/changed with the gsetting tool. The command and syntaxes for each proxy setting are discussed in the above-mentioned guidelines. The proxy modes “auto”, “manual” and “none” are also discussed above along with commands for each mode.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.