OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • English Forums »
  • General Discussion »
  • DNS related task
« previous next »
  • Print
Pages: [1]

Author Topic: DNS related task  (Read 6040 times)

elektroinside

  • Hero Member
  • *****
  • Posts: 574
  • Karma: 51
    • View Profile
DNS related task
« on: January 25, 2018, 07:23:54 pm »
So, I was thinking...
I never heard of something similar, just came up with this idea, but maybe there's a way to do it.

The environment simplified:
So you got two (or more) DNS servers, each with its own records. Both (or all) might resolve the same hostname or only one of them can resolve the hostname, or none of them can resolve the hostname.

The task:
So you need to query a hostname. I would need a solution to get the resolved hostname ONLY if both (or all configured) servers are able to resolve it. If even one fails, do not resolve the hostname, stop querying the rest of the remaining servers and return the specific error "could not find host..."

Imagine the possibility to combine the power of OpenDNS with Adguard. Or other similar services.

Is it possible with OPNsense?


« Last Edit: January 25, 2018, 07:33:46 pm by elektroinside »
Logged
OPNsense v18 | HW: Gigabyte Z370N-WIFI, i3-8100, 8GB RAM, 60GB SSD, | Controllers: 82575GB-quad, 82574, I221, I219-V | PPPoE: RDS Romania | Down: 980Mbit/s | Up: 500Mbit/s

Team Rebellion Member

bartjsmit

  • Hero Member
  • *****
  • Posts: 2023
  • Karma: 194
    • View Profile
Re: DNS related task
« Reply #1 on: January 25, 2018, 07:32:12 pm »
That's not how DNS is defined - you may of course be able to define a protocol that follows those rules, but it won't be DNS.

Out of interest; what is your use case?

Bart...
Logged

elektroinside

  • Hero Member
  • *****
  • Posts: 574
  • Karma: 51
    • View Profile
Re: DNS related task
« Reply #2 on: January 25, 2018, 07:35:16 pm »
I know, the goal of a DNS server (or service) is to resolve, not to do the opposite.
Just updated my first post with details :)
Logged
OPNsense v18 | HW: Gigabyte Z370N-WIFI, i3-8100, 8GB RAM, 60GB SSD, | Controllers: 82575GB-quad, 82574, I221, I219-V | PPPoE: RDS Romania | Down: 980Mbit/s | Up: 500Mbit/s

Team Rebellion Member

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: DNS related task
« Reply #3 on: January 25, 2018, 07:45:46 pm »
You can use my filter if you like:
https://github.com/fabianfrz/dns

You can load a blacklist into it. Please note that it could be hard to get it running on OPNsense.
It should not be hard to provide a special module doing that (just try to resolve it and if it fails, you can make the request fail too).
Logged

elektroinside

  • Hero Member
  • *****
  • Posts: 574
  • Karma: 51
    • View Profile
Re: DNS related task
« Reply #4 on: January 25, 2018, 08:05:21 pm »
Thank you!

But if i got it right, from the code, this implies i do have a blacklist defined... which i don't. The services i mentioned (i think) simply don't have a record of the hostnames they try to protect you from. How they maintain this "resolving", i have no idea.

Basically, i don't have a blacklist. In this case, a DNS proxy would not work... I'm not a dev, so i could be wrong (a strong possibility) about the code.
Logged
OPNsense v18 | HW: Gigabyte Z370N-WIFI, i3-8100, 8GB RAM, 60GB SSD, | Controllers: 82575GB-quad, 82574, I221, I219-V | PPPoE: RDS Romania | Down: 980Mbit/s | Up: 500Mbit/s

Team Rebellion Member

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: DNS related task
« Reply #5 on: January 25, 2018, 09:11:09 pm »
You are right, the blacklist module is using a list of domains. However if you add a file into the modules directory, it will be included automatically and if your class is in the special module, it will be used as a filter. You just have to add some code in the method to check the request. For example, you can query the DNS Server via "Resolv" and then check if it returns an IP.

for example:
https://ruby-doc.org/stdlib-2.5.0/libdoc/resolv/rdoc/Resolv/DNS.html#method-i-getaddress

for example (note: I have not even run it):


Code: [Select]
require 'resolv'
module DNSFilterModule
  class ResolvableCheck
    def initialize(config, logger)
      @config = config
      @logger = logger
      @resolver_cfg = config['ResolvableBy']
      @dns = Resolv::DNS.new(:nameserver => @resolver_cfg['nameserver'] ,:search => @resolver_cfg['search'],:ndots => 1)
    end
    def process(name, res_class, transaction)
      if res_class.to_s.include? '::A'
        begin
          @dns.getaddress(name)
          return
        rescue Resolv::ResolvError => ex
          raise DNSBlockException.new
        end
      end
    end
  end
end
« Last Edit: January 25, 2018, 09:16:54 pm by fabian »
Logged

elektroinside

  • Hero Member
  • *****
  • Posts: 574
  • Karma: 51
    • View Profile
Re: DNS related task
« Reply #6 on: January 25, 2018, 09:37:18 pm »
I'll try this approach, many thanks!

I was further thinking, wouldn't this be a reasonable marketing point if, say, would be somehow integrated into OPNsense?

