netselect-apt
Find fastest Debian/Ubuntu mirror for apt
TLDR
Create sources.list using the lowest latency server
Specify Debian branch, stable is used by default
Include non-free section
Specify a country for the mirror list lookup
SYNOPSIS
netselect-apt [options] [mirror_protocol] [mirror_name]
PARAMETERS
-s
Search for mirrors providing the unstable (sid) distribution instead of stable.
-u
Search for mirrors providing the testing distribution instead of stable.
-o
Write the generated sources.list entry to the specified file instead of standard output.
-c
Limit the search for mirrors to a specific country, e.g., US, DE, FR.
-l
Specify the number of fastest mirrors to select and include in the output. Default is 1.
-n
Use the mirror list provided in the specified file instead of the default Debian mirrors list.
-t
Set the number of tests (pings) to perform per host to determine its score. Default is 2.
-r
Set the number of rounds of testing to perform. Default is 1.
-v
Enable verbose output, showing more details about the mirror selection process.
-x
Exclude specified hosts (comma-separated) from the mirror selection process. Example: mirror1.org,mirror2.net.
-i
Include only specified hosts (comma-separated) in the mirror selection process. Example: mirror3.com,mirror4.edu.
-p
Output only the mirror URL, not the full sources.list line.
-w
Do not output comments in the generated sources.list entry.
--version
Display the program's version information and exit.
--help
Display a help message with usage information and exit.
Optional: The protocol to use for the mirror, e.g., http (default), ftp, https. Applies only when a specific
Optional: The base name of the mirror site (e.g., ftp.debian.org). When provided, netselect-apt attempts to select from its known sub-mirrors or directly test it.
DESCRIPTION
netselect-apt is a utility designed to help Debian and Ubuntu users find the fastest APT (Advanced Package Tool) mirrors for their system. It leverages the netselect program to ping and benchmark various archive mirrors, calculating their scores based on network latency and packet loss. By identifying the mirror with the lowest score (indicating best performance), it generates an optimized sources.list entry, ensuring quicker package downloads and updates. This command is particularly useful for users looking to improve the speed and reliability of their package management operations, leading to faster updates and package installations.
CAVEATS
Network conditions are dynamic; a fast mirror today might be slow tomorrow. It's advisable to re-run netselect-apt periodically for optimal results.
The tool relies on netselect which performs ping-like tests. Firewalls or network configurations blocking ICMP might affect its accuracy.
While netselect-apt can suggest HTTP mirrors, it's generally recommended to use HTTPS mirrors for enhanced security. Users should verify and adjust protocols in their sources.list if needed.
Some mirrors might be geographically close but have poor routing, leading to higher latency despite proximity.
UPDATING SOURCES.LIST
After running netselect-apt, the output (either to standard output or a file) typically contains a 'deb' line for your sources.list. You need to manually update your /etc/apt/sources.list file or create a new file (e.g., fast-mirror.list) in /etc/apt/sources.list.d/ with this content.
Example: sudo netselect-apt -c US > /etc/apt/sources.list.d/fast-mirror.list
Remember to run sudo apt update
after modifying sources.list to refresh your package lists.
UNDERLYING MECHANISM
netselect-apt relies heavily on the netselect command. netselect calculates a "score" for each host based on a combination of ping times and packet loss. A lower score indicates a better, faster mirror. netselect-apt parses the mirror lists, feeds them to netselect, and then formats the result into an APT-compliant sources.list entry.
HISTORY
netselect-apt was developed as a helper script for netselect, a tool designed to measure network performance between a local host and multiple remote hosts. Its purpose was to automate the often tedious process of finding the optimal APT mirror for Debian and later Ubuntu distributions. It simplifies the sources.list configuration by directly generating the relevant entry based on performance metrics. Its development reflects the ongoing need for efficient package management in distributed systems, ensuring users connect to the closest and most responsive mirrors for faster updates and package downloads.