DNS is like a gateway. When the DNS is added internet goes through the Dns. There are special DNS services outthere which we can use. When the traffic goes through them,they only allow visiting normal websites and not porn etc.
For example i have added adguard dns to my mobile.it blocks all the advertising services and apps cant show me ads