/etc/hosts with NSURLProtocol
Latest commit 1164bfe Apr 16, 2014 @mattt Adding workspace
Failed to load latest commit information.
Example Initial Commit Apr 16, 2014
NSEtcHosts.xcworkspace Adding workspace Apr 16, 2014
NSEtcHosts Initial Commit Apr 16, 2014
LICENSE Initial Commit Apr 16, 2014
README.md Update README.md Apr 16, 2014



NSEtcHosts uses NSURLProtocol to intercept requests for specified host names, resolving them instead to a different IP address, similar to an /etc/hosts file on a Unix system. (This does not actually affect the actual hosts file used by iOS, nor does it affect routing behavior outside of the application process)

This is a proof-of-concept, and is not intended for use in production.


[NSURLProtocol registerClass:[EtcHostsURLProtocol class]];
[EtcHostsURLProtocol configureHostsWithBlock:^(id <EtcHostsConfiguration> configuration) {
    [configuration resolveHostName:@"google.com" toIPAddress:@""];

NSEtcHosts in Action

NSURL *URL = [NSURL URLWithString:@"http://google.com"];
[webView loadRequest:[NSURLRequest requestWithURL:URL]];


Mattt Thompson @mattt


NSEtcHosts is available under the MIT license. See the LICENSE file for more info.