views:

6293

answers:

7

I am developing an application that query to the server. In my Mac, I use the hosts file to change the dns to point to a local server within my local area network.

Now I need to test it with my iphone, the problem is that my iphone does not recognize that server due to the missing configuration for dns.

Within my mac or windows, I simply add: 192.168.0.20 http://sunflowerapps.com

Now how to I let my iphone know http://sunflowerapps.com ?

Someone has experienced with it before, please help!

+4  A: 

Not programming related, but I'll answer anyway. It's in /etc/hosts.

You can change it with a simple text editor such as nano.

(Obviously you would need a jailbroken iphone for this)

Andreas Bonini
You can't use nano on a vanilla iphone to directly get to /etc/hosts. I would assume is about an app that would be distributed, in which case you can't mess with files outside your sandbox.
Jaanus
@Jaanus: of course I meant with a jailbroken iphone. And he never said anything about an app being redistributed; he simply mentioned he needed to test it on his iphone which had a dns problem.
Andreas Bonini
I don't understand the downvotes. The answer is technically correct and well written.
Andreas Bonini
I'll restore some karma for the edit; if the down-votes were used because of the *implicit* 'for distributed app' then while I can understand them, I think the downvoters should've left a comment to explain that.
David Thomas
I presume he only needs to change the hosts file so he can test his app. Once tested, it shouldnt need the hosts file changed. Perfectly acceptable to recommend jailbreaking here!
Mongus Pong
+1  A: 

It might exist, but you cannot change it on a non-jailbreaked iPhone.

Assuming that your development webserver is on a Mac, why don't you simply use its Bonjour name (e.g. MyMac.local.) instead of myrealwebserverontheinternet.com?

oefe
all the web services exist in a server within my LAN network. I have a domain name and I would like to map my domain name to this server as well. and immagine that someone gives you an address for all of his webservices, he ask you to query these services using this address, he can show you how to add hosts file to mac, windows, but not iphone :-s
sfa
A: 

No, an iPhone application can only change stuff within its own little sandbox. (And even there there are things that you can't change on the fly.)

Your best bet is probably to use the servers IP address rather than hostname. Slightly harder, but not that hard if you just need to resolve a single address, would be to put a DNS server on your Mac and configure your iPhone to use that.

Stephen Darlington
+1  A: 

This doesn't directly answer your question, but it does solve your problem...

What make of router do you have? Your router firmware may allow you to set DNS records for your local network. This is what I do with the Tomato firmware

Andrew Bullock
thanks, this is what I did to solve the issue ;)
sfa
+1  A: 

Don't change the DNS on the phone. Instead, connect with wifi to the local network and you are all set.

At my office, we have internal servers with internal DNS that are not exposed to the Internet. I just connect with iPhone to the office wifi and can then access them fine.

YMMV, but instead of configuring the phone DNS, it feels to me that just setting up local internal DNS and wifi is a cleaner and easier solution.

Jaanus
+1  A: 

I just edited my iPhone's 'hosts' file successfully (on Jailbroken iOS 4.0).

  • Installed OpenSSH onto iPhone via Cydia
  • Using a SFTP client like FileZilla on my computer, I connected to my iPhone
    • Address: [use your phone's IP address or hostname, eg. simophone.local]
    • Username: root
    • Password: alpine
  • Located the /etc/hosts file
  • Made a backup on my computer (in case I want to revert my changes later)
  • Edited the hosts file in a decent text editor (such as Notepad++). See here for an explanation of the hosts file.
  • Uploaded the changes, overwriting the hosts file on the iPhone

The phone does cache some webpages and DNS queries, so a reboot or clearing the cache may help. Hope that helps someone.

Simon.

Simon
A: 

@Simon I followed the same steps, but it didn't work. Then i tried to change encoding settings, and got it! You have to convert your host file to ANSI in Notepad++ before you save it. For whom failed to get the host file working; click "Convert to ANSI" under "Encoding" menu.

trkaplan