How to edit the hosts file in iOS

Recently, I needed to view my website on an iPad in a test environment. My test server is on an internal network, which is impossible to view without write access to a hosts file.

I’m glad to say that I finally managed to bend the iPad to my will, and – although it feels like it may have gotten the best of me – my sanity is mostly intact. Since I am such a generous person, I will spare you from hours of frustration and tell you how to edit the hosts file in iOS. Just follow these instructions, and everything will be okay.

First of all, if you haven’t jailbroken your device, you will need to do that first.

Notice: I do not recommend jailbreaking your device!!!

With that mandatory disclaimer out of the way, if you have to do it, I suggest upgrading (or downgrading, if you made the mistake of upgrading to iOS 6) to iOS 5.1.1 and using Absinthe 2.0.4 to jailbreak. (See here for a tutorial.) The folks at Chronic Dev Team and iPhone Dev Team have done a great job at making it a mostly painless process. (If you want to jailbreak a different version of iOS, then… well, good luck to you.)

EDIT 4/15/2013: Shortly after I wrote this, a tool called Evasi0n made it possible to jailbreak any version of iOS up to and including 6.1.2, but not 6.1.3. (See here.)

Once that’s done, open Cydia (which will appear on the springboard) and download iFile. You can spend a few bucks to get the full-featured version, but you don’t need to for what we’re doing.

Next, launch iFile and navigate to the root (/) directory. Tap on the hosts file, and select the option to open it with Text Viewer. From here, you should be able to edit and save the file.

This is all pretty standard stuff to anyone with Unix experience. However, there is one thing about the hosts file in iOS that tripped me up for HOURS:

Make sure you leave a blank line at the end of the hosts file!

For whatever reason, the operating system simply refuses to read the last line of the hosts file. Anything you put there will be IGNORED.

That’s it. Have fun! And please let me know if you find a decent five row keyboard in Cydia. I literally cannot function in a terminal without ARROW KEYS.


12 thoughts on “How to edit the hosts file in iOS

  1. Chris

    Well explained, but in my opinion irrelevant on today’s devices. Upgrading to iOS6 isn’t a “mistake” as you say – it’s recommended by Apple for very good reasons (security, features, support, etc). Since Jailbreaking and manually editing hosts files are likely to be things only advanced users are happy to do, I’d therefore recommend running an internal DNS server or something like Squid to act as a proxy. Once again, this is just my opinion …

    1. Dave Post author


      I only meant that, if you wanted to jailbreak your device, it would be much easier on iOS 5 than iOS 6. That was true at the time, at least. It’s pretty simple now to jailbreak your device on iOS 6.

      Your solution using a DNS server or Squid is a much better solution than this. Unfortunately that is not an option for everyone, whereas jailbreaking is.

      1. Chris

        Yes, and I agree with that. The suggestion was more that if someone is comfortable editing a hosts file and understands the implications of doing so, they’re probably also comfortable setting up local DNS or Squid. It’s not for everyone, but possibly “safer” than jailbreaking a device (which, although legal, completely removes any device support options, in the event they’re needed).

  2. mnemonic67

    Chris, any chance of a tutorial on running an internal DNS Server to handle my hosts file? I’m such a noob with all things IOS.


    I left an empty/blank line at the end of the hosts file like you mentioned. I ping the IP address I am trying to point to, and nothing! What could I be doing wrong?

  4. Nemanja

    So please correct me if I’m wrong i type example: “ ” <<– with the space after the com?

    1. Dave Post author

      You don’t need to put quotes around the domain name, and you don’t need the www prefix. Any number of spaces between the IP address and the host name is fine. For example:    stevescomputer

      Only use or if you want to block a site. Otherwise it should be the IP address of the server the site is hosted on.

      1. Dave Post author

        Daniel, I’m not 100% sure about the default for iOS but normally a hosts file just contains a couple of lines:    localhost
        ::1          localhost

Leave a Reply

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

You are commenting using your 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