Jeremias Adriano
Posted on July 25, 2024
Whether for learning, testing, or professional purposes, you might find yourself needing to configure a proxy. In this article, I'll guide you through setting up a proxy for Docker, APT, and SSH. These configurations are crucial to ensure these tools work properly in environments where a proxy is necessary.
Configuring Proxy for Docker
To configure Docker to use a proxy, follow these steps:
-
Create a proxy configuration file within Docker's directory:
sudo mkdir -p /etc/systemd/system/docker.service.d sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf
-
Add the following lines to the configuration file:
[Service] Environment="HTTP_PROXY=http://proxy:port" Environment="HTTPS_PROXY=http://proxy:port" Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"
HTTP_PROXY is used for HTTP connections.
HTTPS_PROXY is used for HTTPS connections.
NO_PROXY specifies addresses that should bypass the proxy (e.g., localhost and 127.0.0.1). -
Reload the systemd configuration and restart Docker:
sudo systemctl daemon-reload sudo systemctl restart docker
Source: Docker Documentation
Configuring Proxy for APT
To configure APT to use a proxy, follow these steps:
-
Create and edit the proxy configuration file within apt directory:
sudo nano /etc/apt/apt.conf.d/proxy.conf
-
Add the following lines to the configuration file:
Acquire { HTTP::proxy "http://proxy:port"; HTTPS::proxy "http://proxy:port"; }
HTTP::proxy is used for HTTP connections.
HTTPS::proxy is used for HTTPS connections. -
Update your system repositories to apply the new proxy settings:
sudo apt update
Configuring Proxy for SSH
To configure SSH to use a proxy, follow these steps:
-
Install
corkscrew
:
sudo apt install corkscrew
-
Add the following lines into
~/.ssh/config
file:
Host github.com Hostname github.com ServerAliveInterval 55 ForwardAgent yes ProxyCommand /usr/bin/corkscrew YourProxy YourPort %h %p
Host specifies the alias for the SSH connection. Replace github.com with the actual host if different.
Hostname specifies the actual hostname of the server you are connecting to.
ServerAliveInterval ensures that the connection remains active by sending keep-alive messages.
ForwardAgent enables forwarding of the SSH authentication agent to the remote server.
ProxyCommand uses corkscrew to route SSH traffic through the specified proxy. Replace YourProxy and YourPort with the address and port of your proxy server.
Posted on July 25, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.