Here are some additional details about each step:
This will create a virtual network interface that will be used to connect the LXC containers to the internet.
To do this:
This will allow the LXC containers to access the internet using the Proxmox server's public IP address.
To do this:
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '192.168.1.0/24' -o vmbr0 -j MASQUERADE
This will define the network range that will be used by the LXC containers.
To do this:
This will tell DNSmasq to listen for DHCP and DNS requests on the bridge interface.
To do this:
interface=vmbr0
dhcp-range=192.168.1.100,192.168.1.200,24h
The interface parameter specifies the network interface that DNSmasq will listen on for DHCP requests.
The dhcp-range parameter specifies the range of IP addresses that DNSmasq will assign to DHCP clients. The first parameter is the starting IP address, the second parameter is the ending IP address, and the third parameter is the lease time.
The 24h in the dhcp-range parameter specifies that the lease time is 24 hours. This means that the DHCP client will be assigned the same IP address for 24 hours before it has to renew its lease.
Once you have edited the /etc/dnsmasq.conf file, you need to restart the DNSmasq service.
This will tell DNSmasq to assign IP addresses to the LXC containers when they boot up.
To restart the DNSmasq service, run the following command:
$ sudo systemctl restart dnsmasq
Once you have restarted the DNSmasq service, DNSmasq will start providing DHCP service to the LXC containers.
This will create a new container that will run the Pi-hole software.
To do this:
This will install the Pi-hole software on the container.
Follow the instructions on the Pi-hole website: https://pi-hole.net/ or via https://github.com/pi-hole/pi-hole/#one-step-automated-install to install Pi-hole in the LXC container.
You can Manually download the installer and run:
$ wget -O basic-install.sh https://install.pi-hole.net
$ sudo bash basic-install.sh
or
Install Pi-hole using the following command:
$ curl -sSL https://install.pi-hole.net | bash
After installation, you can access it via it's Web Interface Dashboard.
http://<IP_ADDRESS_OF_YOUR_PI_HOLE>/admin/
or
http://pi.hole/admin/ (when using Pi-hole as your DNS server)
This will tell Pi-hole to use DNSmasq to resolve DNS queries.
To do this:
Note: More information about this here at https://pi-hole.net/
This will tell the DHCP server to give out Pi-hole's IP address as the DNS server to the LXC containers.
To do this:
127.0.0.1
To restart the DHCP server, you need to run the following command:
$ sudo systemctl restart dhcpd
This will restart the DHCP service and update the list of DNS servers that the DHCP server will give out to DHCP clients.
The DHCP server is responsible for assigning IP addresses to DHCP clients. When a DHCP client boots up, it will send a DHCPDISCOVER message to the network. The DHCP server will receive this message and respond with a DHCPOFFER message. The DHCPOFFER message will contain the IP address, subnet mask, gateway, and DNS servers that the DHCP client should use.
If you have changed the list of DNS servers that the DHCP server should use, you need to restart the DHCP server so that the DHCP clients will receive the updated list of DNS servers.
The systemctl command is used to manage system services. The restart option is used to restart a service.
The dhcpd service is the name of the DHCP server service.
Once you have restarted the DHCP server, the DHCP clients will be assigned new IP addresses and will use the updated list of DNS servers.
Once you have completed these steps, all of the LXC containers will be able to access the internet and have their DNS requests resolved by Pi-hole.
In this guide, you have learnt how to configure DNSmasq to provide DHCP service and how to configure Pi-hole to use DNSmasq as its upstream DNS server.
By following these steps, you can easily create a private network for your virtual machines that can access the internet and have their DNS requests resolved by Pi-hole.