Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
router:dhcp-dns [2024/08/26 09:40] – [DHCP server] willy | router:dhcp-dns [2025/02/06 08:03] (current) – removed willy | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== DNS, DHCP and routing for the internal network ===== | ||
- | |||
- | Since your home network is connected **only** to your home server (right?), in order to be able to navigate and use the home network you must configure some services on your home server. | ||
- | |||
- | In detail, you will need: | ||
- | * one DNS server, so that devices in the home network can resolve names to addresses (and filter ads) | ||
- | * one DHCP server, so provide devices in the home network with automatic configuration | ||
- | * one default gateway and router: to allow devices in the home network to access stuff on the internet | ||
- | |||
- | At first i have been using DNSmasq, which is a seemingly easy approach to both DNS and DHCP for the home network. After a lengthly and annoying debugging session with Android devices i found out that DNS has evolved a lot and DNSMasq is today a bit outdated. | ||
- | |||
- | I decided then to go straight to the Gentoo standard DHCP server and Unbound DNS resolver/ | ||
- | |||
- | For future reference, the older DNSMasq information has been moved to a separate page. | ||
- | |||
- | To create a router, you will be using the Linux built-in great nftables tools that today has replaced the older iptables. | ||
- | |||
- | |||
- | === Unbound, your very own DNS resolver === | ||
- | |||
- | [[https:// | ||
- | |||
- | [[https:// | ||
- | |||
- | It's very simple to setup on Gentoo (see [[https:// | ||
- | |||
- | So, first of all enable DNSCrypt for Unbound by creating the file **/ | ||
- | <file - unbound> | ||
- | net-dns/ | ||
- | </ | ||
- | |||
- | then emerge Unbound: | ||
- | <code bash> | ||
- | emerge unbound | ||
- | </ | ||
- | |||
- | I am using the following **/ | ||
- | <file - unbound.conf> | ||
- | server: | ||
- | verbosity: 1 | ||
- | num-threads: | ||
- | interface: 10.0.0.1 | ||
- | interface: 127.0.0.1 | ||
- | port: 53 | ||
- | so-reuseport: | ||
- | cache-min-ttl: | ||
- | cache-max-ttl: | ||
- | do-ip4: yes | ||
- | do-ip6: yes | ||
- | do-udp: yes | ||
- | do-tcp: yes | ||
- | use-systemd: | ||
- | do-daemonize: | ||
- | # For security reasons, only clients on the home interface can use the DNS service | ||
- | | ||
- | access-control: | ||
- | use-syslog: yes | ||
- | hide-identity: | ||
- | hide-version: | ||
- | harden-short-bufsize: | ||
- | harden-large-queries: | ||
- | harden-glue: | ||
- | harden-dnssec-stripped: | ||
- | harden-below-nxdomain: | ||
- | harden-referral-path: | ||
- | harden-algo-downgrade: | ||
- | qname-minimisation: | ||
- | qname-minimisation-strict: | ||
- | aggressive-nsec: | ||
- | use-caps-for-id: | ||
- | prefetch: yes | ||
- | rrset-roundrobin: | ||
- | minimal-responses: | ||
- | # This will enable DoT (upstream) | ||
- | tls-cert-bundle: | ||
- | # This will add Ad blocking | ||
- | include: / | ||
- | # Add a local resolve for the home server | ||
- | local-zone: " | ||
- | local-data: " | ||
- | |||
- | remote-control: | ||
- | control-enable: | ||
- | |||
- | forward-zone: | ||
- | name: " | ||
- | # Use Google DNS as upstream DNS (put here your preferred ones if not Google) | ||
- | forward-tls-upstream: | ||
- | forward-addr: | ||
- | forward-addr: | ||
- | </ | ||
- | |||
- | To configure specific _internal_ hosts, you need to define a **local-zone** and a matching **local-data** rows as defined above. You might want to move these information to specific files to include (like the adservers.conf) for easier maintenance if you have lots of internal names. | ||
- | |||
- | At this point, read the [[router: | ||
- | |||
- | You need to populate your **/ | ||
- | <file - resolv.conf> | ||
- | # My own local DNS resolver (Unbound) | ||
- | nameserver 127.0.0.1 | ||
- | </ | ||
- | |||
- | Don't forget to autostart Unbound service: | ||
- | <code bash> | ||
- | rc-update add unbound default | ||
- | / | ||
- | </ | ||
- | |||
- | |||
- | |||
- | ==== DHCP server ==== | ||
- | |||
- | Using the [[https:// | ||
- | |||
- | You should disable the ISC DHCP client as it is deprecated (and you already have the Gentoo' | ||
- | <file - dhcp> | ||
- | net-misc/ | ||
- | </ | ||
- | |||
- | then just emerge it: | ||
- | <code bash> | ||
- | emerge net-misc/ | ||
- | </ | ||
- | |||
- | Edit the DHCP configuration file **/ | ||
- | <file - dhcpd.conf> | ||
- | authoritative; | ||
- | subnet 192.168.0.0 netmask 255.255.255.0 { | ||
- | # disable DHCP on ISP#1 upstream network | ||
- | } | ||
- | subnet 192.168.1.0 netmask 255.255.255.0 { | ||
- | # disable DHCP on ISP#2 upstream network | ||
- | } | ||
- | subnet 10.0.0.0 netmask 255.255.255.0 { | ||
- | range 10.0.0.100 10.0.0.250; | ||
- | option domain-name-servers 10.0.0.1; | ||
- | option domain-name " | ||
- | option routers 10.0.0.1; | ||
- | } | ||
- | host fixed-ip-pc { | ||
- | hardware ethernet 12: | ||
- | fixed-address 10.0.0.95; | ||
- | } | ||
- | </ | ||
- | |||
- | Here i assign a pool od dynamic IP addresses (from 100 to 254) on the 10.0.0.0 subnet. Addresses under 100 can be used for static assignments. For example, i use static IPs for all my OpenWRT Access Points and wired security cameras, and dynamic for all other devices. I have also defined my two ISP's subnets to explicitly disable DHCP assignments on them, which is not needed and might be an attack vector. | ||
- | |||
- | This config will also ensure that all devices will use the home server both as DNS server and gateway. | ||
- | |||
- | This will **not work** for devices that use hard-coded DNS servers (like Fire Sticks and Google Chromecasts...) but there is a workaround for those too, and i will show you on [[router: | ||
- | |||
- | This will **not work** with some Android devices either, and it's a massive PITA, because Android is moving to DoH and this will totally bypass your internal Unbound resolver, and there is _no way_ to fix it. This means also issues with Ad Blocking, go figure why Google is pushing this hard. | ||
- | |||
- | Well, this is almost all. Start //dhcp// service and make it start on boot: | ||
- | <code bash> | ||
- | rc-update add dhcp default | ||
- | / | ||
- | </ | ||
- | |||
- | Now you can connect your devices to the home network and they will get an IP address and a full network configuration to go with it. | ||
- | |||