Assign Different DNS to DHCP clients

General discussion about Gargoyle, OpenWrt or anything else even remotely related to the project

Moderator: Moderators

Post Reply
setham
Posts: 24
Joined: Sun Jun 28, 2015 1:47 pm

Assign Different DNS to DHCP clients

Post 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

ispyisail
Moderator
Posts: 5180
Joined: Mon Apr 06, 2009 3:15 am
Location: New Zealand

Re: Assign Different DNS to DHCP clients

Post by ispyisail »

command line only (not through the GUI)

setham
Posts: 24
Joined: Sun Jun 28, 2015 1:47 pm

Re: Assign Different DNS to DHCP clients

Post 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

ispyisail
Moderator
Posts: 5180
Joined: Mon Apr 06, 2009 3:15 am
Location: New Zealand

Re: Assign Different DNS to DHCP clients

Post by ispyisail »


setham
Posts: 24
Joined: Sun Jun 28, 2015 1:47 pm

Re: Assign Different DNS to DHCP clients

Post 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

Lantis
Moderator
Posts: 6735
Joined: Mon Jan 05, 2015 5:33 am
Location: Australia

Re: Assign Different DNS to DHCP clients

Post 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.
http://lantisproject.com/downloads/gargoyle_ispyisail.php for the latest releases
Please be respectful when posting. I do this in my free time on a volunteer basis.

setham
Posts: 24
Joined: Sun Jun 28, 2015 1:47 pm

Re: Assign Different DNS to DHCP clients

Post 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.

d3fz
Posts: 277
Joined: Sun Aug 28, 2016 7:34 pm

Re: Assign Different DNS to DHCP clients

Post 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.
TP-Link Archer C7 v2 - Gargoyle 1.12.X
TP-Link WR842ND v2 - Gargoyle 1.10.X
TP-Link RE450 AC v2 - Stock FW 1.0.4
TP-Link WA850RE v1.2 - LEDE 17.01.1

setham
Posts: 24
Joined: Sun Jun 28, 2015 1:47 pm

Re: Assign Different DNS to DHCP clients

Post 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

Post Reply