https://github.com/b2un0/esphome-dns-rewrite-proxy
use your esp32 as dns rewrite proxy
https://github.com/b2un0/esphome-dns-rewrite-proxy
dns-proxy dns-resolver dns-rewrite dns-server esphome esphome-component
Last synced: 25 days ago
JSON representation
use your esp32 as dns rewrite proxy
- Host: GitHub
- URL: https://github.com/b2un0/esphome-dns-rewrite-proxy
- Owner: b2un0
- License: mit
- Created: 2025-11-03T16:11:46.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-11-03T17:01:03.000Z (8 months ago)
- Last Synced: 2025-12-26T22:56:03.080Z (6 months ago)
- Topics: dns-proxy, dns-resolver, dns-rewrite, dns-server, esphome, esphome-component
- Language: C++
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# esphome DNS Rewrite Proxy
This ESPHome component acts as a DNS proxy that rewrites DNS queries based on user-defined rules.
Records not found in the rewrite rules are forwarded to the upstream DNS server from the current network configuration.
Tested on `ESP32-C3` and `ESP32-S3` devices. Support for `ESP8266` is not available due to memory constraints.
## Konfiguration Example
```yaml
external_components:
- source: github://b2un0/esphome-dns-rewrite-proxy@main
dns_proxy:
id: dns_server
records:
- domain: "tc.fritz.box"
ip: "192.168.155.250"
- domain: "geo.hivebedrock.network"
ip: "192.168.155.15"
- domain: "play.inpvp.net"
ip: "192.168.155.15"
- domain: "mco.lbsg.net"
ip: "192.168.155.15"
- domain: "play.galaxite.net"
ip: "192.168.155.15"
- domain: "hivebedrock.network"
ip: "192.168.155.15"
- domain: "mco.cubecraft.net"
ip: "192.168.155.15"
- domain: "mco.mineplex.com"
ip: "192.168.155.15"
```
## Sensors
```yaml
sensor:
- platform: template
name: "DNS Query Count"
id: query_count_sensor
accuracy_decimals: 0
state_class: "total_increasing"
icon: "mdi:dns"
lambda: |-
return id(dns_server).get_query_count();
update_interval: 10s
- platform: template
name: "DNS Forwarded Count"
id: forwarded_count_sensor
accuracy_decimals: 0
state_class: "total_increasing"
icon: "mdi:dns-outline"
lambda: |-
return id(dns_server).get_forwarded_count();
update_interval: 10s
- platform: template
name: "DNS Records Count"
id: record_count_sensor
accuracy_decimals: 0
state_class: "measurement"
icon: "mdi:database"
lambda: |-
return id(dns_server).get_record_count();
update_interval: 60s
```
## Test if rewrite works
in case the esp device has the ip `192.168.155.51` and you have the `tc.fritz.box` domain rewritten, you can test it
with:
```shell
nslookup tc.fritz.box 192.168.155.51
```
the answer should be something like:
```plain
Server: 192.168.155.51
Address: 192.168.155.51#53
Non-authoritative answer:
Name: tc.fritz.box
Address: 192.168.155.250
```
and in the esp log you should see something like:
```plain
[D][dns_redirect:171]: DNS query for: tc.fritz.box (ID: b6e8)
[D][dns_redirect:187]: Local response: 192.168.155.250
```
## Test if forwarding works
for a domain that is not rewritten, e.g. `esphome.io`:
```shell
nslookup esphome.io 192.168.155.51
```
the answer should be something like:
```plain
Server: 192.168.155.51
Address: 192.168.155.51#53
Non-authoritative answer:
Name: esphome.io
Address: 104.21.87.21
Name: esphome.io
Address: 172.67.168.170
```
and in the esp log you should see something like:
```plain
[D][dns_redirect:171]: DNS query for: esphome.io (ID: c1fe)
[D][dns_redirect:228]: Forwarded query (ID: c1fe -> 9145)
[D][dns_redirect:309]: Forwarded response (ID: 9145 -> c1fe)
```
## Note
IPv6 is not supported at the moment.