1. Package Managers
1.1 apt
Debian’s repository configuration file is /etc/apt/sources.list.
# Uncomment to enable official repository
# deb https://deb.debian.org/debian/ trixie main contrib non-free non-free-firmware
# deb https://deb.debian.org/debian/ trixie-updates main contrib non-free non-free-firmware
# deb https://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware
# Comment to disable mirror
deb <mirror>/ trixie main contrib non-free non-free-firmware
deb <mirror>/ trixie-updates main contrib non-free non-free-firmware
deb https://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware
After changing the configuration, run:
# Refresh package index
sudo apt update
Some mirrors:
| Mirror | Debian URL |
|---|---|
| TUNA | https://mirrors.tuna.tsinghua.edu.cn/debian |
1.2 dnf
Fedora’s repository configuration files are /etc/yum.repos.d/fedora.repo and /etc/yum.repos.d/fedora-updates.repo.
/etc/yum.repos.d/fedora.repo:
# Fedora main repository
[fedora]
name=Fedora $releasever - $basearch
baseurl=<mirror>/releases/$releasever/Everything/$basearch/os/
enabled=1
countme=1
metadata_expire=7d
repo_gpgcheck=0
type=rpm
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False
# Fedora debug repository, disabled by default
[fedora-debuginfo]
name=Fedora $releasever - $basearch - Debug
baseurl=<mirror>/releases/$releasever/Everything/$basearch/debug/tree/
enabled=0
metadata_expire=7d
repo_gpgcheck=0
type=rpm
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False
# Fedora source repository, disabled by default
[fedora-source]
name=Fedora $releasever - Source
baseurl=<mirror>/releases/$releasever/Everything/source/tree/
enabled=0
metadata_expire=7d
repo_gpgcheck=0
type=rpm
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False
/etc/yum.repos.d/fedora-updates.repo:
# Fedora updates repository
[updates]
name=Fedora $releasever - $basearch - Updates
baseurl=<mirror>/updates/$releasever/Everything/$basearch/
enabled=1
countme=1
repo_gpgcheck=0
type=rpm
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False
# Updates debug repository, disabled by default
[updates-debuginfo]
name=Fedora $releasever - $basearch - Updates - Debug
baseurl=<mirror>/updates/$releasever/Everything/$basearch/debug/
enabled=0
repo_gpgcheck=0
type=rpm
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False
# Updates source repository, disabled by default
[updates-source]
name=Fedora $releasever - Updates Source
baseurl=<mirror>/updates/$releasever/Everything/source/tree
enabled=0
repo_gpgcheck=0
type=rpm
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False
After changing the configuration, run:
# Refresh repository metadata
sudo dnf makecache
# Show enabled repositories and their baseurl
dnf repolist -v
Some mirrors:
| Mirror | Fedora URL |
|---|---|
| Aliyun | https://mirrors.aliyun.com/fedora |
2. Terminal
#!/usr/bin/env bash
# http_proxy is used for HTTP, and https_proxy is used for HTTPS.
# Use http://127.0.0.1:7890 as the example proxy address.
export http_proxy=http://127.0.0.1:7890
export https_proxy=$http_proxy
# Remove the proxy from the current shell.
unset http_proxy https_proxy
# Functions to enable/disable proxy.
enable_proxy() {
export http_proxy=http://127.0.0.1:7890
export https_proxy=$http_proxy
}
disable_proxy() {
unset http_proxy https_proxy
}
3. Git
PROXY=http://127.0.0.1:7890
git config --global http.proxy "$PROXY"
# Only set github to use proxy
git config --global http.https://github.com.proxy "$PROXY"
# Show the current proxy configuration.
git config --global --get-regexp 'proxy'
# Use these two lines to remove the proxy.
git config --global --unset http.proxy
git config --global --unset http.https://github.com.proxy
#!/usr/bin/env bash
# srv_ip is a remote IP address, and local_ip is the local IP address.
srv_ip=192.168.1.2
local_ip=127.0.0.1
proxy_port=7890
proxy=
# Connect to the server proxy if available.
if nc -z "$srv_ip" "$proxy_port"; then
proxy=$srv_ip
elif nc -z "$local_ip" "$proxy_port"; then
proxy=$local_ip
fi
# Enable proxy if it works
if [ -n "$proxy" ]; then
git config --global http.proxy "http://$proxy:$proxy_port"
else
git config --global --unset http.proxy
fi
4. npm
#!/usr/bin/env bash
npm config set registry <mirror>
# Show the current registry.
npm config get registry
# List all configurations
npm config list
| Mirror | Registry URL |
|---|---|
| Tencent Cloud | https://mirrors.cloud.tencent.com/npm/ |
5. Ruby
5.1 gem
#!/usr/bin/env bash
# Change the RubyGems source with gem sources.
# Add the <mirror> mirror and remove the official source.
gem sources \
--add <mirror> \
--remove https://rubygems.org/
# Only the mirror should remain.
gem sources -l
# Restore the official source.
# gem sources \
# --add https://rubygems.org/ \
# --remove <mirror>
5.2 Bundler
#!/usr/bin/env bash
# Set the global mirror for <mirror>.
bundle config set --global mirror.https://rubygems.org <mirror>
# Show the configuration.
bundle config list
# Check the active mirror.
bundle config get mirror.https://rubygems.org
# Remove the mirror.
# bundle config unset --global mirror.https://rubygems.org
Available mirrors:
| Mirror | RubyGems URL |
|---|---|
| TUNA | https://mirrors.tuna.tsinghua.edu.cn/rubygems/ |
6. Docker
Docker in the Fedora repositories is provided by moby-engine.
#!/usr/bin/env bash
# Fedora repositories provide moby-engine to replace docker
sudo dnf install -y moby-engine
# Enable Docker at boot.
sudo systemctl enable docker
Docker image pulls are handled by dockerd, so configure the proxy for dockerd.
Add environment variables to docker.service:
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf >/dev/null <<'EOF'
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890"
Environment="HTTPS_PROXY=http://127.0.0.1:7890"
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
Confirm the configuration:
systemctl show --property=Environment docker
docker info | grep -i proxy
Verify with hello-world:
docker pull hello-world
7. Desktop Environments: GNOME and KDE
| Desktop | Entry point | Configuration |
|---|---|---|
| GNOME | Settings -> Network -> Network Proxy | Choose “Manual” and fill in HTTP/HTTPS/SOCKS |
| KDE Plasma | System Settings -> Network -> Proxy | Choose “Manually specify proxy settings” and fill in HTTP/HTTPS/SOCKS |
8. Firefox and Chromium
Firefox. The GUI path is Settings -> General -> Network Settings -> Settings.
Chromium. Chromium only inherits the desktop system proxy.
9. Clash
Clash is no longer maintained.
Clash is a proxy client written in Go.
The user configuration directory is ~/.config/clash/.
The system-level configuration uses /etc/clash/.
9.1 User-Space Run
Put config.yaml in ~/.config/clash/ and start Clash with -d to specify the configuration directory:
mkdir -p ~/.config/clash
cp config.yaml ~/.config/clash/
clash -d ~/.config/clash
9.2 LAN Sharing
Enable allow-lan in config.yaml:
allow-lan: true
bind-address: '*'
bind-address set to '*' listens on all interfaces.