How to Check and Configure Proxy Settings on an Ubuntu Server

If you’re working with an Ubuntu server, you might need to configure or check the proxy settings to ensure that your server can connect to the internet or internal networks properly. This guide will walk you through the steps to verify and set up proxy settings on an Ubuntu server.

1. Checking Proxy Settings

a. Check Environment Variables

One of the most common ways to configure proxy settings in Ubuntu is by using environment variables. These variables are used by various command-line tools to determine if they should route traffic through a proxy server.

To check the current proxy settings, you can inspect the following environment variables:

     To check the current proxy settings

echo $http_proxy

echo $https_proxy

echo $ftp_proxy

echo $no_proxy

These commands will display the current proxy settings for HTTP, HTTPS, FTP, and the list of addresses that should bypass the proxy (no_proxy).

b. Check apt Proxy Configuration

If you are using apt for package management, it might be configured to use a proxy. You can check the proxy settings for apt by inspecting the configuration file:

Check apt Proxy Configuration

cat /etc/apt/apt.conf.d/95proxies

If a proxy is configured, you will see something like:

If a proxy is configured

Acquire::http::Proxy "http://username:password@proxy-server:port/";

Acquire::https::Proxy "https://username:password@proxy-server:port/";

2. Setting Up a Proxy

If you need to set up a proxy on your Ubuntu server, you can do so by setting the appropriate environment variables or by configuring specific applications like apt.

a. Setting Environment Variables

To set the proxy environment variables temporarily, use the export command:

Setting Environment Variables

export http_proxy="http://username:password@proxy-server:port/"

export https_proxy="https://username:password@proxy-server:port/"

export ftp_proxy="ftp://username:password@proxy-server:port/"

export no_proxy="localhost,127.0.0.1,::1"

To make these changes permanent, add them to your shell’s configuration file, such as ~/.bashrc or /etc/environment for system-wide settings:

echo 'export http_proxy="http://username:password@proxy-server:port/"' >> ~/.bashrc

echo 'export https_proxy="https://username:password@proxy-server:port/"' >> ~/.bashrc

echo 'export ftp_proxy="ftp://username:password@proxy-server:port/"' >> ~/.bashrc

echo 'export no_proxy="localhost,127.0.0.1,::1"' >> ~/.bashrc

After editing .bashrc, apply the changes by running:

source ~/.bashrc

For system-wide settings, edit /etc/environment:

sudo nano /etc/environment

Add the following lines:

http_proxy="http://username:password@proxy-server:port/"

https_proxy="https://username:password@proxy-server:port/"

ftp_proxy="ftp://username:password@proxy-server:port/"

no_proxy="localhost,127.0.0.1,::1"

After saving the file, apply the changes:

source /etc/environment

b. Setting Proxy for apt

To configure apt to use a proxy, create or edit the 95proxies file:

Setting Proxy for apt

sudo nano /etc/apt/apt.conf.d/95proxies

Add the following lines:

 
Acquire::http::Proxy "http://username:password@proxy-server:port/";
Acquire::https::Proxy "https://username:password@proxy-server:port/";

3. Testing Proxy Configuration

To ensure that your proxy configuration is working, you can use a few different commands:

  • Curl:
  • Curl

    curl -I http://example.com

  • Apt:
    sudo apt update

If everything is configured correctly, these commands should execute without errors.

4. Troubleshooting Proxy Issues

If you encounter issues while configuring the proxy, consider the following:

  • Credentials: Ensure that the username and password for the proxy are correct.
  • Proxy Server: Verify that the proxy server is reachable from your Ubuntu server.
  • Firewall: Check if any firewall settings are blocking the proxy connection.

Conclusion

Configuring a proxy on your Ubuntu server is a straightforward process that can be done through environment variables or specific application configurations like apt. By following the steps outlined in this guide, you can easily set up and verify proxy settings to ensure smooth network operations on your server.

How to Check and Configure Proxy Settings on an Ubuntu Server (F.A.Q)

How do I check if my Ubuntu server is using a proxy?

You can check the proxy settings by inspecting environment variables such as http_proxy, https_proxy, ftp_proxy, and no_proxy using the echo command. Additionally, check the proxy configuration for apt by viewing the /etc/apt/apt.conf.d/95proxies file.

How can I temporarily set a proxy on my Ubuntu server?

Use the export command to set proxy environment variables temporarily. For example: export http_proxy="http://proxy-server:port/". These settings will last only for the current session.

How do I make proxy settings permanent on my Ubuntu server?

Add the proxy environment variables to your shell configuration file (e.g., ~/.bashrc) or to the /etc/environment file for system-wide settings. This ensures the proxy is set up each time the server starts.

What should I do if the proxy settings are not working?

Double-check the proxy server address, port, and credentials. Ensure the server can reach the proxy and that no firewall settings are blocking the connection. Also, verify that the environment variables are correctly set and applied.