Assign Different DNS to DHCP clients

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

Moderator: Moderators

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

Assign Different DNS to DHCP clients

Postby setham » Fri Apr 13, 2018 12:37 pm

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: 4055
Joined: Mon Apr 06, 2009 3:15 am
Location: New Zealand

Re: Assign Different DNS to DHCP clients

Postby ispyisail » Fri Apr 13, 2018 2:53 pm

command line only (not through the GUI)

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

Re: Assign Different DNS to DHCP clients

Postby setham » Fri Apr 13, 2018 7:02 pm

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: 4055
Joined: Mon Apr 06, 2009 3:15 am
Location: New Zealand

Re: Assign Different DNS to DHCP clients

Postby ispyisail » Fri Apr 13, 2018 9:36 pm


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

Re: Assign Different DNS to DHCP clients

Postby setham » Sat Apr 14, 2018 2:44 pm

ispyisail wrote:https://www.gargoyle-router.com/phpbb/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: 4087
Joined: Mon Jan 05, 2015 5:33 am
Location: Australia

Re: Assign Different DNS to DHCP clients

Postby Lantis » Sat Apr 14, 2018 7:05 pm

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.
WRT1900AC V1 on 1.10.X
WNDR3800/WRT3200ACM in a constant state of flux
www.lantisproject.com for custom builds and other projects
www.lantisproject.com/gargoyle_ispyisail/ for the latest releases

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

Re: Assign Different DNS to DHCP clients

Postby setham » Wed May 09, 2018 6:38 pm

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: 256
Joined: Sun Aug 28, 2016 7:34 pm

Re: Assign Different DNS to DHCP clients

Postby d3fz » Wed May 09, 2018 7:12 pm

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

Tired of Chrome? Try Vivaldi - an advanced browser built for power users

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

Re: Assign Different DNS to DHCP clients

Postby setham » Thu May 10, 2018 12:20 pm

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


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests