Today I will show you how to easily block the servers hosting Spotify ads on your Linux/Mac or Windows machine with a hosts file. This will allow you to listen all day long on a free account without hearing a single ad + to protect yourself from Spotify selling your private data to highest bidder. 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 (23 August 2019) it works swimmingly.
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.
Updates & changes on this project can be found below on Github:
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):
Fully Updated HOSTS File: https://github.com/x0uid/SpotifyAdBlock/blob/master/hosts
For Windows 10 & 8
- Press the Windows key.
- Type Notepad in the search field.
- In the search results, right-click Notepad and select Run as administrator.
- From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
- Make the necessary changes to the file.
- Click File > Save to save your changes.
For Linux
- Open a terminal window.
- Use the nano command line text editor, or a different one you have available to open up the hosts file. The command with nano is as follows (the command will require your Linux user’s password):
sudo nano /etc/hosts
For Mac OS X 10.6 through 10.12
- Open Applications > Utilities > Terminal.
- Open the hosts file by typing the following line in the terminal window:
sudo nano /private/etc/hosts
- Type your domain user password when prompted.
- 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.
- Save the hosts file by pressing Control+x and answering y.
- 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.
workes for me on linux thansk dude
How can you see these domains? Maybe Spotify changes the domain name servers. Is it possible to keep the list updated?
tired of nothing of ads !!!! thank you
I just tried this now and it works on Windows 10. Thanks so much!
thank you so much 😀
it works like a charm on iOS 10.14.4 BuildVersion: 18E226. thanks dude
the last line doesn’t work on linux :/
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
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.
This list shows the friend list but doesn’t block ads here. Not really useful.
wow, love that idea, finally understood a slightly bit the idea of DNS. Let’s hope it’ll work!
This worked for me in Windows 10. Thank so much!
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
Works on MAC OS 10.13.4 as of May 18, 2018. No more long pauses like when I was using Spotifree.
doing this actually causes the friend feed to stop working for me, anyone else?
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
so will removing this line not solve the issue then?
Same for me.
Has anyone figured out a work around. I llike using radio feature.
worked for me too on Windows10
works on me. Windows 10 user. kudos!
Working fine but the Friend Activity is not displayed anymore !?
Thank you mate 🙂
Notepad c:\Windows\System32\Drivers\etc\hosts is more easy for command, just need open cmd to admin .
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!
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).
You’re right, fixed the issue. Thanks for correction!
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.
Stopped working for mi in Ubuntu 18, now it blocks all the songs too.
List updated, works again!
Spotify likes playing games 🙂
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.
The small list does works, you cant block Spotify’s, because they use those services for receiving data back to let you listen to music 9 evil technical methods) but third party ads are blocked.
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
Yep thanks for the updated list Johan, this list works perfect!
Johan, great modification! Works beautifully here on my linux system. Thanks.
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.
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!
Try again list updated again, new DNS entries added. Don’t forget to edit your HOSTS file again 🙂
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
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
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.
Fixed, update the hosts file.
Thanks. Loving the ad-free listening but my friend-activity tab is not working now.
Not working for either, I can only play songs in favourite, not other ones
Fixed, update the HOSTS file.
How do I undo this? With the new Spotify update, it completely screws up everything
How to undo what? Just delete list from your HOSTS file.
He is asking how to remove all the entries from the host file!!
Hey there,
Whatever OS you are using, open the hosts file just like you opened it before. Once opened, remove all the entries which you had copy pasted. Save the file and exit. Restart your Computer. You will be good to go.
Good job. Works great again!
This is great but I still get a black bar in place of an ad. Any idea how to remove it?
doesnt work, ads still play on windows 10 using desktop app
Looks like Spotify plays games again – “Can’t play the current song”
This does not work, I pasted it in host files like it said to and I am still hearing the ads
This doesn’t work, I am on Windows 10 and I did exactly what it said to do yet I am still getting ads :/
I commented this line because it prevented me from listening to some songs and some thumbnails were not showing.
#0.0.0.0 beta.spotify.map.fastly.net
I’m on ubuntu 19.04 and the spotify version is this one : 1.1.0.237.g378f6f25-11
It works really well for me
I get spotify stuck when displaying an ad and the only way to fix it is closing and opening the software again
how do I figure out which address in the host file I should comment?
ya man thanks! everything works as perfect. even my customized version in ubuntu under wine. the only thing which appears is that some album covers and playlist thumbnails aren’t loading anymore, but thats the point you have to come to a compromise when ur using such a free way of getting rid of ads on spotify 😛
How come ads are getting blocked!! Mine doesn’t get blocked. Ubuntu user!
For me, it does not block all adds. However, adds are much less than before.
So it partially works. Maybe we need an update!
Thanks a lot.
On Ubuntu, the updated hosts file doesn’t show any thumbnail.
Ads still do play.
Sorry for late reaction, issue should be fixed now.
Cool!!
Is the pastebin link updated since the removal of the 2 entries in April? because it didn’t work for me as of 18-5-19 and the date next to the link says 10-3-19
Fixed issue and yes its fully updated now.
If anyone’s having trouble displaying album art, simply remove this line: beta.spotify.map.fastly.net 😉
Yeah removed entrie by default, thanks for suggestion.
I was having trouble displaying album art with the updated list (May 26, 2019), and I narrowed it down to ‘i.scdn.co` being the culprit. Just remove that from the list, and everything is fixed!
I can’t play music with Pastebin 29-05-19
That’s weird because i can play every song. What list of album/song cant you play?!
The updated list disables the option to hear many of the songs
is there a solution?
Hi, i wrote an java program that collects all host row entries from this sites host file and adds them to your localhost file without you doing it manually. It works in linux, not tested yet in windows but should not be a problem. Read the instructions first and then try it it you want to, here is the simple code:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
/*This program is written to copy online host file rows from https://pastebin.com/raw/9M5ALu8n
* to your local hosts file so you could run it from crontab or from a .bat file
* from windows so you dont have to update it manually if changes are made to the online host file
* The syntax should be: java -jar thisJar.jar pathToYourHostFile urlToPasteBin
* It has been tested in linux/ubuntu but should work in windows to.
* If there are some new rows on the site that is not in your local host file it will insert them in
* a new host file, but the program backups your current host file first with syntax hostFile-currentDate
* Then it saves the new host file to your regular path. Use this program if you want to.
* Take a backup of your host file first if you are scared of running it the first time 😀
* Best regards Eskimos20
*/
public class ReplaceHostFileEntries {
private static String path = “”;
private static String address = “”;
//Containing all rows from current host file + new rows from online site
private static ArrayList hostFileArr = new ArrayList();
//Containing all rows from sites host file
private static ArrayList hostFileFromSite = new ArrayList();
//If a change has occured then this boolean is true
private static boolean changeHasOccured = false;
public static void main(String[] args) {
if ((args!=null && args.length>0) || (path != “” && address != “”)) {
if (args.length>0) {
for(int i = 0; i < args.length;i++) {
if (i == 0) {
path = args[i];
}else {
address = args[i];
getHostsInfo(address, path);
}
}
}else {
getHostsInfo(address, path);
}
}else {
System.out.println("This program requires two parameter, first path to hosts file: /etc/hosts and url to pastebin, as of now it should be: https://pastebin.com/raw/9M5ALu8n");
}
}
private static void getHostsInfo(String address, String hostsPath) {
URL url;
try {
url = new URL(address);
InputStream in;
try {
in = url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while((line = reader.readLine()) != null) {
if(line.contains("#")) {
continue;
}else {
//Collects all rows from online site containing 0.0.0.0 ip
hostFileFromSite.add(line);
}
}
//Saves rows from local host file
gatherRowsFromLocalHostFile();
//Compares local host file to sites host file
compareLocalHostFileToSiteHostFile();
} catch (IOException e) {
System.out.println("Could not connect to URL: " + address);
e.printStackTrace();
}
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
}
private static void gatherRowsFromLocalHostFile() {
File file = new File(path);
BufferedReader br;
try {
br = new BufferedReader(new FileReader(file));
String line;
//Adding local rows from local hostfile
while ((line = br.readLine()) != null) {
hostFileArr.add(line);
}
} catch (FileNotFoundException e) {
System.out.println("Could not find current host file: " + path);
e.printStackTrace();
} catch (IOException e) {
System.out.println("Failure while reading input from local host file: " + path);
e.printStackTrace();
}
}
private static void compareLocalHostFileToSiteHostFile() {
Iterator siteArrItr = hostFileFromSite.iterator();
String siteHostFileRow = “”;
//Looping sites host file and comparing it to the original host file
while (siteArrItr.hasNext()) {
siteHostFileRow = siteArrItr.next();
addStringToArrayIfNotFound(siteHostFileRow);
}
writeToHostFile(hostFileArr);
}
private static void addStringToArrayIfNotFound(String myRow) {
Iterator itr = hostFileArr.iterator();
String hostFileRow = “”;
boolean foundMatch = false;
while(itr.hasNext()) {
hostFileRow = itr.next();
if (hostFileRow.equalsIgnoreCase(myRow)) {
foundMatch = true;
}
}
//Add sites row to local host file if it did not exist
if (!foundMatch) {
changeHasOccured = true;
hostFileArr.add(myRow);
}
}
private static void writeToHostFile(ArrayList myNewHostArray)
{
Iterator itr = myNewHostArray.iterator();
String fileContent = “”;
while(itr.hasNext()){
fileContent += itr.next() + “\n”;
}
if (fileContent!=””) {
File origFile = new File(path);
SimpleDateFormat formatter= new SimpleDateFormat(“yyyy-MM-dd”);
Date date = new Date(System.currentTimeMillis());
File renameFile = new File(path + “-” + formatter.format(date));
if (changeHasOccured) {
if(origFile.renameTo(renameFile)) {
BufferedWriter writer;
try {
writer = new BufferedWriter(new FileWriter(path));
writer.write(fileContent);
writer.close();
if (changeHasOccured) {
System.out.println(“There was changes between your local host file and the online site!”);
System.out.println(“Your local host file has now been backup up to: ” + renameFile.toString());
System.out.println(“Your new host file has been written to: ” + path);
System.out.println(“Finished!”);
}
} catch (IOException e) {
System.out.println(“Could not write file to disk: ” + path);
e.printStackTrace();
}
}else {
System.out.println(“Could not rename original hosts file to: ” + renameFile.toString());
}
}else {
System.out.println(“No changes has been made to host file since it is up to date!”);
System.out.println(“Finished!”);
}
}
}
}
Thanks for your host file updates 😀
Could you please update me on what command you are using to sniff traffic so that you can collect the ads addresses ? I have tried tcpdump on port 4070, 443 and 80 just to see what traffic is showing. Would love to be able to find out spotify ads servers just like you did 😀
Seems to be working with banner ads, but I’m still getting audio ads.
Another Ubuntu user btw 🙂
Hi! Since the latest update spotify cant update album art or play songs.
Living in Sweden..
Yep, fixed now, update your hosts file with new one! Have fun!
Hi! I updated it with the latest, now it works better, but some albums dont show album art and some cant play. But most of them can play.
Its quite hard to understand the logic that spotify have with their streams :/
Not running in Linux: “Offline mode” using the – just updated – hosts file. I’ll stick with my own file, Friend Activity, blank banner ads, but couple Audio/video ads (I close and launch Spotify again)
The Rev Update 103, GitHub Hosts version doesn’t work in my Linux Mint 19.1. When I open the Spotify app, it always appear to be OFFLINE, with the warning “No internet connection detected”.
Could you fix this? Thx.
Thanks for reporting. will look into it.
Thx for the update. It really works now since i Update the hosts and then downgrade the Spotify to the older version. Best Regards, greeting from Indonesia 🙂
How do you downgrade Spotify version in Linux Mint?
Fully explained here: https://community.spotify.com/t5/Desktop-Linux/Downgrading-Spotify-for-Linux/td-p/2318293
I have already tried that, but I have no previous version in /var/cache/apt/archives/. I have use unsuccessfully “find” tool. You can install with “sudo apt install spotify-client-0.9.17” but it is a tool old version.
I’m trying this on Ubuntu 18.04.3 LTS from the Netherlands.
I’m still getting ads.
Is this list country-specific?
Or do I need to flush the cache like on Mac OS before it takes effect?
Any help is appreciated 🙂
Howdy,
What ads do you get banners? Videos? Or just Spotify premium ads?
Grtz
it start working but after a while it stopped all conecion on spotify to the internet and now it is not working at all