How to set custom DNS server for Chrome browser?

92,086

Solution 1

You could use an extension to redirect a named HTTP request to one using an IP address.

This solution doesn't require any modification of the DNS or hosts file, and this redirection may possibly be enabled on and off via the extension :

Switcheroo Redirector

Solution 2

Chromium's DNS resolver is broken, and it won't respect the order in resolv.conf. So when I try to connect to hosts on my VPN, which the system resolves correctly using the VPN's DNS server, Chromium instead uses the non-VPN DNS, and resolves it to my internet provider's advertisement page (which they gratuitously reply with to any non-resolving host).

The only solution I've found was to add private IPs to /etc/hosts.

Solution 3

FoxyProxy Chrome extension worked nicely for me. It is also available for Mozilla Firefox as well. However, can take some time to configure initially. Have tested only for locally hosted sites without HTTPS.

Host Switch Plus extension for Chrome worked for me. Though easier to configure, as it allows multiple tagged entries for different environments as well. However, it seems to have some error which causes it to fail sometimes.

Solution 4

In case the --host-rules does not work, try --host-resolver-rules.

Example: --host-resovler-rules=MAP example.com 127.0.0.1.

Note that we do not need to double quote the "MAP ... ..." part. (Verified in Version 89 of both Chrome non-headless and Chrome headless mode).

Also see a discussion on this: https://bugs.chromium.org/p/chromium/issues/detail?id=798793

Share:
92,086

Related videos on Youtube

acelot
Author by

acelot

Updated on September 18, 2022

Comments

  • acelot
    acelot almost 2 years

    I have a local DNS server that resolves all URLs *.domain.tld to 127.0.0.1. Also, I have the production server with the same address *.domain.tld. They have the same names, because subdomains interact with each other, and I have hardcoded domain URLs. I can't change them in the production server.

    The problem is to reach the production server from my developer computer without touching the DNS server and /etc/hosts.

    I found some options for Chrome such as --dns-server, --host-rules, but none is working. I have Google Chrome 23.0.1271.64 and Chromium 22.0.1229.94 on Ubuntu 12.10 64-bit.

    • poplitea
      poplitea over 11 years
      What OS are you on? It's not an option to modify /etc/hosts (or its equivalent) on your computer (the one with Chrome)?
    • Flup
      Flup over 11 years
      You could run a local proxy with a rule to route your request as you wish.
    • Oliver Salzburg
      Oliver Salzburg over 11 years
      Seems like --dns-server is no longer supported.
    • harrymc
      harrymc over 11 years
      Would for example the Switcheroo Redirector extension or the Redirector extension be useful?
    • Louis Waweru
      Louis Waweru over 11 years
      @harrymc Those two claim to redirect HTTP requests, but I think a DNS request is something different.
    • harrymc
      harrymc over 11 years
      @Louis: The post says Chrome, and these extensions can redirect a named HTTP request to an IP address, therefore solving the problem without monkeying with DNS.
    • Sachin
      Sachin over 8 years
    • Ali
      Ali over 5 years
      star this feature request: bugs.chromium.org/p/chromium/issues/…
  • Louis Waweru
    Louis Waweru over 11 years
    thanks harrymc, I think this could solve the asker's problem. I actually offered the bounty because I had the same title question, but the details were different. I want all DNS requests to go a different route. So, not just example.com, but all the images, scripts, etc. that might be found on the page. Maybe I should ask a separate question?
  • harrymc
    harrymc over 11 years
    Such an extension (if programmed correctly) should work on all the page elements, including images etc. Unfortunately, as mentioned above, I cannot test.
  • Louis Waweru
    Louis Waweru over 11 years
    Yes, but that's assuming all the redirects were hardcoded. I was looking for a solution that would avoid DNS leaks for general browsing when using a proxy server. It's my fault that I didn't think that there were solutions for his specific problem, and assuming there was a general solution to the title question.
  • Spooky
    Spooky over 9 years
    This extension replaces URLs in the HTTP response body; it has nothing to do with DNS. This does not answer the question.
  • cregox
    cregox about 9 years
    Redirector updated link but none of this work as adding custom DNS...
  • Sachin
    Sachin over 8 years
    @harrymc Redirector Chrome store link is not valid anymore. Maybe you want to add Requestly to the list chrome.google.com/webstore/detail/requestly/….
  • DavidPostill
    DavidPostill almost 8 years
    Please read How do I recommend software for some tips as to how you should go about recommending software. You should provide at least a link, some additional information about the software itself, and how it can be used to solve the problem in the question.
  • Justin Gardner
    Justin Gardner over 2 years
    This rocks! Thanks