Giter Site home page Giter Site logo

ekristen / dns-proxy Goto Github PK

View Code? Open in Web Editor NEW
201.0 12.0 43.0 176 KB

Simple DNS Proxy written in Node.JS. Override hosts, domains, or tlds. Redirect certain domains to different nameservers.

License: MIT License

JavaScript 94.40% Shell 5.60%
dns dns-proxy dnsmasq nodejs javascript

dns-proxy's Introduction

CircleCI npm npm David David

DNS Proxy

Simple DNS Proxy written in Node.JS

Designed to allow you to override hosts or domains with specific answers or override tlds, or domains to use different nameservers. Useful when using VPN connections with split DNS setups.

This app makes use of the rc module for configuration, the default configuration is below, use any file location to override the defaults. Appname is dnsproxy when creating a configuration file.

I can guarentee this app isn't perfect but fulfills my current needs for routing certain domains to private IP name servers when on VPN.

Install

Grab a binary from the release section.

OLD METHOD

npm install -g dns-proxy

Features

  • Override nameservers for TLD
  • Override nameservers for Domain
  • Set IP for entire domain or TLD. (example: if you want to answer 192.168.11.1 for local.dev)
  • Set IP for host
  • Wildcard Support

Examples

For nameserver overrides if an answer isn't received by a threshold (350ms by default) DNS proxy will fallback to one of the default nameservers provided in the configuration (by default 8.8.8.8 or 8.8.4.4)

TLD Specific Nameserver

This will send all .com queries to 8.8.8.8 and .dk queries to 127.0.0.1 and custom port 54.

"servers": {
  "com": "8.8.8.8",
  "dk": "127.0.0.1:54"
}
  • This is a snippet that will go into your rc config file.

Domain Specific Nameserver

This will match all google.com and its subdomains.

"servers": {
  "google.com": "8.8.8.8"
}
  • This is a snippet that will go into your rc config file.

Domain Specific Answers

This will match all of google.com and its subdomains and return 127.0.0.1 as the answer. This technically doens't even have to be a real domain or a full domain, if you configure ogle.com and do a lookup on google.com, the ogle.com will match.

"domains": {
  "google.com": "127.0.0.1"
}

Wildcard Domain Specific Answers

this will resolve review-someotherstring.google.com to 127.0.0.1

"domains": {
  "review-*.google.com": "127.0.0.1"
}

Aliases

Domains and Hosts support aliases now, whereby you can define a host like normal such as "hi": "127.0.0.1" and in another entry reference it like "hello": "hi".

Default Configuration

This is the default configuration in the application, you should override this by creating the proper rc file in one of the searchable paths.

{
  port: 53,
  host: '127.0.0.1',
  logging: 'dns-proxy:query',
  nameservers: [
    '8.8.8.8',
    '8.8.4.4'
  ],
  servers: {},
  domains: {
    'dev': '127.0.0.1'
  },
  hosts: {
    'devlocal': '127.0.0.1'
  }
}
  • Note this snippet is JavaScript and rc config file format is JSON.

Logging

Logging is handled by the simple lightweight debug package. By default all queries are logged. To change the logging output update the logging variable to any of the following: dns-proxy:error, dns-proxy:query, dns-proxy:debug. You can specify all or none, separate using a comma, a wildcard can be used as well.

Running as a Service

OSX

You can copy the resources/launchd.plist file into /Library/LaunchDaemons as com.github.ekristen.dns-proxy.plist. To start just run sudo launchctl load /Library/LaunchDaemons/com.github.ekristen.dns-proxy.plist. This will also make the dns-proxy service to start on boot.

dns-proxy's People

Contributors

ekristen avatar frozzare avatar greenkeeperio-bot avatar renovate-bot avatar renovate[bot] avatar wclr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dns-proxy's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/auto-release.yml
  • release-drafter/release-drafter v5
  • actions/checkout v2
  • actions/setup-node v1
  • shogo82148/actions-upload-release-asset v1
.github/workflows/tests.yml
  • actions/checkout v2
  • actions/setup-node v1
npm
package.json
  • debug ^4.0.0
  • native-dns-packet ~0.1.1
  • rc ^1.2.8
  • wildcard2 0.0.2
  • pkg 5.5.2
  • standard 14.3.3

  • Check this box to trigger a request for Renovate to run again on this repository

Doesn't work when installed as a package dependency

When adding dns-proxy as a package dependency and trying to run it using a npm script.

  // ...
  "scripts": {
    "start": "dns-proxy"
  },
  "dependencies": {
    "dns-proxy": "*"
    // ...
  }
  // ...

It will try to load ../dns-proxy.js which doesn't exist relative to the bin that node runs.

