C
C
chief2019-12-16 15:19:54
Domain Name System
chief, 2019-12-16 15:19:54

How to forward a DNS query to another server for a particular IP range using iptables?

Can't ping by PC name (which is 1-2 levels up on the network).
How can I add another specific DNS server just for the 192.168.5.x IP range?
Or only for domains of one word (pc name)?. In general, so that requests to sites remain on 8.8.8.8, and requests to Vasya-PC are sent to 192.168.0.6, for example?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
mikes, 2019-12-16
@mikes

you are requesting in DNS not IP, but FQDN, that's what you have to dance from.
if you want to resolve the world through 8.8.8.8 and pc.somedomainname.ru through 192.168.0.6, then you can’t do this without parsing the dns requests themselves.
Of course, you can make a rule in iptables that will look for the word "somedomainname" for packets on port 53 and do DNAT to the right place, but it's better to start your own DNS server and configure forward zones according to your needs.
dnsmasq or coredns are quite suitable.
But in general, there is little input data, if these are all your networks, then why not make a DNS server with ddns via dhcp or register all the necessary records yourself.

T
Talyan, 2019-12-16
@flapflapjack

iptables -t nat -I -s 192.168.5.0/24 -d !192.168.0.6 -p tcp -m tcp --dport 53  -j DNAT --to-destination 192.168.0.6:53
iptables -t nat -I -s 192.168.5.0/24 -d !192.168.0.6 -p udp -m udp --dport 53  -j DNAT --to-destination 192.168.0.6:53

try like this. Just what are you pinging? Hostname or IP address?
If an aypishnik, then DNS has nothing to do with it.

A
Alexander, 2019-12-16
@UPSA

Everything is as usual ...
1. Well, please, put a caching DNS server on the network)))
Then all computers on the network will request it. You can set the IP-Name correspondence on it, otherwise the ping by name does not work. An exception, on a computer in hosts, prescribe names.
2. Complexity with subnets.
The DNS server must be available on all networks at the same time. Therefore:
a) put a DNS server in each subnet, where to prescribe the correspondence of names.
b) install a DNS server on a computer with several network interfaces. Each interface to its own subnet.
c) build a subnet common with other subnets and install a DNS server in it
3. And add - routing packets through iptables already by IP addresses

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question