@Test
  public void testRegionServerHostname() throws Exception {
    for (NetworkInterface ni : getValidNetworkInterfaces()) {
      Enumeration<InetAddress> addrList = ni.getInetAddresses();
      // iterate through host addresses and use each as hostname
      while (addrList.hasMoreElements()) {
        InetAddress addr = addrList.nextElement();
        if (
          addr.isLoopbackAddress() || addr.isLinkLocalAddress() || addr.isMulticastAddress()
            || !addr.isSiteLocalAddress()
        ) {
          continue;
        }
        String hostName = addr.getHostName();
        LOG.info("Found " + hostName + " on " + ni + ", addr=" + addr);

        TEST_UTIL.getConfiguration().set(DNS.MASTER_HOSTNAME_KEY, hostName);
        TEST_UTIL.getConfiguration().set(DNS.UNSAFE_RS_HOSTNAME_KEY, hostName);
        StartTestingClusterOption option = StartTestingClusterOption.builder()
          .numMasters(NUM_MASTERS).numRegionServers(NUM_RS).numDataNodes(NUM_RS).build();
        TEST_UTIL.startMiniCluster(option);
        try {
          ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
          List<String> servers = ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().rsZNode);
          assertEquals(NUM_RS, servers.size());
          for (String server : servers) {
            assertTrue("From zookeeper: " + server + " hostname: " + hostName,
              server.startsWith(hostName.toLowerCase(Locale.ROOT) + ","));
          }
          zkw.close();
        } finally {
          TEST_UTIL.shutdownMiniCluster();
        }
      }
    }
  }
Tests for the hostname specification by region server
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerHostname.java