92

I doubt this is possible without extensive jail-breaking, but is it at all possible to edit the iPad's (or any iOS device's) hosts file?

Ahmed Nuaman
  • 11,324
  • 13
  • 50
  • 80
  • 1
    Not without jailbreaking. Once it's jailbroken, it'll be the same as any other Unix/BSD system. I assume, I haven't done it before. – Jasarien Jan 24 '11 at 15:50
  • 1
    Imagine if any app could change the association between host names and their legitimate IPs. – Jano Aug 02 '11 at 19:20
  • 2
    @jano Presumably that issue now exists with apps on the Mac App Store. It's dealt with by OSX requiring a password before you can edit the hosts file, and also presumably by Apple's app vetting procedure. – Danyal Aytekin Sep 21 '11 at 13:43
  • 3
    @Jano: Microsoft Windows allows this now, and it causes 0 problems. You just need to have Administrator permissions. And there are legitimate reasons for wanting to modify a hosts file (all related to getting to stuff without a DNS server or else dealing with VPN issues). – Josh Mouch Nov 14 '11 at 17:21

13 Answers13

55

The previous answer is correct, but if the effect you are looking for is to redirect HTTP traffic for a domain to another IP there is a way.

Since it technically is not answering your question, I have asked and answered the question here:

How can I redirect HTTP requests made from an iPad?

Community
  • 1
  • 1
tremoloqui
  • 3,118
  • 3
  • 22
  • 21
48

No, you can't change iPad's host file(without jailbreak), but can workaround.

Here is my scenario:

  • Mac OS X, with IP 192.168.2.1, running a web app
  • iPad, the device you would like to test the web app
  • Charles (for Mac), enables HTTP proxy for your iPad

I am going to test the web app running in my Mac via iPad, but I can't access directly to it.

The solution works for me:

  • Firstly, make sure that your server and iPad are in the same local network.
  • Then, set up Charles proxy, in the menu "Proxy > Proxy Settings...", fill in Port(mostly 8888) and toggle Enable transparent HTTP proxying.

enter image description here


  • Setup proxy setting in iPad.

enter image description here

Now you can visit your web app in iPad.

Of course you can use other proxy tools like Squid or Varnish in Linux, or fiddler in Wondows.

holys
  • 11,255
  • 12
  • 40
  • 50
  • 1
    It doesn't answer the question... but this is an excellent, easy to implement, easily toggleable solution for the purposes most people would want to edit the hosts file for. – Matt Kenefick Apr 13 '15 at 18:28
  • Awesome solution! Clean and easy to implement. I use linux as my OS for my workstation, so I used tinyproxy and the proxy works great with my iPhone. Thanks man! – Edenshaw Apr 24 '17 at 13:45
  • It doesn't work on newer version of iOS due to security issues maybe, It can be more easy with a `NodeJs` module [filternet](https://github.com/axiak/filternet) – vanduc1102 May 19 '17 at 12:13
  • 2
    "Now you can visit your web app in iPad" - but how? If my app only works on "myapp.dev.domain.com", how does the Ipad resolve the name. This is where the host file comes in, and I suspect the point of the question – Greg Woods May 09 '19 at 09:29
  • @GregWoods i have a similar configuration and this worked for me by visiting 'myapp.env.domain.com' but only after a tried a few times – RenaissanceProgrammer Sep 18 '19 at 20:57
  • @GregWoods there's a popup that appears on the mac machine asking to allow or deny the connection, allow it, then refresh the mobile device again and it should connect now – RenaissanceProgrammer Sep 18 '19 at 21:05
48

No. Apps can only modify files within the documents directory, within their own sandbox. This is for security, and ease of installing/uninstalling. So you could only do this on a jailbroken device.

Jonathan.
  • 51,850
  • 46
  • 174
  • 275
  • 1
    Only in the sandbox, but not only within the documents directory (see iOS Application Programming Guide > Application Runtime > File System). – Jano Aug 02 '11 at 19:17
6

I needed the same functionality, and doing jailbreak is no-no. One solution is to host yourself DNS server (MaraDNS), go to your wifi settings in ipad/phone, and add your custom DNS server there.

The whole process took me only 10 minutes, and it works!

1) Download MaraDNS

2) Run mkSecretTxt.exe as administrator

3) Modify mararc file, mine is:

ipv4_bind_addresses = "put your public IP Here"
timestamp_type = 2
random_seed_file = "secret.txt"

csv2 = {}
csv2["Simple.Example.com."] = "example.configuration"

