Answers to this question are difficult to google because a lot of documentation out there reads as though "example.com" is really just a placeholder (as it should be) for an actual privately owned domain.
Now locally on your own network, you can set up a certificate authority and your own DNS service for the domain, and then do whatever you want within the confines of your local network. But you won't be able to reach the real example.com at the same time, since you'll be configured to route example.com through your internal imitation of the external network for at least that domain.
I used to do this for "hacme.corp" (which is not currently a valid domain on the Internet) for teaching penetration test courses.