Mongosh command rejects host names with an underscore which are accepted by mongo command

Agreed. I would generally stick to using alphanumerics and hyphens however underscores look to be valid characters for DNS CNAMES. They are accepted by Microsoft’s DNS Manager for CNAMES and I’d say they are probably in use in the wild. We have quite a few clients tools in use and mongodb shell is the first I have come across which fails to connect if the hostname contains an underscore.