Skip to content

JMeter java.net.UnknownHostException

Fix JMeter UnknownHostException: DNS resolution failure, wrong server names, proxy issues, and Docker/Kubernetes container DNS resolution troubleshooting.

Difficulty
beginner
Guide type
troubleshooting
Estimated read time
5 min read
Last verified version
Verified JMeter 5.6

In View Results Tree, jmeter.log, or JTL execution results, all or specific requests fail immediately with:

Response code: Non HTTP response code: java.net.UnknownHostException
Response message: Non HTTP response message: staging-api.internal.corp

The sample fails within 0–5 milliseconds without transmitting any network packets to the destination server.

UnknownHostException means the Java Virtual Machine running JMeter could not resolve the specified hostname or domain into an IP address using the operating system’s DNS resolvers or JMeter’s DNS Cache Manager.

CauseWhy it happens
Protocol / Path in Server Name fieldEntering https://api.example.com or api.example.com/v1 in the “Server Name or IP” field instead of just api.example.com
Unresolved property variableUsing \${__P(host)} without supplying -Jhost=api.example.com on the command line
Private / Internal DNS inaccessibleRunning load tests in CI/CD (GitHub Actions, GitLab CI) or Docker where private enterprise DNS is not reachable
Trailing whitespace in server nameCopy-pasting hostname with invisible leading/trailing whitespace into HTTP Request Defaults
Missing DNS Cache ManagerHigh-concurrency tests overwhelming local OS DNS cache with repeated lookups
Docker / Kubernetes CoreDNSContainerized JMeter workers unable to resolve cluster services (service.namespace.svc.cluster.local)

1. Clean the “Server Name or IP” Field

Section titled “1. Clean the “Server Name or IP” Field”

In HTTP Request Defaults and individual HTTP Request samplers:

  • Protocol: https (do not put https:// in Server Name)
  • Server Name or IP: api.example.com (no http://, no trailing /, no /path)
  • Port Number: 443 (or leave blank if standard 80/443)
  • Path: /v1/users
<!-- Correct XML structure in JMX -->
<stringProp name="HTTPSampler.domain">api.example.com</stringProp>
<stringProp name="HTTPSampler.port">443</stringProp>
<stringProp name="HTTPSampler.protocol">https</stringProp>
<stringProp name="HTTPSampler.path">/v1/users</stringProp>

2. Verify Property Defaults in Command Line Runs

Section titled “2. Verify Property Defaults in Command Line Runs”

If using JMeter properties for dynamic environment switching:

Terminal window
# If using ${__P(hostname,)} in the JMX, always provide -Jhostname
jmeter -n -t test.jmx -Jhostname=staging.example.com -l results.jtl -j jmeter.log

In your JMX, always supply a fallback default:

${__P(hostname,api.example.com)}

3. Add and Configure the DNS Cache Manager

Section titled “3. Add and Configure the DNS Cache Manager”

To simulate real browser DNS caching behavior or use custom DNS servers:

  1. Right-click Thread Group -> Add -> Config Element -> DNS Cache Manager.
  2. Select Use System DNS or Use Custom DNS.
  3. If testing internal staging environments, add static host mappings directly in the table:
HostHostnameIP Address
api.staging.internalapi.staging.internal10.0.4.15

4. Test DNS Resolution from Injector Terminal

Section titled “4. Test DNS Resolution from Injector Terminal”

Verify that the host machine running JMeter can resolve the target name:

Terminal window
# Linux / macOS
nslookup api.example.com
dig api.example.com
# Windows PowerShell
Resolve-DnsName api.example.com
Test-NetConnection -ComputerName api.example.com -Port 443

If running JMeter inside Docker or Kubernetes pods:

# Kubernetes Pod spec DNS config
spec:
dnsPolicy: "ClusterFirst"
hostAliases:
- ip: "10.240.0.1"
hostnames:
- "auth.staging.internal"
- "api.staging.internal"
ResourceUse when
ConnectExceptionDNS resolves but connection is refused or timed out
Non HTTP response codeOverview of all non-HTTP sample errors
Docker & KubernetesContainerized JMeter networking configuration
CLI Command BuilderGenerate CLI commands with -Jhostname properties

Why does it work in a browser on my laptop but fail in JMeter?

Section titled “Why does it work in a browser on my laptop but fail in JMeter?”

Your browser may use DoH (DNS-over-HTTPS) or an active VPN profile that Java’s network stack does not inherit, or the browser proxy configuration is not replicated inside JMeter.

Can DNS resolution failures cause high response times in JMeter?

Section titled “Can DNS resolution failures cause high response times in JMeter?”

Yes. If DNS queries timeout before failing over, sample elapsed time includes the multi-second DNS lookup delay. Adding a DNS Cache Manager eliminates repeated DNS queries per thread iteration.

How do I point JMeter to a specific IP without changing DNS?

Section titled “How do I point JMeter to a specific IP without changing DNS?”

Add a DNS Cache Manager to your Test Plan, choose “Use Custom DNS”, and add a static entry mapping the hostname to the target IP address.

On this page