Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OFF-TOPIC] [Need Help] How to use it in router which only supports IPv4 DNS? #91

Open
webpixeldesign opened this issue Apr 9, 2024 · 4 comments

Comments

@webpixeldesign
Copy link

I am using Xiaomi Router 3c & Router 4c, both of which only support IPv4 DNS. Cause when I entered the IPv6 one, it gave an error saying the DNS needs to of a value 255.255.255.255 max. The script is working perfectly fine. This is first time I used node.js, npm, etc. but surprisingly managed to do it in one go. Tried the output in two of my android devices and chrome browser using the dns over tls / https DNS and all are working fine.

I just couldn't manage to make it work in my router and windows 10 PC.

My ISP is using PPPoE connection type, which assigns random IP address to my network.

If someone can guide me how can I use this DNS with my router I'll be very grateful 🙏

mi3-wireless-router-repeater-mmode

@webpixeldesign
Copy link
Author

Forgot to mention that, the DNS Cloudflare provided to be used in IPv4 devices, didn't work. I mean the internet was working fine, but nothing was getting filtered. I was getting ads in all my devices.

@mrrfv
Copy link
Owner

mrrfv commented Apr 10, 2024

It's better to manually configure all your devices to use the DNS settings to benefit from DoH/DoT.

The DNS settings provided by Cloudflare might not've worked if you didn't link your IP address to the DNS location. This is required because we don't have an infinite amount of IPv4 addresses, so Cloudflare can't give everyone their personal IP for DNS. You can do this by clicking on the DNS location and pressing "Configure", then "Add IP" in the "Source IPv4 address" section.
Keep in mind that this may eventually break if you have a dynamic IP.

As an ideal alternative that doesn't use moving parts, run a tiny DNS server at home that forwards queries over to your DoH URL such as cloudflared:

cloudflared proxy-dns --address 0.0.0.0 --upstream https://changeme.cloudflare-gateway.com/dns-query

@galpt
Copy link

galpt commented Jul 8, 2024

@webpixeldesign

You can use IPv4 but you'll need a static IP address from your ISP, which most home ISPs don't give static IPs unless you specifically request it.

Go to your Cloudflare One dashboard > Gateway > DNS Locations and add your IPv4 there.

Screenshot 2024-07-08 100805

After that, Cloudflare will give you 2 IPv4 addresses that you can use on your router or anything that uses IPv4.
To check if the DNS works, you open those IPv4 addresses on your browser and they should show you a block page of your Gateway.

Screenshot 2024-07-08 101147

This will only work after you've added your ISP's IP address there.
I mentioned about getting a static IP because the IPv4 Gateway needs to check that you're the same IP accessing the Gateway.
If static IP isn't possible, just use DoH since it's safer and less hassle.

@gpolydoros
Copy link

gpolydoros commented Dec 9, 2024

Actually, you can have Cloudflare's IPv4 DNS servers with a dynamic IP, but you will need to use the Cloudflare API to update the source IP of your default DNS location every time your WAN IP changes, as their web UI does not currently allow you to update it with the free plan.

You can automate the whole process with very little effort.

For reference, here's the script I'm using on my EdgeRouter to detect WAN IP changes and update CloudFlare accordingly:

#!/usr/bin/env bash

[ -f /tmp/cfgw.dnsloc.ip ] && old_ip=`cat /tmp/cfgw.dnsloc.ip` || old_ip=0.0.0.0/0

new_ip=`ip -f inet addr show pppoe0 | grep inet | awk '{print $2 "/32"}'`

cloudflare-update() {
  curl --request PUT \
  --url https://api.cloudflare.com/client/v4/accounts/ACCOUNT_ID/gateway/locations/LOCATION_ID \
  --header 'Content-Type: application/json' \
  --header 'X-Auth-Email: CLOUDFLARE_EMAIL' \
  --header 'X-Auth-Key: CLOUDFLARE_GLOBAL_API_KEY' \
  --data "{
    \"client_default\": true,
    \"name\": \"LOCATION_NAME\",
    \"networks\": [{ \"network\": \"$new_ip\" }]
  }"
  rm -rf /tmp/cfgw.dnsloc.ip
  echo $new_ip >> /tmp/cfgw.dnsloc.ip
}

[ $new_ip != $old_ip ] && cloudflare-update

CAPS need to be replaced with your own settings/secrets of course.

You can schedule it to run every 1 to 5 minutes with cron; it will only run the update when it's really needed.

You can run it on any Linux box you may have lying around, as long as you have a reliable way to determine your WAN IP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants