Skip to content
RU

Hostname/IP Does Not Match Certificate's Altnames (ERR_TLS_CERT_ALTNAME_INVALID)

What it means: The certificate is trusted, but it is not issued for the host name or IP your code connected to.

  1. Read the host and altnames in the message
  2. Connect by a name the certificate lists
  3. Set servername when connecting by IP
  4. Otherwise reissue the certificate with that name

Test your URL now

Runs a full TLS check: handshake, protocol versions, certificate chain, trust and expiry.

Check your site's SSL →

What ERR_TLS_CERT_ALTNAME_INVALID means

Node.js raises ERR_TLS_CERT_ALTNAME_INVALID from tls.checkServerIdentity(), after the chain has already been verified. The message format is fixed in the Node.js source (lib/tls.js, lib/internal/errors.js):

  • Hostname/IP does not match certificate's altnames: Host: api.example.com. is not in the cert's altnames: DNS:www.example.com, DNS:example.com
  • Hostname/IP does not match certificate's altnames: IP: 203.0.113.10 is not in the cert's list: — you connected by IP and the certificate has no matching IP-address entry (an empty list means none at all).
  • Host: api.example.com. is not cert's CN: ... — the certificate has no DNS names in subjectAltName, so Node fell back to the Common Name, and that did not match either.
  • Cert does not contain a DNS name — there is nothing to compare against.

The dot after the host name in the message is part of Node's format, not a typo in your URL. The error object also carries reason, host and cert properties, so you can log exactly which names the server presented.

Why the name does not match

You connect toCertificate coversResult
https://203.0.113.10/DNS:api.example.comFails: an IP needs an IP-address SAN
https://api (a Docker or Kubernetes service name)DNS:api.example.comFails: short names are different names
https://example.com/DNS:*.example.comFails: a wildcard does not cover the bare domain
https://a.b.example.com/DNS:*.example.comFails: a wildcard covers exactly one label
https://api.example.com/ via the wrong IPAnother site's certificateFails: DNS or SNI sent you to a different virtual host

Node's matcher follows RFC 6125 strictly. It compares label by label, allows one * only in the left-most label, rejects patterns with two labels or fewer (no *.com), and does not expand a wildcard inside a punycode (xn--) label. The Common Name is consulted only when the certificate has no DNS names at all, which is rare for public certificates today.

Node checks the name in servername if you set it, otherwise host (lib/internal/tls/wrap.js). That is why connecting to an IP address while the certificate is issued for a name always fails unless you pass the name separately.

Diagnose it

node -e "
const tls = require('tls');
const s = tls.connect({host: 'api.example.com', port: 443, servername: 'api.example.com'}, () => {
  console.log(s.getPeerCertificate().subjectaltname); s.end();
});
s.on('error', e => console.log(e.code, e.reason));"

The same check from the shell, with the same SNI:

openssl s_client -connect api.example.com:443 -servername api.example.com </dev/null 2>/dev/null \
  | openssl x509 -noout -ext subjectAltName

If the names printed are for a different site, the request reached the wrong server: compare dig +short api.example.com with the address your code uses, and check whether a proxy or load balancer default certificate is answering.

How to fix it

  1. Use a host name the certificate lists. Replace IPs and internal aliases in configuration with the public name, or add an internal DNS record for that name.
  2. Must connect to a specific IP? Keep the name for SNI and the identity check by passing it as servername:
    https.get({host: '203.0.113.10', servername: 'api.example.com',
               headers: {Host: 'api.example.com'}, path: '/health'}, res => {
      console.log(res.statusCode);
    });
  3. Service-to-service inside a cluster: issue the internal certificate with the names clients actually use (for example the service DNS name) in subjectAltName, from your internal CA.
  4. Bare domain or deeper subdomain: add example.com or a.b.example.com explicitly next to *.example.com when you reissue.
  5. Do not override checkServerIdentity with a function that returns undefined, and do not set rejectUnauthorized: false. Both accept a certificate for any other domain signed by any trusted CA.

How to confirm the fix