Add file called "example.configuration" into the same folder where run_maradns.bat is.

4) Edit your example.configuration file:

Simple.Example.com. 10.10.13.13 ~

5) Disable all Firewalls (convenience)

6) Run file "run_maradns.bat"

7) There should be no errors.

8) Add your DNS server to list, as shown here: http://www.iphonehacks.com/2014/08/change-dns-iphone-ipad.html

9) Works!

Erti-Chris Eelmaa
  • 22,879
  • 5
  • 54
  • 76
  • 1
    every answer here assumes OP wants to sniff HTTP traffic while this is the only actual answer that focus on spoofing DNS resolution (as modifying hosts file) – Filipe Pina Jul 30 '18 at 00:13
6

The easiest way to do this is to run an iPad simulator using XCode and then add an entry in the hosts file (/etc/hosts) on the host system to point to your test site.

Payson Welch
  • 317
  • 3
  • 10
5

Yes, you can edit the iPad hosts file, but you need to be jailbroken. Once you've done that, download Cydia (app market), and get iFile. The hosts file is located within "/etc/hosts".

Apollo Clark
  • 786
  • 8
  • 16
4

I would imagine you could do it by setting up a transparent proxy, using something like charles and re-direct traffic that way

CosmicChild
  • 181
  • 8
3

Workarond I use for development purposes:

  1. Create your own proxy server (One option would be: Squid on Linux).
  2. Set your hosts file with your domains.
  3. Set the proxy server on the IPAD/IPHONE and you can use with your hosts.
tauanz
  • 271
  • 3
  • 4
3

I know it's been a while this has been posted, but with iOS 7.1, a few things have changed.

So far, if you are developing an App, you MUST have a valid SSL certificate recognized by Apple, otherwise you will get an error message on you iDevice. No more self-signed certificates. See here a list:

http://support.apple.com/kb/ht5012

Additionally, if you are here, it means that you are trying to make you iDevice resolve a name (to your https server), on a test or development environment.

Instead of using squid, which is a great application, you could simply run a very basic DNS server like dnsmasq. It will use your hosts file as a first line of name resolution, so, you can basically fool your iDevice there, saying that www.blah.com is 192.168.10.10.

The configuration file is as simple as 3 to 4 lines, and you can even configure its internal DHCP server if you want.

Here is mine:

listen-address=192.168.10.35

domain-needed

bogus-priv

no-dhcp-interface=eth0

local=/localnet/

Of course you have to configure networking on your iDevice to use that DNS (192.168.10.35 in my case), or just start using DHCP from that server anyway, after properly configured.

Additionally, if dnsmasq cannot resolve the name internally, it uses your regular DNS server (like 8.8.8.8) to resolve it for you. VERY simple, elegant, and solved my problems with iDevice App installation in-house.

By the way, solves many name resolution problems with regular macs (OS X) as well.

Now, my rant: bloody Apple. Making a device safe should not include castrating the operating system or the developers.

Carlos Cap
  • 41
  • 3
  • Thank you Carlos. The struggle is we use Pulse Secure's mobile vpn product to get to test servers. These are not available outside. So, if we want to test a new PROD certificate then we need the iPad to go to the test server (where the PROD cert is installed); but to use the URL www.prod......com. so, far, no solution to this scenario found. :0( – codeslapper Jul 13 '17 at 18:55
2

If you have the freedom to choose the hostname, then you can just add your host to a dynanmic DNS service, like dyndns.org. Then you can rely on the iPad's normal resolution mechanisms to resolve the address.

jonseymour
  • 696
  • 7
  • 21
1

You can also make use of a proxy server on your iPhone or iPade via mobile internet (3G) by using a iPhone Mobile proxy generator:

http://iphonesettings.net/mobileproxygenerator.php

Just enter the apn of your carrier (with apn username/password if needed) and the proxy server you want to go through and tap Generate

Savas
  • 19
  • 2
  • 2
    **READER BEWARE**: the web site in this answer is listed as malware by many corporate internet firewall solutions. By sending all your traffic through an untrusted proxy server, you expose all the transmitted information. Do you *really* trust `iphonesettings.net`? – ErikE Apr 17 '19 at 17:52
-2

You need access to /private/etc/ so, no. you cant.

  • @OmG, The question was "is it at all possible" and his/her comment does in fact accurately answer the question. Stop copy/pasting comments to boost your own reputation. – Daniel Smith Dec 21 '17 at 19:47
-7

Best Answer: Simply add http or https in your browser, the IP address, colon and port number. Example: https://123.23.145.67:80