I'm using apt-cacher-ng at my local network with the following configuration on the clients:

Acquire::http { Proxy "http://acng-host:3142"; };

Some of the clients are laptops, so how do I configure them to use the cache only when it's available on this network?

3 Answers 3


From the server you can announce to the network there is an apt-cacher-ng instance through avahi

From the client you can check if exist an apt-cacher-ng service and modify apt proxy settings accordly.



$ sudo apt-get install apt-cacher-ng squid-deb-proxy-client

For Ubuntu releases older than 14.04 put the following snippet in /etc/avahi/services/apt-cacher-ng.service:

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
 <name replace-wildcards="yes">apt-cacher-ng proxy on %h</name>
 <service protocol="ipv4">



$ sudo apt-get install squid-deb-proxy-client

Here is a snippet to install server|client depending if there is already an apt-get proxy or not:

Source: http://blog.surgut.co.uk/2013/03/avahi-apt-cacher-ng-sbuild.html

  • That's a nice find! I'm wondering why this isn't the default whenever apt-cacher-ng is suggested, Dimitri John Ledkov has a canonical.com address and the snippet is already included in 14.04. I just made an edit your answer.
    – LiveWireBT
    Nov 13, 2016 at 22:59
  • So the magic on 18.04 appears to be in /etc/apt/apt.conf.d/30autoproxy, which contains the single line: Acquire::http::ProxyAutoDetect "/usr/share/squid-deb-proxy-client/apt-avahi-discover"; (referring to a Python script). Sweet. This gets installed by squid-deb-proxy-client. So for my own scenario I don't need that on the server at all! Apr 29, 2020 at 21:21

Something like this should work:


nc -w 1 $ip $port
if [ $? -eq 0 ]; then
    echo "Acquire::http { Proxy \"http://$ip:$port\"; };" > $proxy_file
    echo 'Acquire::https { Proxy "false"; };' >> $proxy_file
    rm -f $proxy_file

Fix permissions

sudo chmod +x /etc/NetworkManager/dispatcher.d/99SetAptProxy


  • The "nc" command tests that it can connect to the 3142 port on the given IP address.
  • This script is run everytime the networking interfaces are changed by network manager.
  • Feel free to alter the way that you detect for the proxy, this works for me, but it is a security vulnerability if you install packages on a foreign network, for example.

Not an exact answer, since you'll have to change your existing cache setup, but squid-deb-proxy is a good solution to providing a cache that will be used transparently if available, and is very easy to set up on both cache server and clients. See the first answer to this question for more details.

  • ... that was hopefully meant to be "that will be used transparently if available and if avahi is installed on the client side" ;) Feb 28, 2013 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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