node -e "require('https').get('https://api.example.com/', r => console.log(r.statusCode)).on('error', e => console.log(e.code, e.reason))"
# 200
openssl s_client -connect api.example.com:443 -servername api.example.com -verify_hostname api.example.com </dev/null 2>/dev/null | grep 'Verify return code'
# Verify return code: 0 (ok)

The SSL/TLS checker lists the names on the certificate your server presents, so you can see whether the host you call is covered before you change code.

Related errors

CertificateExpiry, issuer, domains (SAN)
ChainIntermediate and root CA validation
TLS ProtocolTLS version and cipher suite
VulnerabilitiesHeartbleed, POODLE, weak ciphers

Why teams trust us

TLS 1.3
supported
Full
CA chain check
3,158
checks in 30 days
30/14/7
days-to-expiry alerts

How it works

1

Enter domain

2

TLS chain verified

3

Expiry date & vulnerabilities

What Does the SSL Check Cover?

SSL/TLS is the encryption protocol that protects data between the browser and server. Our tool analyzes the certificate, chain of trust, TLS version, and knownvulnerabilities.

Certificate Details

Issuer, validity period, signature algorithm, covered domains (SAN), and validation type (DV/OV/EV).

Chain of Trust

Full chain verification: from leaf certificate through intermediates to root CA.

TLS Analysis

Protocol version (TLS 1.2/1.3), cipher suites, Perfect Forward Secrecy (PFS) support.

Expiry Alerts

Set up a monitor — get Telegram and email alerts 30/14/7 days before expiration.

DV vs OV vs EV Certificates

DV (Domain Validation)
  • Confirms domain ownership only
  • Issued in minutes automatically
  • Free via Let's Encrypt
  • Suitable for most websites
  • Most common certificate type
OV / EV
  • Organization (OV) or Extended Validation (EV)
  • Issued in 1-5 business days
  • Costs $50 to $500/year
  • For finance, e-commerce, government sites
  • Increases user trust

Who uses this

DevOps

SSL certificate monitoring

Security

TLS config audit

SEO

HTTPS as ranking factor

E-commerce

customer trust

Common Mistakes

Expired certificateBrowsers block sites with expired SSL. Set up auto-renewal or monitoring.
Incomplete certificate chainWithout intermediate CA, some browsers and bots cannot verify the certificate.
Mixed content on HTTPS siteHTTP resources on an HTTPS page — the browser lock icon disappears, reducing trust.
Using TLS 1.0/1.1Legacy TLS versions have known vulnerabilities. Use TLS 1.2+ or 1.3.
Domain mismatch in certificateThe certificate must cover all site domains, including www and subdomains.

Best Practices

Set up auto-renewalLet's Encrypt + certbot with cron — certificate renews automatically every 60-90 days.
Enable HSTSStrict-Transport-Security header forces browsers to always use HTTPS.
Use TLS 1.3TLS 1.3 is faster (1-RTT handshake) and safer — legacy ciphers removed.
Monitor expiration datesCreate a monitor on Enterno.io — get notified well before expiration.
Verify chain after renewalAfter certificate renewal, confirm that intermediate certificates are installed.

Get more with a free account

SSL certificate monitoring, check history and alerts 30 days before expiry.

Sign up free

Learn more

Sources

Frequently Asked Questions

Why does Node.js fail when I connect by IP address?

The certificate lists host names, not your IP, and Node checks the host you connected to. Pass the real name as servername, or use a certificate with an IP-address SAN.

Does *.example.com cover example.com in Node.js?

No. A wildcard matches exactly one label, so it covers api.example.com but neither example.com nor a.b.example.com. List those names separately.

Is it safe to override checkServerIdentity?

Not with a function that always succeeds: then any trusted certificate for any domain is accepted. Override it only to add stricter checks, such as pinning, and call tls.checkServerIdentity first.

Why is there a dot after the host name in the error?

It is part of the message format in Node.js source: Host: name. is not in the cert's altnames. It does not mean your URL has a trailing dot.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.