Ubuntu/RDK Development Proxy Configuration: Automatic Switching and LAN Access
A practical Ubuntu and RDK proxy setup with automatic detection, manual controls, sudo environment inheritance, and troubleshooting for apt, Git, curl, and ROS.
In Ubuntu and RDK development environments, a proxy often serves apt, Git, curl, ROS packages, and Python dependencies at the same time. A proxy device on the local network may change with the network environment, so fixed shell variables can interfere with offline work, LAN communication, and device debugging.
This article combines an automatic Ubuntu Shell proxy script with the RDK LAN proxy variables into one configuration: the terminal checks the proxy port when it starts and enables the proxy when the port is available. LAN device addresses are added to NO_PROXY so that SSH, ROS nodes, and WebSocket connections stay direct. All host, port, and RDK address examples use placeholders; fill them in for the actual network before deployment.
- Ubuntu desktop or an RDK board running Bash.
- A proxy service running on another computer or gateway on the same LAN.
- A need to let apt, Git, curl, or ROS tools read proxy environment variables.
- Frequent switching between a proxied network and a regular network.
First confirm the current shell:
echo "$SHELL"ps -p "$$" -o comm=This configuration is written to ~/.bashrc. When an RDK image uses another shell, put the same functions in that shell’s startup file and validate the syntax for that shell.
| Variable | Purpose |
|---|---|
| HTTP_PROXY, HTTPS_PROXY | Provide an HTTP/HTTPS proxy to clients |
| ALL_PROXY | Provide a SOCKS5 proxy to programs that support the variable |
| NO_PROXY | Keep local, LAN, and RDK addresses on a direct connection |
| PROXY_HOST | Address of the LAN proxy device |
| HTTP_PORT, SOCKS5_PORT | HTTP and SOCKS5 service ports |
Setting both uppercase and lowercase variables improves compatibility across programs. Processes launched by apt, Git, curl, and ROS inherit the exported variables from the current shell.
Automatic detection uses nc from netcat-openbsd:
sudo apt updatesudo apt install netcat-openbsdnc -hWhen installing this package for the first time without a proxy, use an accessible package source temporarily or configure the proxy in the system network settings first.
By default, sudo removes some environment variables. Create /etc/sudoers.d/proxy:
sudoedit /etc/sudoers.d/proxyWrite:
Defaults env_keep += "http_proxy https_proxy HTTP_PROXY HTTPS_PROXY all_proxy ALL_PROXY no_proxy NO_PROXY"Set the owner and permissions, then validate the sudoers syntax:
sudo chown root:root /etc/sudoers.d/proxysudo chmod 0440 /etc/sudoers.d/proxysudo visudo -cThe expected output includes:
/etc/sudoers: parsed OK/etc/sudoers.d/proxy: parsed OKFiles under /etc/sudoers.d/ need the root:root owner and 0440 permissions, or sudo may refuse to read them.
Edit ~/.bashrc:
nano ~/.bashrcAppend the following code. Replace PROXY_HOST, HTTP_PORT, SOCKS5_PORT, and RDK_HOST first. Keeping the placeholders temporarily is useful for checking the script structure.
# =========================# Ubuntu/RDK network proxy# =========================
PROXY_SCHEME="http"PROXY_HOST="<PROXY_HOST>"HTTP_PORT="<HTTP_PORT>"SOCKS5_PORT="<SOCKS5_PORT>"RDK_HOST="<RDK_IP>"
# auto: check the proxy port, system proxy, or TUN; port: check only the proxy port# system: check the system proxy and use the proxy above; tun: check TUN and use the proxy above# off: do not change proxy variables while reading ~/.bashrcPROXY_AUTO_MODE="auto"
proxy_configured() { [ -n "$PROXY_HOST" ] && [ "$PROXY_HOST" != "<PROXY_HOST>" ] && [ -n "$HTTP_PORT" ] && [ "$HTTP_PORT" != "<HTTP_PORT>" ]}
proxy_port_available() { proxy_configured || return 1 command -v nc >/dev/null 2>&1 || return 1 nc -z -w1 "$PROXY_HOST" "$HTTP_PORT" >/dev/null 2>&1}
proxy_system_enabled() { command -v gsettings >/dev/null 2>&1 || return 1 local mode mode=$(gsettings get org.gnome.system.proxy mode 2>/dev/null) case "$mode" in ""|*none*) return 1 ;; *) return 0 ;; esac}
proxy_tun_enabled() { command -v ip >/dev/null 2>&1 || return 1 ip -o link show 2>/dev/null | awk -F': ' '{print $2}' | cut -d@ -f1 | grep -Eq '^(tun|tap|wg|tailscale|zt)'}
proxy_network_enabled() { proxy_port_available || proxy_system_enabled || proxy_tun_enabled}
proxy_on() { if ! proxy_configured; then [ "${1:-}" = "--quiet" ] || echo "Please configure PROXY_HOST and HTTP_PORT first." return 1 fi
export http_proxy="$PROXY_SCHEME://$PROXY_HOST:$HTTP_PORT" export https_proxy="$PROXY_SCHEME://$PROXY_HOST:$HTTP_PORT" export HTTP_PROXY="$PROXY_SCHEME://$PROXY_HOST:$HTTP_PORT" export HTTPS_PROXY="$PROXY_SCHEME://$PROXY_HOST:$HTTP_PORT"
if [ -n "$SOCKS5_PORT" ] && [ "$SOCKS5_PORT" != "<SOCKS5_PORT>" ]; then export all_proxy="socks5h://$PROXY_HOST:$SOCKS5_PORT" export ALL_PROXY="socks5h://$PROXY_HOST:$SOCKS5_PORT" else unset all_proxy ALL_PROXY fi
# NO_PROXY wildcard support depends on the client; RDK_HOST explicitly keeps the device direct. export no_proxy="localhost,127.0.0.1,::1,$RDK_HOST,10.*,192.168.*,172.*" export NO_PROXY="$no_proxy"
if [ "${1:-}" != "--quiet" ]; then echo "Proxy enabled" echo "HTTP proxy: $http_proxy" if [ -n "$all_proxy" ]; then echo "SOCKS5 proxy: $all_proxy" else echo "SOCKS5 proxy: disabled" fi fi}
proxy_off() { unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY unset all_proxy ALL_PROXY no_proxy NO_PROXY if [ "${1:-}" != "--quiet" ]; then echo "Proxy disabled" fi}
proxy_status() { if proxy_system_enabled; then echo "System proxy: ON" else echo "System proxy: OFF" fi
if proxy_tun_enabled; then echo "TUN route : ON" else echo "TUN route : OFF" fi
if proxy_port_available; then echo "Proxy port : ON ($PROXY_HOST:$HTTP_PORT)" else echo "Proxy port : OFF ($PROXY_HOST:$HTTP_PORT)" fi
if [ -n "$http_proxy" ]; then echo "Shell proxy : ON" echo "HTTP proxy : $http_proxy" echo "HTTPS proxy : $https_proxy" if [ -n "$all_proxy" ]; then echo "SOCKS5 proxy: $all_proxy" else echo "SOCKS5 proxy: disabled" fi else echo "Shell proxy : OFF" fi}
case "$PROXY_AUTO_MODE" in auto) if proxy_network_enabled && proxy_port_available; then proxy_on --quiet else proxy_off --quiet fi ;; port) if proxy_port_available; then proxy_on --quiet else proxy_off --quiet fi ;; system) if proxy_system_enabled && proxy_port_available; then proxy_on --quiet else proxy_off --quiet fi ;; tun) if proxy_tun_enabled && proxy_port_available; then proxy_on --quiet else proxy_off --quiet fi ;; off) ;; *) echo "Unknown PROXY_AUTO_MODE: $PROXY_AUTO_MODE" ;;esacReload the file:
source ~/.bashrcproxy_statusManual controls:
proxy_onproxy_offproxy_statusproxy_on and proxy_off affect the current shell and its child processes. Opening a new terminal runs the automatic logic again.
env | grep -i proxycurl -I --max-time 10 https://example.comUse verbose mode to inspect the CONNECT or SOCKS5 handshake:
curl -vI --max-time 10 https://example.comsudo env | grep -i proxysudo apt updatecurl --noproxy '*' -I --max-time 5 http://$RDK_HOST:8000ssh <RDK_USER>@$RDK_HOSTThe device address used by ROS, SSH, the camera page, and the rosbridge WebSocket should be listed in NO_PROXY. Test LAN services with curl –noproxy ‘*’ to isolate proxy rules from connectivity problems.
The proxy mainly serves public dependency downloads:
- apt update and apt install retrieve Ubuntu, ROS, or RDK packages.
- Git clones and pulls access remote repositories.
- curl, wget, and Python package managers access external addresses.
RDK SSH, the camera page, the rosbridge WebSocket, and LAN ROS communication need direct connections. Keeping RDK_HOST and the LAN ranges in NO_PROXY allows the proxy variables to remain active for public requests.
nc only proves that the TCP port accepts a connection. The proxy service still needs the correct protocol. Use http:// for an HTTP proxy and socks5h:// for a SOCKS5 proxy. Check the proxy application’s listening address, port, and access controls.
Check in this order:
proxy_statussudo env | grep -i proxysudo visudo -csudo apt -o Debug::Acquire::http=true updateSome apt versions can also use a separate proxy file under /etc/apt/apt.conf.d/. This configuration starts with environment variables so proxy_on and proxy_off control the complete shell setup consistently.
Check that NO_PROXY contains the current RDK IP, hostname, and local network range. Client support for wildcards and CIDR notation varies, so the most reliable approach is to put the exact RDK IP in RDK_HOST.