Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any plug-in available for apt-get to select fast mirror just as the YUM's fastestmirror plugin The fastest mirror plugin is designed for use in repository configurations where you have more than 1 mirror in a repo configuration. It makes a connection to each mirror, timing the connection and then sorts the mirrors by fastest to slowest for use by yum.

Reason: I added several (intranet and internet ) mirrors in apt's config file, and I want apt-get use intranet mirror when I am at office, and internet mirror at home.

share|improve this question
up vote 1 down vote accepted

As a workaround, you could write a script that checks which network you are connected to and changes /etc/apt/sources.list accordingly. Something like the script below, just edit it to suit your needs.

First, make a backup of your /etc/apt/sources.list. Then, create two sources.list files, one for your home and one for the office. Let's assume they are called and sources.home.list. Save both of them in /etc/apt/.

Now, edit the following script to suit your needs save it (for this example, I am assuming you will save it as ~/bin/, and make it executable by running this command :

$ chmod +x ~/bin/

The script:

ip=ifconfig | grep Bcast | cut -d " " -f 12

## Set this for your office IP
if [ $ip == "XXX.XXX.XXX.XXX" ]
    cp /etc/apt/ /etc/apt/sources.list 
    cp /etc/apt/sources.home.list /etc/apt/sources.list 

Now, edit the file etc/rc.local and add this line to the end of the file, before exit(0):


Obviously, change the path above to reflect the path to the script you just created.

The next time you reboot, the script should be run and automatically choose the correct sources.list file.

EDIT: If you want to have both repositories accessible at all times, and download a given package from the fastest, if present, you just need to change the order of the repos in the sources.list. Follow the procedure I suggested above, simply make it so that the relevant lines in /etc/apt/ are like this:

deb http://fastest.mirror.for.home

and in /etc/apt/sources.home.list like this:

deb http://fastest.mirror.for.home

If a package exists with the same version in both repositories, apt will download from the first.

NOTE1: If the versions are different, apt will get the newest irrespective of the order the repositories are in.

NOTE2: This does not check the download speed of the repos. You have to do that yourself. To find the fastest mirror you can try using netselect-apt:

sudo apt-get install netselect-apt

Package netselect-apt:

speed tester for choosing a fast Debian mirror

This package provides a utility that can choose the best Debian mirror by downloading the full mirror list and using netselect to find the fastest/closest one.

share|improve this answer
Thanks very much terdon. I exported http.proxy variable and both internet and intranet mirror accessible in office, I still want keep internet mirror in the source list in case local mirror don't have the package wanted. is there any solution to test connectivity speed and select the fasted just as fastestmirror did. – Ted Aug 20 '12 at 16:17
@Ted I updated the answer, this should be what you need. – terdon Aug 20 '12 at 16:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.