Log DNS requests to syslog for one network

As @trendy said, by default only the first rule will be taken into account.
There is a workaround, but it is a bit complicated and I don't know if it's worth the effort.
You can use the iptables statistic module, which is part of the iptables-mod-ipopt package.
The rules should look like this:

config redirect
        option target 'DNAT'
        option name 'DNS1'
        option src 'lan'
        option src_dport '53'
        option dest_ip '208.67.222.222'
        option dest_port '53'
        option reflection '0'
        option dest 'lan'
        option extra '-m statistic --mode nth --every 2 --packet 0'
        list proto 'tcp'
        list proto 'udp'
        option src_ip '192.168.1.0/24'
        
config redirect
        option target 'DNAT'
        option name 'DNS2'
        option src 'lan'
        option src_dport '53'
        option dest_ip '208.67.220.220'
        option dest_port '53'
        option reflection '0'
        option dest 'lan'
        list proto 'tcp'
        list proto 'udp'
        option src_ip '192.168.1.0/24'

Check the results running iptables -t nat -nvL zone_lan_prerouting

Chain zone_lan_prerouting (3 references)
 pkts bytes target     prot opt in     out     source               destination
 2254  535K prerouting_lan_rule  all  --  *      *       0.0.0.0/0            0.0.0.0/0            /* !fw3: Custom lan prerouting rule chain */
    0     0 DNAT       tcp  --  *      *       192.168.1.0/24      0.0.0.0/0            tcp dpt:53 statistic mode nth every 2 /* !fw3: DNS1 */ to:208.67.222.222:53
    7   471 DNAT       udp  --  *      *       192.168.1.0/24      0.0.0.0/0            udp dpt:53 statistic mode nth every 2 /* !fw3: DNS1 */ to:208.67.222.222:53
    0     0 DNAT       tcp  --  *      *       192.168.1.0/24      0.0.0.0/0            tcp dpt:53 /* !fw3: DNS2 */ to:208.67.220.220:53
    6   396 DNAT       udp  --  *      *       192.168.1.0/24      0.0.0.0/0            udp dpt:53 /* !fw3: DNS2 */ to:208.67.220.220:53
2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.