It's another thing to maintain, but who knows.

I'm imagining this like a checkbox under Unbound (or Dnsmasq, or System: Settings: General), called, I don't know, "Protection mode" with the description "Combine different DNS services and only return an IP if all o them can resolve the queries".
If checked, it will load the DNS proxy and do just that. Of course, this will naturally mean longer time to get an IP (slower DNS performance overall). But might be worth it.

For example, you can have the customizable power of OpenDNS to block malware and the non-customizable AdGuard servers to block ads under one hood.
Logged
OPNsense v18 | HW: Gigabyte Z370N-WIFI, i3-8100, 8GB RAM, 60GB SSD, | Controllers: 82575GB-quad, 82574, I221, I219-V | PPPoE: RDS Romania | Down: 980Mbit/s | Up: 500Mbit/s

Team Rebellion Member

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: DNS related task
« Reply #7 on: January 25, 2018, 10:10:37 pm »
Quote from: elektroinside on January 25, 2018, 09:37:18 pm
I was further thinking, wouldn't this be a reasonable marketing point if, say, would be somehow integrated into OPNsense?
No this is really an edge case...


Quote from: elektroinside on January 25, 2018, 09:37:18 pm
For example, you can have the customizable power of OpenDNS to block malware and the non-customizable AdGuard servers to block ads under one hood.
You may also be interested in quad 9 if you want a DNS provider filtering malware etc.:
https://www.quad9.net/#/faq
Logged

elektroinside

  • Hero Member
  • *****
  • Posts: 574
  • Karma: 51
    • View Profile
Re: DNS related task
« Reply #8 on: January 25, 2018, 11:19:45 pm »
Yes, I know about Quad9, quite powerful. There are also others. But there is not one to offer both (malware + ads + why not, other stuff). Each is best doing one specific thing. This is why I still think it's a good idea to combine them somehow. DNS is fast and why block the malware or ad if you can block the source directly. Why maintain lists and import stuff when there are publicly available free & powerful tools to do just that with the right infrastructure to handle the load.

This may be part of "security through obscurity" mentality, which is better than "trust but verify".

So I think I will try your initial approach, maybe I'll have some amount of success.

Thank you.
« Last Edit: January 25, 2018, 11:28:23 pm by elektroinside »
Logged
OPNsense v18 | HW: Gigabyte Z370N-WIFI, i3-8100, 8GB RAM, 60GB SSD, | Controllers: 82575GB-quad, 82574, I221, I219-V | PPPoE: RDS Romania | Down: 980Mbit/s | Up: 500Mbit/s

Team Rebellion Member

elektroinside

  • Hero Member
  • *****
  • Posts: 574
  • Karma: 51
    • View Profile
Re: DNS related task
« Reply #9 on: January 26, 2018, 12:08:04 am »
Another idea would be to get a Raspberry PI (or use a vm), install pi-hole and use one of the malware blocking DNS servers as the upstream servers.

Hmm..
« Last Edit: January 26, 2018, 01:12:01 am by elektroinside »
Logged
OPNsense v18 | HW: Gigabyte Z370N-WIFI, i3-8100, 8GB RAM, 60GB SSD, | Controllers: 82575GB-quad, 82574, I221, I219-V | PPPoE: RDS Romania | Down: 980Mbit/s | Up: 500Mbit/s

Team Rebellion Member

elektroinside

  • Hero Member
  • *****
  • Posts: 574
  • Karma: 51
    • View Profile
Re: DNS related task
« Reply #10 on: January 26, 2018, 04:52:57 pm »
Well, an autostarting VM with pi-hole did the trick :)
Logged
OPNsense v18 | HW: Gigabyte Z370N-WIFI, i3-8100, 8GB RAM, 60GB SSD, | Controllers: 82575GB-quad, 82574, I221, I219-V | PPPoE: RDS Romania | Down: 980Mbit/s | Up: 500Mbit/s

Team Rebellion Member

elektroinside

  • Hero Member
  • *****
  • Posts: 574
  • Karma: 51
    • View Profile
Re: DNS related task
« Reply #11 on: January 26, 2018, 09:28:09 pm »
Curious geek statistics:

My TV queried the (new, hence the statistics) pi-hole DNS server 11.000 (!!) times in the last ~3-4hrs, out of which more than 2.000 where for *.adcolony.com and other ad providers. This is just my TV.
35% of my queries overall in my LAN where blocked (ad & malware as categories, but only ads where blocked), and I only browsed 3-4 websites. Not a single malware anywhere (scanned the files & traffic).
« Last Edit: January 26, 2018, 09:31:11 pm by elektroinside »
Logged
OPNsense v18 | HW: Gigabyte Z370N-WIFI, i3-8100, 8GB RAM, 60GB SSD, | Controllers: 82575GB-quad, 82574, I221, I219-V | PPPoE: RDS Romania | Down: 980Mbit/s | Up: 500Mbit/s

Team Rebellion Member

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 17706
  • Karma: 1618
    • View Profile
Re: DNS related task
« Reply #12 on: January 27, 2018, 01:43:04 pm »
Smart TVs don't get smart by doing nothing, eh.... weird.
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • English Forums »
  • General Discussion »
  • DNS related task
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2024 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2