You cannot test a CNAME URL on your local machine without having a DNS server installed. To be able to test that like IP addresses on “hosts” file, you need to get its current assigned IP address by just pinging it.
1. Ping and get the IP
ping cname.domain.comCode language: Bash (bash)
You’ll see the IP address there.
2. Then you can add it to the “/etc/hosts” file on your computer.
xxx.xxx.xx.x www.testdomain.comCode language: Nginx (nginx)
This is useful for testing load balancers or any other services which provide CNAME to point.