How to find a fastest Debian Linux mirror for your /etc/apt/sources.list

Having a slow Debian mirror can be frustrating and thus it is always best to choose closest mirror to your geographical location as possible. Even your best guess may not always bring good results. Fortunately netselect-apt command line tool is here to help you find the fastest mirror available.
Here is the basic idea:

finding a fastest debian mirror

As you can see on the above image 87.0 kB/s is rather disappointing. Let’s try to change that using netselect-apt faster mirror locator tool. Installation is simple:

# apt-get install netselect-apt

Next we are going to find a fastest mirror located in Australia -c, we will compare results from 15 sites -t if available, the architecture must be amd64 -a and the version we are looking for is testing:

# netselect-apt -c australia -t 15 -a amd64 -n testing
Using distribution testing.
Retrieving the list of mirrors from www.debian.org...

--2015-01-29 19:33:12--  http://www.debian.org/mirror/mirrors_full
Resolving www.debian.org (www.debian.org)... 140.211.15.34, 128.31.0.62
Connecting to www.debian.org (www.debian.org)|140.211.15.34|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 353167 (345K) [text/html]
Saving to: ‘/tmp/netselect-apt.vPhJid’

/tmp/netselect-apt.vPhJid           100%[===============>] 344.89K   445KB/s   in 0.8s   

2015-01-29 19:33:14 (445 KB/s) - ‘/tmp/netselect-apt.vPhJid’ saved [353167/353167]

Choosing a main Debian mirror using netselect.
(will filter only for mirrors in country australia)
netselect: 8 (8 active) nameserver request(s)...         
Duplicate address 218.100.43.30 (http://mirror.waia.asn.au/debian/,
http://ftp.au.debian.org/debian/); keeping only under first name.
Running netselect to choose 15 out of 12 addresses.     
.............................................................................................................................
Only found 12 hosts out of 15 requested.
The fastest 15 servers seem to be:

        http://debian.mirror.uber.com.au/debian/
        http://debian.mirror.serversaustralia.com.au/debian/
        http://mirror.optus.net/debian/
        http://mirror.overthewire.com.au/debian/
        http://mirror.crucial.com.au/debian/
        http://mirror.eftel.com/debian/
        http://mirror.as24220.net/pub/debian/
        http://ftp.iinet.net.au/debian/debian/
        http://mirror.waia.asn.au/debian/
        http://ftp.monash.edu.au/pub/linux/debian/
        http://mirror.cse.unsw.edu.au/debian/                                                                                                   
        http://mirror.linux.org.au/debian/                                                                                                      
                                                                                                                                                
Of the hosts tested we choose the fastest valid for HTTP:                                                                                       
        http://debian.mirror.uber.com.au/debian/                                                                                                
                                                                                                                                                
Writing sources.list.                                                                                                                           
Done.


Based on the output of the above command we can see that netselect-apt found only 12 mirrors from which the best choice is http://debian.mirror.uber.com.au/debian/. netselect-apt also created a sources.list file in the current working directory for your consideration. If netselect-apt command is run from the actual /etc/apt/ directory it will output your sources list file with a random suffix such as sources.list exists, moving to sources.list.1422520852.

Alternatively you can run netselect-apt command with fewer options:

# netselect-apt testing

or simply as:

# netselect-apt

in which case the default Debian version will be stable. Once you have your sources.list generated you can include the resulting mirror in your system’s sources.list by:

# cp /etc/apt/sources.list /etc/apt/sources.list_backup
# mv sources.list /etc/apt/sources.list

Or only add the resulting line to your current /etc/apt/sources.list. Let’s see the result

found fastest debian mirror