@VisibleForTesting
    static void initAddrUseFqdn(List<InetAddress> addrs) {
        useFqdn = true;
        analyzePriorityCidrs();
        String fqdn = null;

        if (PRIORITY_CIDRS.isEmpty()) {
            // Get FQDN from local host by default.
            try {
                InetAddress localHost = InetAddress.getLocalHost();
                fqdn = localHost.getCanonicalHostName();
                String ip = localHost.getHostAddress();
                LOG.info("Get FQDN from local host by default, FQDN: {}, ip: {}, v6: {}", fqdn, ip,
                        localHost instanceof Inet6Address);
            } catch (UnknownHostException e) {
                LOG.error("failed to get FQDN from local host, will exit", e);
                System.exit(-1);
            }
            if (fqdn == null) {
                LOG.error("priority_networks is not set and we cannot get FQDN from local host");
                System.exit(-1);
            }
            // Try to resolve addr from FQDN
            InetAddress uncheckedInetAddress = null;
            try {
                uncheckedInetAddress = InetAddress.getByName(fqdn);
            } catch (UnknownHostException e) {
                LOG.error("failed to parse FQDN: {}, message: {}", fqdn, e.getMessage(), e);
                System.exit(-1);
            }
            if (null == uncheckedInetAddress) {
                LOG.error("failed to parse FQDN: {}", fqdn);
                System.exit(-1);
            }
            // Check whether the InetAddress obtained via FQDN is bound to some network interface
            boolean hasInetAddr = false;
            for (InetAddress addr : addrs) {
                LOG.info("Try to match addr in fqdn mode, ip: {}, FQDN: {}",
                        addr.getHostAddress(), addr.getCanonicalHostName());
                if (addr.getCanonicalHostName()
                        .equals(uncheckedInetAddress.getCanonicalHostName())) {
                    hasInetAddr = true;
                    break;
                }
            }
            if (hasInetAddr) {
                localAddr = uncheckedInetAddress;
                LOG.info("Using FQDN from local host by default, FQDN: {}, ip: {}, v6: {}",
                        localAddr.getCanonicalHostName(),
                        localAddr.getHostAddress(),
                        localAddr instanceof Inet6Address);
            } else {
                LOG.error("Cannot find a network interface matching FQDN: {}", fqdn);
                System.exit(-1);
            }
        } else {
            LOG.info("using priority_networks in fqdn mode to decide whether ipv6 or ipv4 is preferred");
            for (InetAddress addr : addrs) {
                String hostAddr = addr.getHostAddress();
                String canonicalHostName = addr.getCanonicalHostName();
                LOG.info("Try to match addr in fqdn mode, ip: {}, FQDN: {}", hostAddr, canonicalHostName);
                if (isInPriorNetwork(hostAddr)) {
                    localAddr = addr;
                    fqdn = canonicalHostName;
                    LOG.info("Using FQDN from matched addr, FQDN: {}, ip: {}, v6: {}",
                            fqdn, hostAddr, addr instanceof Inet6Address);
                    break;
                }
                LOG.info("skip addr {} not belonged to priority networks in FQDN mode", addr);
            }
            if (fqdn == null) {
                LOG.error("priority_networks has been set and we cannot find matched addr, will exit");
                System.exit(-1);
            }
        }

        // double-check the reverse resolve
        String canonicalHostName = localAddr.getCanonicalHostName();
        if (!canonicalHostName.equals(fqdn)) {
            LOG.error("The FQDN of the parsed address [{}] is not the same as " + 
                    "the FQDN obtained from the host [{}]", canonicalHostName, fqdn);
            System.exit(-1);
        }
    }
@Test(expected = IllegalAccessException.class)
    public void testGetStartWithFQDNThrowUnknownHostException() {
        String oldVal = Config.priority_networks;
        Config.priority_networks = "";
        testInitAddrUseFqdnCommonMock();
        List<InetAddress> hosts = NetUtils.getHosts();
        new MockUp<InetAddress>() {
            @Mock
            public InetAddress getLocalHost() throws UnknownHostException {
                throw new UnknownHostException();
            }
        };
        FrontendOptions.initAddrUseFqdn(hosts);
        Config.priority_networks = oldVal;
    }