How to protect your privacy by blocking all annoying Spotify ads & analytics in Linux, OSX and Windows with hosts file.


Today I will show you how to easily block the servers hosting Spotify ads on your Linux/Mac or Windows machine. This will allow you to listen all day long on a free account without hearing a single ad.  This trick is very simple, legal and works great.  Spotify may catch on and find some way to stop this from working but, as of today (13 March 2019) it works swimmingly.

UPDATE 20-02-19: List updated thanks to Johan, ad blocking works again. Somehow Spotify found cheap way to block music if you block they DNS ad services by pinging it back from client. Note to update your HOSTS entries.

UPDATE 10-03-19: Huge DNS list update, added lots of new advertising entries.

UPDATE 04-04-19: Fixed issue that Spotify client only plays songs that are in favourite list, by remove 2 entries from HOSTS file list.

spotify-ad-block

Blocking Ad Server

In order to remove those pesky ads, all we need to do is setup out hosts file to override the DNS for Spotify’s ad servers and redirect that traffic to our local machine.  When the traffic hits out local machine the call will fail and the ad will be skipped.  Follow the steps below to add the entries needed.

Open your hosts file using your favorite text editor. I mostly use terminal in Linux. Add the following lines to the bottom of your hosts file and save your hosts file (Look below How To in your favour OS):

RAW HOSTS File Updated 10-03-19: https://pastebin.com/raw/9M5ALu8n

For Windows 10 & 8

  1. Press the Windows key.
  2. Type Notepad in the search field.
  3. In the search results, right-click Notepad and select Run as administrator.
  4. From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
  5. Make the necessary changes to the file.
  6. Click File > Save to save your changes.

Or very easy way of using Batch file! Take the info from the THIS paste bin url, copy all of it, paste it into Notepad and save the filename as whatever you please but be sure to add “.bat” at the end (without quotes). And execute it As Admin in Windows.

For Linux

  1. Open a terminal window.
  2. Open the hosts file in a text editor (you can use any text editor) by typing the following line:
    sudo nano /etc/hosts

