Step-By-Step Guide to Block Ads on your iPhone

If you find advertisements on websites annoying (including the ones here on iPhone Hacks); then on your computer you can always use browser add-ons like Adblock to prevent page elements such as advertisements from being downloaded and displayed.

However, there was no way to block advertisements in iPhone’s Safari browser. Not any more, as James over at James is Bored has figured out a way to block ads even in your iPhone’s Safari browser.

You can checkout the step-by-step guide to block ads on your jailbroken iPhone after the jump.

Before we can start, please note that you need to jailbreak your iPhone.

It goes without saying that hacking your iPhone is at your own risk, please take a backup of your iPhone.

Please follow the step-by-step guide to block ads on your jailbroken iPhone:

  1. You need to be able to transfer files to your iPhone, so you can either install OpenSSH application using Cydia or use iPhone software like iPhoneBrowser (for Windows).
  2. Then go to Settings -> Wi-Fi, click on arrow next to the Wi-Fi server you are currently using on your iPhone and write down the IP address.
  3. If you are not using iPhone software like iPhoneBrowser to transfer files from your computer to your iPhone and vice versa, then you will need and FTP client with SFTP (secure SSH connection over FTP). Windows users can try FileZilla while Mac users can use Cyderduck.
  4. Download the replacement host file from this link. (Please note that the host file downloaded from this link will also disable Apple’s kill-switch mechanism to deactivate iPhone apps). Note: If you want to use the Categories App, then please remove the 127.0.0.1 mm.admob.com line from the downloaded replacement host file, otherwise mentioned by reader, Zai, it will not work. If you don’t want to disable Apple’s kill-switch mechanism then remove this line as well 127.0.0.1 iphone-services.apple.com from the replacement host file.
  5. Open your FTP client, set it to connect over an SFTP connection, and then put your iPhone’s IP address (the one your had written down in step 2) in the "host" section. The username and password (unless you changed them) are root and alpine, respectively. The connection may take a few minutes at first, and you may be asked to accept a host key; say yes to any prompts. In case the connection fails try again.
  6. Take a backup of the host file on your iPhone before you override the host file. You will find it in /etc folder at your iPhone’s root directory.
  7. After taking the backup, replace the host file on your iPhone with the replacement host file you had downloaded in step 4.
  8. Close your FTP client and restart your iPhone.

After restarting your iPhone, you should start seeing blank spaces or compressed frames instead of advertisements.

If you open the replacement host file using a text editor, you will figure out that the trick behind this iPhone hack similar to the method used by iPhone Expert Zdziarski to block Apple’s kill-switch mechanism to deactivate iPhone apps. You are basically mapping the IP address of most of the ad servers to localhost (127.0.0.1) in the host file.

This hack also seems to block ads in iPhone apps that use any of the ad servers that are mapped to localhost.

You can see the screen shot of the iPhone Hacks website before the Adblock hack below:


iPhone Hacks Before Blocking Ads

And the screen shot of the iPhone Hacks website after the Adblock hack below:


iPhone Hacks After Blocking Ads

If you observe any issues or want to revert the hack, simply copy the backed up host file back to your iPhone’s /etc folder and restart it.

Hope this makes readers who were complaining about the ads on iPhone Hacks happy. As always, let us know how it goes.

[James is Bored via Lifehacker]




Follow this blog

 

Top iPhone Hacks Categories:

Hacks
iPhone Applications
Unlock iPhone
JailBreak iPhone
iPhone Tips & Tricks
iPhone Games
iPhone News 

Like this post? Share it!

  • louis.tristan@gmail.com

    interesting. If one stays focused on the content you won't see the ad. That's a lot of trouble to go through.. What if there's a breaking news story. Some of the ads are good except for the sylvan learning $100.00 off…

    Don't have kids n folks that have them should be speeding time with them not hacking the iphone. Aren't parents supposed to set a good example for them so they don't wind up like us? : )

  • thedevilsjester

    Personally, I dislike the ads on this site.

    Its not the content of the ads, its the placement.

    Instead of creating a true separation with content on top and bottom of the ad, it allows the content to wrap around the ad, forcing the article into an annoyingly narrow column of text.

    If you have them create a true separation, you will probably have less people resorting to ad blocking.

  • zai

    This technic raise some issues.

    I notice that it is icompatible with "categories" app. This app refuse to launch if adblock is enable :(.

  • http://www.iphonehacks.com iPhoneHacks

    Hey Zai,

    You are right I just checked it and the Categories app does not work with adblock. It does not stop me from launching the category folders that I have created using the Categories app but does not let me launch the app.

    It gives the Permission error message when I try to launch it "Admob blocking has been detected in your hosts file. I have worked many hours for this app. It cannot run with this block in place".

    I guess its only fair, the developer is making money using ads on the app so if you want to use the app you will need to revert back to the host file you had backed up in Step 6 above or just remove the Admob block from the replacement host file.

    To remove just the Admob block follow these steps:
    Open the replacement host file you had downloaded in step 4.
    Remove the following entry from the host file:
    127.0.0.1 mm.admob.com
    Follow steps 5 to 8 again (ensure you dont override the original host file).

    You should be able to launch Categories app (with the ads) again after restarting your iPhone with the modified hosts file.

    Hope this helps.

    Thanks for pointing it out.

    cheers!

  • Zed Sefi

    It conflicts with QuickGold and disables it too .. which is an application that I can't live without.

  • http://www.phidelity.com phidelity

    you can downgrade the Category app to 2.16 and it will run and block ads.

    download http://iphonebigboss.com/repo/repofiles/cydia/debs2.0/categories_2.16.deb

    1. SFTP or SCP your deb file into /tmp
    2. SSH into your iPhone with Terminal and type:
    dpkg -i /tmp/filename.deb

  • David Boring

    It is *not* fair. The user is never asked "Is it OK if I start displaying ads on your device?" It is obnoxious and intrusive. I'd rather pay for the damned app, but that isn't an option with many admob-enabled apps.

  • foxintampa

    Does anyone notice this slows down response time of the iPhone due to the size of that file? Test it out for your self with the speedtest app. I went from 250ms pings with the stock hosts file loaded, to 500-600ms with this new host file.

  • http://www.top-favoris.co.cc SMed79

    When I try to go to More Settings in SBSettings, it says :
    “Permission error. An ad blocking host file is installed. The app cannot run this way. Would you like to unblock the elements we need? (The app will need to be restarted after).”
    I selected No, and it just quits.

  • Chris

    This works like a charm, thanks a lot!

  • Yash

    I am getting a “No Sim” meesage after doing this process

    • Yash

      Am sorry it’s workign perfectly thank you!