There are many ways, a popular choice would be managing your own recursive DNS resolver and then blocking the endpoint it contacts.
PiHole - Non recursive but offers blocking capabilities, can make it recursive with Unbound.
Technitium - Recursive but not nearly as user friendly as PiHole, also lacks the fancy Ui.