For Mac OS X 10.6 through 10.12

  1. Open Applications > Utilities > Terminal.
  2. Open the hosts file by typing the following line in the terminal window:
    sudo nano /private/etc/hosts
    
  3. Type your domain user password when prompted.
  4. Edit the hosts file.The file contains some comments (lines starting with the # symbol), and some default hostname mappings (for example, 127.0.0.1 – local host). Add your new mappings after the default mappings.
  5. Save the hosts file by pressing Control+x and answering y.
  6. Make your changes take effect by flushing the DNS cache with the following command:
    dscacheutil -flushcache
    

There you go, editing hosts file has taken effect.

Why This Works?

To understand how this works we first need to understand the role DNS plays in our operating system.  When we are communicating with other services on the web everything is referenced by IP address.  For instance, when I tell my browser to go to google.com, it has to know where to find google.com.  This is where DNS comes into play.  DNS short for Domain Name Servers is a service that translates human readable, easy to remember domain names into IP addresses that other machines can communicate with.  Whenever you add an entry to your local hosts file you are overriding the DNS entry locally for whatever domain you enter.  For instance, if I add the line “127.0.0.1 test.local” to my hosts file, whenever i type “test.local/” into my browser, it will see the entry in my hosts file and use the IP 127.0.0.1(locahost) rather than reaching out to a DNS server to try and resolve that address.  Where this comes into play for us is overriding Spotify ad servers.  When we add an entry for each server that hosts ads for Spotify and points them to our local machine, we are ensuring that whenever Spotify reaches out for an add it hits our local machine instead of the real ad server and gets an error. When Spotify detects this error it stops trying to attempt to run the ad and the ad is skipped.

Wrap Up

Hopefully after reading this you have a better understanding of how DNS works, how to override it and how to never have to listen to another spotify ad again.  As always I love feedback so leave a comment down below if you have anything you would like to add or contact me on Twitter: @0xUID.

48 thoughts on “How to protect your privacy by blocking all annoying Spotify ads & analytics in Linux, OSX and Windows with hosts file.

    1. I use debian, and it didn’t work either:

      if you are using a debian based OS try booth commands with root perm:

      1. apt-get install nscd
      2. /etc/init.d/nscd restart

  1. Or, you can add the following entries to your HOSTS file:

    # Spotify
    127.0.0.1 adclick.g.doublecklick.net
    127.0.0.1 adeventtracker.spotify.com
    127.0.0.1 ads-fa.spotify.com
    127.0.0.1 analytics.spotify.com
    127.0.0.1 audio2.spotify.com
    127.0.0.1 b.scorecardresearch.com
    127.0.0.1 bounceexchange.com
    127.0.0.1 bs.serving-sys.com
    127.0.0.1 content.bitsontherun.com
    127.0.0.1 core.insightexpressai.com
    127.0.0.1 crashdump.spotify.com
    127.0.0.1 d2gi7ultltnc2u.cloudfront.net
    127.0.0.1 d3rt1990lpmkn.cloudfront.net
    127.0.0.1 desktop.spotify.com
    127.0.0.1 doubleclick.net
    127.0.0.1 ds.serving-sys.com
    127.0.0.1 googleadservices.com
    127.0.0.1 googleads.g.doubleclick.net
    127.0.0.1 gtssl2-ocsp.geotrust.com
    127.0.0.1 js.moatads.com
    127.0.0.1 log.spotify.com
    127.0.0.1 media-match.com
    127.0.0.1 omaze.com
    127.0.0.1 open.spotify.com
    127.0.0.1 pagead46.l.doubleclick.net
    127.0.0.1 pagead2.googlesyndication.com
    127.0.0.1 partner.googleadservices.com
    127.0.0.1 pubads.g.doubleclick.net
    127.0.0.1 redirector.gvt1.com
    127.0.0.1 s0.2mdn.net
    127.0.0.1 securepubads.g.doubleclick.net
    127.0.0.1 spclient.wg.spotify.com
    127.0.0.1 tpc.googlesyndication.com
    127.0.0.1 v.jwpcdn.com
    127.0.0.1 video-ad-stats.googlesyndication.com
    127.0.0.1 https://www.techattend.com
    127.0.0.1 weblb-wg.gslb.spotify.com
    127.0.0.1 http://www.googleadservices.com
    127.0.0.1 http://www.googletagservices.com
    127.0.0.0 gads.pubmatic.com

    Hope it helps.

    1. these instructions are incomplete. the HOSTS file is a hidden, read-only system file. in order to change the hosts file, you must apply the following commands on command prompt while run as administrator:

      1) attrib -s -h -r c:\Windows\System32\Drivers\etc\HOSTS

      to make the file writeable. and the following after appending (NOT changing) the HOSTS file:

      2) attrib +s +h +r c:\Windows\System32\Drivers\etc\hosts

      to make the file hidden again

  2. This works for blocking the adds, but it also blocks all requests from spotify to its server (for example for the friends feed or radio stations).. Didn’t find a solution for this so far, the line which is causing the issue is
    127.0.0.1 spclient.wg.spotify.com

  3. Thank you for this simple solution.

    THIS IS SIMPLY GREAT.
    Now I have Spotify free without the ads on my Windows 10 PC.

    You made my day!

    Could we do the same directly on the router so the whole house would be spotify FREE of pubs? That would be great! (I tried but could’t find a simple way of doing so 😦 )

    Thank you again!

  4. There are many illegal entries in the list, all domains listed to start with http:// need to be fixed so that the http:// is removed, or else they will not work at all.
    Also change 127.0.0.1 to 0.0.0.0, this will give the benefit that no request will be made (going against 127.0.0.1 will make a request to the local machine).

  5. On Mac OSX 10.11.6, works perfectly, no more adds,no pauzes, and no more banners too. Excellent work ! Many thanks . and I now understand DNS.

  6. Sad ly the small list at the top doesn’t work and the long list in A.S. comment only let you play your songs in your Album section, so no new songs…..anyone? The only thing i can do now is search without list, than add to Albums and than add list to hosts file.

  7. Not here, on El Capitan OSX 10.11.6 I’ll try use the big list and delete the Spotify ones….At this moment this one is working for me( as long as it last):
    # Block Spotify Ads
    127.0.0.1 media-match.com
    127.0.0.1 adclick.g.doublecklick.net
    127.0.0.1 googleadservices.com
    127.0.0.1 pagead2.googlesyndication.com
    127.0.0.1 googleads.g.doubleclick.net
    127.0.0.1 pubads.g.doubleclick.net
    127.0.0.1 omaze.com
    127.0.0.1 b.scorecardresearch.com
    127.0.0.1 bounceexchange.com
    127.0.0.1 bs.serving-sys.com
    127.0.0.1 content.bitsontherun.com
    127.0.0.1 core.insightexpressai.com
    127.0.0.1 d2gi7ultltnc2u.cloudfront.net
    127.0.0.1 d3rt1990lpmkn.cloudfront.net
    127.0.0.1 doubleclick.net
    127.0.0.1 ds.serving-sys.com
    127.0.0.1 googleadservices.com
    127.0.0.1 gtssl2-ocsp.geotrust.com
    127.0.0.1 js.moatads.com
    127.0.0.1 omaze.com
    127.0.0.1 pagead46.l.doubleclick.net
    127.0.0.1 partner.googleadservices.com
    127.0.0.1 redirector.gvt1.com
    127.0.0.1 s0.2mdn.net
    127.0.0.1 securepubads.g.doubleclick.net
    127.0.0.1 tpc.googlesyndication.com
    127.0.0.1 v.jwpcdn.com
    127.0.0.1 video-ad-stats.googlesyndication.com
    127.0.0.1 https://www.techattend.com
    127.0.0.1 http://www.googletagservices.com
    127.0.0.0 gads.pubmatic.com

  8. Works seamlessly in both my Windows and Ubuntu, but in Windows when i tried to download a file from Google Drive on a browser its download nothing. Then i remove the “googletagservices.com” lines and its works again. Just FYI.

  9. Hey,
    I tried doing this on my PC but no luck!
    Could it be because of my location (India)???
    If yes, can you add Indian add servers too?? (or) how can I find Indian ad servers?

    Thanks in advance!

      1. Hey thanks for the quick response. I see that you have added 0.0.0.0 spclient.wg.spotify.com. Though the ads are gone the “Friends Activity” tab isnt working.
        I was wondering if any info from my pc’s c:\Windows\System32\activity.txt could be of any help
        I hav got a couple of variations of this in there
        TCP 192.168.0.***:**** 53.224.186.35.bc.googleusercontent.com:https CLOSE_WAIT

  10. also these .deploy.static.akamaitechnologies.com:http TIME_WAIT

    server-54-230-191-157.maa3.r.cloudfront.net:https CLOSE_WAIT

    maa03s23-in-f14.1e100.net
    maa05s06-in-f4.1e100.net:https ESTABLISHED

  11. This hosts-list breaks my spotify. The only songs that play are the ones already in my favourites. I can’t play any other songs or add new ones.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.