For my development process I need to access a webserver which is behind a VPN and has no DNS entry. What I was doing on 4.x was to edit /etc/hosts on the iPhone, and add it to the hosts file.
Now I'm on 5.0 beta, and don't want to jailbreak for now just for this purpose.
Is there a way I can add a line to /etc/hosts, just for development purposes (the final, distribution application does not need this hack), without jailbreaking? Can I use other means (declare a fake DNS entry by some unknown means at application launch, for example)?
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". Save this answer.
Just like in macOS, you can change the DNS servers on your iPhone. This can significantly speed up Safari and other iPhone apps that use the Internet. For a general introduction to DNS, and to learn why you would want to change the DNS servers on your iPhone, see How to Change Your Mac's DNS Servers.
EDIT: If you're willing to purchase a small license, I recommend using Charles Proxy, a web debugging proxy tool. It will also resolve domains from your local /etc/hosts, and it gives a lot of bonus features (i.e. inspect requests/responses and throttle network speeds). I only stumbled upon this tool from a WWDC video and I'm not affiliated with the product at all. I recommend reading Chris Ching's tutorial for iPhone and Charles Proxy to get you started.
To add to Ramon's answer, a way around it is to setup your local computer as a DNS server and have your iPhone point to your computer as a DNS server. This would also work for Android devices as well
brew install dnsmasq
dnsmasq
is a lightweight dns server that will fallback to the original DNS server when it encounters an unknown domainaddress=/.your.domain.com/10.0.0.5
to the file /usr/local/etc/dnsmasq.conf
10.0.0.5
is whatever the IP address assigned to your local computer by your router. You can find this via Network Utility
(if you want to be fancy, you can assign a static IP to your local computer in your router)sudo dnsmasq
dnsmasq
will fulfill unknown entries through the other known DNS servers. Without the router entry, you're whatever devices connected to you dnsmasq
won't know how to connect to the internet.dnsmasq
will look at your /etc/hosts, so if you had pointed your.domain.com
to 127.0.0.1
, your iPhone will resolve your.domain.com
to 127.0.0.1
, which means you won't connect to anything. To change this behaviour edit uncomment the #no-hosts
line in the dnsmasq config.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With