Workaround

  // ...
  "scripts": {
    "start": "node node_modules/dns-proxy"
  }
  // ...

ERR_SOCKET_CANNOT_SEND

Hey - don't know if you're still actively maintaining this. I have it running on my home network as my router doesn't allow me to add DNS entries for local machines, and it works (almost*) perfectly. So thank you.

Almost*: Running on Ubuntu 18.04.5. Every so often in syslog I see the following:

Sep 14 14:52:49 server1 dns-proxy[7015]: 2020-09-14T18:52:49.197Z dnsproxy:error Socket Error: Error [ERR_SOCKET_CANNOT_SEND]: Unable to send data
Sep 14 14:52:49 server1 systemd[1]: dns-proxy.service: Main process exited, code=exited, status=5/NOTINSTALLED
Sep 14 14:52:49 server1 systemd[1]: dns-proxy.service: Failed with result 'exit-code'.
Sep 14 14:52:50 server1 systemd[1]: dns-proxy.service: Service hold-off time over, scheduling restart.
Sep 14 14:52:50 server1 systemd[1]: dns-proxy.service: Scheduled restart job, restart counter is at 31.
Sep 14 14:52:50 server1 systemd[1]: Stopped Local DNS proxy.
Sep 14 14:52:50 server1 systemd[1]: Started Local DNS proxy.
Sep 14 14:52:50 server1 dns-proxy[12011]: 2020-09-14T18:52:50.544Z dnsproxy:info we are up and listening at 192.168.77.2 on 53

It's not really a problem - the server restarts and runs fine - but maybe worth investigating. Happens probably 3 times a day.

Thanks.

Bad issue with rerouting IPs

You need to make sure that domain.indexOf(s) does not equal -1 in your server.js file in order to fix the problem. The more IPs that are being routed, the more prominent the issue is. Also, include your github repo in with your json file so that users can get here easily from the npm site.

Add IPv6 support

On Windows, as soon as an IPv6 address is assigned, IPv6 takes precedence over IPv4, so DNS queries will always be sent to the IPv6 DNS server. It would be great if you could add IPv6 support so dns-proxy can listen on [::1]:53 as well.

non-alias host entry crashes

I was getting a crash until I replaced this line in server.js:

if (opts.hosts[opts.hosts[h]] != 'undefined') {

with this line:

if (opts.hosts[opts.hosts[h]]) {

Using launchdaemon randomly caused EMFILE errors

Mainly after a wake up, node will complain about EMFILE.

Not exactly sure of the cause at the moment I'm testing with maxprocs set to 2048, hard to believe that has been reached and max files are set to 65535

Release binary broken

Downloaded the latest win release. Executable terminates with error:

c:\Users****\Downloads>dns-proxy-win.exe
path.js:28
throw new TypeError('Path must be a string. Received ' + inspect(path));
^

TypeError: Path must be a string. Received undefined
at assertPath (path.js:28:11)
at Object.resolve (path.js:221:7)
at Object.fs.watchFile (fs.js:1471:25)
at Object. (C:\snapshot\dns-proxy\dns-proxy.js:0:0)
at Module._compile (pkg/prelude/bootstrap.js:1243:22)
at Object.Module._extensions..js (module.js:644:10)
at Module.load (module.js:552:32)
at tryModuleLoad (module.js:495:12)
at Function.Module._load (module.js:487:3)
at Function.Module.runMain (pkg/prelude/bootstrap.js:1298:12)

Ask about https

Hi,

Thanks for your library.
I pull project then run with node in terminal by config below :

{
  port: 53,
  host: '127.0.0.1',
  logging: 'dnsproxy:query,dnsproxy:info,dnsproxy:error',
  nameservers: [
    '1.1.1.1',
    '1.0.0.1'
  ],
  servers: {
    
  },
  domains: {    
    "*" : '127.0.0.1'
  },
  hosts: {
    devlocal: '127.0.0.1'
  },
  fallback_timeout: 350,
  reload_config: true
}

127.0.01 is a server local static html.

But it only work with domain http. When i access a domain https browser display "This site can’t be reached"
How to work with https?

Thank you.

Add regex support

Add regex support in the hosts directive, maybe the domains directive too.

Should probably add a configuration switch to enable/disable regex support.

Add Support for Wildcards within Domain Specific Answers

Description

Currently we're trying to resolve all requests to https://review-*.salte.io internally.

While at the same we need https://www.salte.io to resolve externally.

This means that we can't just do:

{
  // ...
  "domains": {
    "salte.io": "192.168.1.50"
  }
  // ...
} 

Instead we need something like this:

{
  // ...
  "domains": {
    "review-*.salte.io": "192.168.1.50"
  }
  // ...
} 

Unable to use it

How to use this? where should i place the configuration file?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.