Page 1 of 1

Assign Different DNS to DHCP clients

Posted: Fri Apr 13, 2018 12:37 pm
by setham
Hello,

Thanks in advance for any help.

Through DHCP I want to assign different DNS to clients, using option 6 editing /etc/config/dhcp and adding

config dhcp 'lan'
list 'dhcp_option' '6,192.168.1.10, 192.168.1.11'

I can assign a different to the router DNS servers (192.168.1.1)

I would like to add the option at the client level, is there a place in Gargoyle where I can add DHCP options at client level like it is possible with OpenWRT (eg. OpenWrt Chaos Calmer 15.05.1) where we can add it at the corresponding "config host" entry?

Thanks

Re: Assign Different DNS to DHCP clients

Posted: Fri Apr 13, 2018 2:53 pm
by ispyisail
command line only (not through the GUI)

Re: Assign Different DNS to DHCP clients

Posted: Fri Apr 13, 2018 7:02 pm
by setham
ispyisail wrote:command line only (not through the GUI)
Hi,

Not even through config files? When do you say command line only may you please elaborate a bit more on how to do it?

Thanks in advance

Re: Assign Different DNS to DHCP clients

Posted: Fri Apr 13, 2018 9:36 pm
by ispyisail

Re: Assign Different DNS to DHCP clients

Posted: Sat Apr 14, 2018 2:44 pm
by setham
ispyisail wrote:viewtopic.php?f=8&t=8505
Hi,

I know how to access the cli.

I am in need for help on how to set DHCP client level options in gargoyle.

I am having a difficult time to locate where (not how) can I add those client level options.

Thanks

Re: Assign Different DNS to DHCP clients

Posted: Sat Apr 14, 2018 7:05 pm
by Lantis
Have you read the dnsmasq OpenWrt wiki? In particular, the section on assigning individual options to hosts?
https://wiki.openwrt.org/doc/uci/dhcp#c ... l_options1

This is probably the solution you are after, but it isn’t compatible with the Gargoyle GUI. any change you make in the GUI after setting this up might revert it.

Re: Assign Different DNS to DHCP clients

Posted: Wed May 09, 2018 6:38 pm
by setham
Thanks.

I ended up using iptables to pre-route blocks of IPs or individual hosts to different DNS's.

Not pretty but easy to track and configure with scripts and custom config files.
Lantis wrote:Have you read the dnsmasq OpenWrt wiki? In particular, the section on assigning individual options to hosts?
https://wiki.openwrt.org/doc/uci/dhcp#c ... l_options1

This is probably the solution you are after, but it isn’t compatible with the Gargoyle GUI. any change you make in the GUI after setting this up might revert it.

Re: Assign Different DNS to DHCP clients

Posted: Wed May 09, 2018 7:12 pm
by d3fz
setham wrote:I ended up using iptables to pre-route blocks of IPs or individual hosts to different DNS's.

Not pretty but easy to track and configure with scripts and custom config files.
Mind sharing your solution steps using iptables?

Might help other users in the same/similar situation.

Thanks.

Re: Assign Different DNS to DHCP clients

Posted: Thu May 10, 2018 12:20 pm
by setham
d3fz wrote:
setham wrote:I ended up using iptables to pre-route blocks of IPs or individual hosts to different DNS's.

Not pretty but easy to track and configure with scripts and custom config files.
Mind sharing your solution steps using iptables?

Might help other users in the same/similar situation.

Thanks.
Sure thing, but I have to apologize, when looking for the scripts I recalled that I ended up creating the scripts for a pihole running raspbian. Gargoyle has the pihole IP as DNS for DHCP and I run the script on the pihole.

The script can be highly optimized, I use it with a text file that has the hosts or ip-ranges that I want to redirect to a different DNS. Everytime the pihole is rebooted runs the scripts for all the hosts in the text file. Manually you can add or remove hosts on demand.

The concept is the same but I have not tested them in the gargoyle router. I will try to test/port them over the weekend.

Code: Select all

#!/bin/bash

# set -x

if [ $# -ne 4 ];
    then echo "illegal number of parameters"
    exit 1
fi

if [ "$1" == "-e" ]
then
  sysctl -w net.ipv4.conf.all.forwarding=1
  iptables -t nat -I PREROUTING -p udp -s $2 --dport 53 -j DNAT --to $3
  iptables -t nat -A POSTROUTING -p udp --dport 53 -m conntrack --ctdir ORIGINAL --ctstate DNAT -j SNAT --to-source $4
  exit 0
fi

if [ "$1" == "-d" ]
then
  sysctl -w net.ipv4.conf.all.forwarding=0
  iptables -t nat -D PREROUTING -p udp -s $2 --dport 53 -j DNAT --to $3
  iptables -t nat -D POSTROUTING -p udp --dport 53 -m conntrack --ctdir ORIGINAL --ctstate DNAT -j SNAT --to-source $4
  exit 0
fi

echo "usage: override_dns.sh -[e|d] ip dns defaultdns"
exit 1

# override_dns.sh -e client dnsserver defaultdns -> enables dnsserver for client
# override_dns.sh -d client dnsserver defaultdns -> deletes dnsserver for client, defaults to dhcp provided