What Actually Goes Into a Request: IP Literal, Hostname, and SNI — A Step-by-Step Guide with Hands-On Verification
Table of contents
- Introduction: why you should care what actually goes into a request
- Preliminary setup: tools and environment
- Basic concepts in plain words
- Step 1: parsing the url and determining whether we have a name or an address
- Step 2: watching how a name turns into an address
- Step 3: connecting by name and catching sni
- Step 4: connecting by ip literal and seeing the difference
- Step 5: controlling the name-address pairing via --resolve and --connect-to
- Step 6: catching clienthello in wireshark and finding sni in the packet
- Step 7: seeing what goes into a request through a proxy
- Verifying the result: checklist
- Common mistakes and solutions
- Extra possibilities for advanced users
- Faq: common questions
- Conclusion
Introduction: Why You Should Care What Actually Goes Into a Request
When you type a website address and hit Enter, it feels like a single line flies off into the network — the URL. In reality, several different things happen at once, at different levels. First, the site name is turned into a numeric IP address. Then a TCP connection is opened to that address. Then, inside the connection, the TLS handshake begins, and in its very first message the server name is sent in the clear — that's the SNI field. And only after that, inside the encrypted channel, does the HTTP request go out with its Host header.
This guide is all about the transport level. We won't be digging into application headers like Via and X-Forwarded-For — those have their own dedicated article, and they work quite differently: they're added by intermediate nodes inside HTTP. Here we're talking about what the client sends on its own, before even a single byte of HTTP has left its machine: the difference between connecting via an IP literal and via a hostname, and where the server name ends up in TLS.
What You'll Get Out of It
- You'll understand how an IP literal differs from a hostname and why that affects the connection result.
- You'll see the SNI field in ClientHello with your own eyes via curl, openssl, and Wireshark.
- You'll learn to connect to the right server by address while keeping the correct name — a trick that comes in handy for debugging and configuration.
- You'll figure out exactly what a proxy server sees during a CONNECT tunnel and what stays only between you and the target site.
- You'll get a checklist for troubleshooting errors like "certificate mismatch" and "server is serving the wrong site."
Who This Guide Is For
For anyone setting up proxies and servers, working on automation and scraping, debugging application behavior, or simply wanting to understand what happens "under the hood" of a browser. The level is intermediate: we'll explain the basics, but we assume you're not afraid of the command line.
What You Should Know Beforehand
- How to open a terminal (Windows PowerShell, Terminal on macOS, or any terminal emulator on Linux).
- What a URL is and what it consists of — at least at a basic level.
- That a website lives on a server, and that a server has an address.
How Much Time It Takes
Installing the tools — 10-15 minutes. Going through all seven steps — 45-60 minutes. Total: anywhere from one to one and a half hours if you carefully repeat each command. You can skip Wireshark and come back to it later — that way you'll finish in 40 minutes.
Preliminary Setup: Tools and Environment
We'll need a small set of command-line utilities. The good news: most of them are already on your system.
System Requirements
- Windows 10 or 11, macOS 12 or newer, or any modern Linux (Ubuntu 22.04+, Debian 12+, Fedora).
- Internet access without restrictions on outbound connections to ports 80 and 443.
- Administrator rights — only needed for installing Wireshark and editing the hosts file.
What to Install or Check
- curl. It's built into Windows 10 and 11, also on macOS, and usually installed on Linux. Open your terminal and type
curl --version. You should see a line likecurl 8.x.xand a list of supported protocols. If it says "command not found," runsudo apt install curlon Ubuntu. - openssl. Present by default on macOS and Linux: check with
openssl version. It's not on Windows out of the box — the easiest way is to install Git for Windows: after installation, openssl.exe will be in theC:\Program Files\Git\usr\binfolder. Alternatively, use WSL (Windows Subsystem for Linux). - nslookup or dig. nslookup is everywhere, including Windows. dig is more convenient, it comes in the dnsutils package (Ubuntu:
sudo apt install dnsutils), and it's already installed on macOS. - Wireshark (optional, for Step 6). Download the installer from the project's official website. During installation on Windows, agree to install the Npcap capture driver — without it, the program won't see any traffic.
- Access to any proxy (optional, for Step 7). Any HTTP or SOCKS5 proxy with a login and password will do, for example a mobile proxy from your personal dashboard.
Backups
The only system file we'll be touching is hosts. Before editing, be sure to copy it. On Windows it's at C:\Windows\System32\drivers\etc\hosts, on macOS and Linux — /etc/hosts. Just make a copy named hosts.bak next to it.
Tip: Create a separate folder for this workshop and save the output of each command to a text file there. In a week you'll forget the details, and comparing old and new output can be extremely useful for troubleshooting.
Basic Concepts in Plain Words
Before we start hammering away at the keyboard, let's agree on terminology. There isn't much, but without it things will get messy.
IP Address and IP Literal
IP address — the numeric address of a network node. IPv4 looks like four numbers separated by dots: 93.184.216.34. IPv6 uses hexadecimal groups separated by colons: 2606:2800:220:1:248:1893:25c8:1946. An IP literal is when you write the address directly in the URL instead of a name: https://93.184.216.34/. For IPv6, the address in a URL is wrapped in square brackets: https://[2606:2800:220:1:248:1893:25c8:1946]/. The word "literal" here means "written out exactly as it is."
Hostname
A hostname is a human-readable name like example.com or api.example.com. By itself, a name addresses nothing: the network doesn't understand it. To establish a connection, the name must first be turned into an IP address. That's the job of DNS — the distributed name service. One hostname can point to multiple addresses, and one address can serve hundreds of names. Every complication we'll cover grows out of that asymmetry.
TCP Connection
Once the IP address is known, your system opens a TCP connection to that address and port (443 for HTTPS, 80 for HTTP). At this level, the hostname is already gone — only numbers remain. The server accepting the connection only knows that someone arrived at its address and port. Which of a hundred sites you want, it doesn't know yet.
TLS and ClientHello
TLS is the encryption protocol — the S in HTTPS. The first message a client sends to a server is called ClientHello. It goes out in the clear because the encryption keys haven't been negotiated yet. ClientHello lists supported protocol versions, cipher suites, and extensions. One of those extensions is SNI.
SNI — Server Name Indication
SNI literally means "Server Name Indication." It's a TLS extension in which the client says: "I want to talk to the site example.com." Why is this necessary? Because dozens of sites with different certificates can live on a single IP address. Without SNI, the server doesn't know which certificate to present. Important: the standard only allows a hostname in SNI, not an IP address. That's why when connecting via an IP literal, the SNI field is simply absent. This is the key fact for the entire guide.
The Host Header and the :authority Pseudo-Header
Once the TLS channel is established, the HTTP request travels inside it. In HTTP/1.1, the site name is duplicated in the Host header; in HTTP/2 and HTTP/3, in the :authority pseudo-header. This is already the application level, and from the outside this field is invisible — it's encrypted. But the server compares it with SNI, and if they diverge, it may respond with an error.
Certificate and SAN
In response to ClientHello, the server returns a certificate. It contains a list of names for which it was issued — the Subject Alternative Name (SAN) field. The client checks the name from the URL against this list. If you connected via an IP literal, the client looks for the IP address in the SAN — and such certificates are extremely rare. Hence the typical "certificate doesn't match the name" error.
How This Differs from Via and X-Forwarded-For
The Via and X-Forwarded-For headers are application-level. Your client doesn't send them; proxies and load balancers insert them inside HTTP to tell the destination server who the request passed through. Everything we're covering here — the destination IP address, the hostname in CONNECT, and the SNI in ClientHello — is sent by the client itself, and it happens before and outside of HTTP. Keep that boundary in mind: transport level here, application headers there.
Step 1: Parsing the URL and Determining Whether We Have a Name or an Address
Goal of this stage: learn to tell an IP literal from a hostname in a second and predict whether the client will send SNI.
- Take any URL, for example
https://api.example.com:8443/v1/status?debug=1. - Find the scheme — the part before
://. Here it'shttps. The scheme determines the default port (443) and whether there will be TLS at all. - Find the authority — the part between
://and the next slash:api.example.com:8443. That's the host plus an optional port. - Separate the port. If after the colon there are only digits and there's just one colon — that's the port (8443). Everything else is the host.
- Look at the host. If it consists only of digits and three dots — it's an IPv4 literal. If it's in square brackets — it's an IPv6 literal. In all other cases — it's a hostname.
- Draw your conclusion: for a hostname, the client will perform a DNS query and send SNI. For an IP literal, DNS isn't needed, and SNI won't be sent.
Work through three examples on your own for practice: https://10.0.0.5/admin (IPv4 literal, no SNI), https://[2001:db8::1]:8443/ (IPv6 literal, port 8443, no SNI), http://cdn.example.net/img.png (hostname, but the scheme is http — no TLS, so no SNI either, the name only goes in the Host header in the clear).
Watch out: a common trap is a string like https://192.168.1.10.nip.io/. It looks like an address, but it's a hostname: it contains letters. Such a name will be resolved via DNS and will end up in SNI. Always check whether the host consists only of digits and dots.
Check: for any URL, you can name the scheme, host, port, and host type (literal or name), and also say whether the SNI field will be sent. If you're unsure, go back to point 5.
Possible Issues
The URL has a username and password before the @ sign. For example https://user:pass@host.com/. The host starts after the @. Credentials aren't related to the transport level.
Multiple colons without brackets. That's an invalid URL for IPv6 — the browser won't accept it. Brackets are mandatory.
Step 2: Watching How a Name Turns Into an Address
Goal of this stage: see DNS resolution live and understand that a name and an address are two independent things.
- Open your terminal.
- Type
nslookup example.comand press Enter. - Read the output. The first lines show your DNS server's address (Server and Address). Below is the answer section:
Name: example.comand one or moreAddress:lines with IPv4 and IPv6 addresses. - Write down one of the IPv4 addresses in your notes file. You'll need it in Step 4.
- If you have dig, run
dig +short example.com A— you'll get just the addresses without extra noise. Anddig +short example.com AAAAwill show IPv6 addresses. - Now do the reverse:
nslookup 93.184.216.34(substitute the address from step 4). You'll get either a PTR name that may not match example.com at all, or a message that no record was found.
What does this prove? Forward resolution (name to address) and reverse resolution (address to name) are different databases, and they don't have to match. A server accepting a connection on 93.184.216.34 has no way of knowing from the connection alone which name you typed. The only way to tell it is via SNI and Host.
Tip: large services change their addresses from request to request and depending on region. Don't be surprised if nslookup returns a different set a minute later. That's exactly why in our tests we'll explicitly pin the address.
Local Override: The hosts File
The system checks the hosts file before querying DNS. It's a handy way to test how a site behaves if a name points to a different address.
- Make sure the hosts.bak copy is made (see the setup section).
- Open hosts as administrator: on Windows, launch Notepad via right-click and "Run as administrator," then File — Open, enable showing all files, and select hosts. On macOS and Linux:
sudo nano /etc/hosts. - Add the line
127.0.0.1 test.localat the end, save. - Run
ping test.local. Replies should come from 127.0.0.1. - Remove the added line when you're done with the experiment, or restore hosts.bak.
Check: you got example.com's IP address via nslookup or dig and wrote it down. You understand that hosts can override DNS results locally.
Possible Issues
nslookup gives "DNS request timed out." Check your internet connection and try specifying a public resolver: nslookup example.com 8.8.8.8.
Changes to hosts don't take effect. On Windows, run ipconfig /flushdns. Browsers have their own DNS cache — restart the browser.
Step 3: Connecting by Name and Catching SNI
Goal of this stage: see that when connecting by hostname, the client sends SNI and receives the correct certificate.
Option A: curl with Verbose Output
- In the terminal, run
curl -v https://example.com/ -o /dev/null. On Windows PowerShell, writeNULinstead of/dev/null, and call the command ascurl.exeso that PowerShell's built-in alias doesn't kick in. - Find the line about name resolution in the output: in recent curl versions, it's
* Host example.com:443 was resolved.followed by* IPv4: 93.184.216.34. - Find the line
* Connected to example.com (93.184.216.34) port 443. That's the moment the TCP connection is established. Notice: curl shows both the name and the address — it knows both. - Find the TLS block:
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384and then* Server certificate:withsubjectandsubjectAltNamefields. - The key line:
* subjectAltName: host "example.com" matched cert's "example.com". It means: the name from the URL matched the name in the certificate. Verification passed. - Below you'll see the request itself:
> GET / HTTP/2and> Host: example.com(or> :authority: example.comdepending on the version). That's the application level inside the encrypted channel.
curl doesn't print SNI on a separate line, but a simple rule applies here: curl sends in SNI whatever name is in the URL. Since the URL says example.com, example.com went into SNI. Let's confirm this with openssl.
Option B: openssl s_client
- Run
openssl s_client -connect example.com:443 -servername example.com < /dev/null. On Windows, replace the input redirection by pressing Ctrl+C after the output appears. - The
-connectflag specifies where to open TCP. The-servernameflag specifies what to put in SNI. Right now they match. - In the output, find the
Certificate chainblock — there you'll sees:CN = example.comor a similar name, plus the issueri:. - Find the line
Verify return code: 0 (ok). Zero means the trust chain was verified successfully. If you see code 20 or 21 — openssl doesn't have a system root certificate store; add the-CAfileflag with the path to the root certificates file, or just ignore it for this step, since the name in the certificate is more important.
Now let's run a control experiment: remove SNI but keep the same name for the connection.
- Run
openssl s_client -connect example.com:443 -noservername < /dev/null. - Compare the certificate. Some servers will return the same one — meaning they have a single site on this address or a sensible default site configured. Others will give you a completely different certificate or a handshake error like
alert handshake failure— that's a server that refuses to work without SNI. - Try the same with a large site behind a CDN, for example
openssl s_client -connect www.cloudflare.com:443 -noservername < /dev/null. You'll most likely see a rejection or a placeholder certificate.
Tip: add the -tlsextdebug flag: openssl s_client -connect example.com:443 -servername example.com -tlsextdebug < /dev/null. It prints the list of TLS extensions exchanged by the two sides. The extension named server name is the SNI as seen from the server confirming it received it.
Check: curl showed the name matching the certificate, openssl with -servername returned a certificate for example.com, and with -noservername the behavior changed for at least one of the sites tested.
Possible Issues
curl says "schannel: SEC_E_UNTRUSTED_ROOT." That's the Windows build of curl using the system certificate store, and it's missing a root certificate. Update Windows or use the curl from Git for Windows.
openssl hangs and prints nothing. It's waiting for input. Press Ctrl+C or add the redirection < /dev/null.
Step 4: Connecting by IP Literal and Seeing the Difference
Goal of this stage: confirm that when connecting by address, SNI isn't sent, the certificate doesn't match, and the server may serve the wrong site.
- Take the IP address from Step 2. For example, let's say it's 93.184.216.34.
- Run
curl -v https://93.184.216.34/ -o /dev/null. - Notice: there are no DNS resolution lines at all. curl immediately writes
* Trying 93.184.216.34:443...and* Connected to 93.184.216.34 (93.184.216.34) port 443. No name — both parentheses contain the address. - The TLS handshake will probably complete, but then curl will throw an error:
* SSL: no alternative certificate subject name matches target host name "93.184.216.34"andcurl: (60) SSL certificate problem. That's expected: the SAN field doesn't contain an IP address. - Repeat with certificate verification disabled:
curl -vk https://93.184.216.34/ -o /dev/null. The-kflag forces curl to accept any certificate. We do this only for observation. - Now look at the request:
> Host: 93.184.216.34. The client honestly passed whatever was in the URL into Host — an address. And it sent no SNI at all. - Look at the response. Possible outcomes: a 200 with the default site's content for this address; a 404 or 421; a 400 or 403 with text like "Direct IP access not allowed"; or the TLS handshake being cut before HTTP even starts.
Here's what happened. Your client reached the right server — after all, the address is the same. But the server got neither SNI nor a meaningful Host, which means it couldn't tell which of its hosted sites you wanted. So it either served the first one it had (the default) or refused. Connecting by address delivers packets but doesn't deliver intent.
The Same Experiment in a Browser
- Open a browser and type
https://93.184.216.34/into the address bar. - Most likely you'll see a warning about an insecure connection with a code like NET::ERR_CERT_COMMON_NAME_INVALID. The browser drew the same conclusion as curl: the name in the certificate doesn't match the address.
- Click the padlock icon or the "Not secure" text and open the certificate information. In the "Subject Alternative Name" field, you'll see domain names, but not the IP address.
- Don't click "Proceed" on real sites — it's not needed for the experiment, and it's best not to make a habit of it.
Watch out: the -k flag in curl and the "Proceed" button in a browser disable certificate verification. Use them only in tests against servers you control. When working with real services, especially when passwords or tokens are involved, never disable verification — you'll lose the guarantee that you're talking to who you meant to talk to.
Check: without -k, curl fails with error 60 and a mention of the IP address; with -k, the request shows Host: address; the server responds differently than when accessed by name, or with an error.
Possible Issues
The server responds by IP exactly the same as by name. That means there's a single site on this address and it's configured as default. Not an error. Repeat on a major CDN's address to see the difference.
curl exited with error 35 (SSL connect error). The server cut off the handshake because SNI was missing. That's also part of the answer: without a name, it doesn't even start the conversation.
Step 5: Controlling the Name-Address Pairing via --resolve and --connect-to
Goal of this stage: learn to connect to a specific address while keeping the correct SNI and Host. This is the number one working technique for debugging servers, load balancers, and CDNs.
The --resolve Flag: Same URL, Different Address
- Run
curl -v --resolve example.com:443:93.184.216.34 https://example.com/ -o /dev/null. - Flag format:
name:port:address. curl will substitute this address instead of the DNS response, but only for that name-port pair. - In the output, you'll see
* Added example.com:443:93.184.216.34 to DNS cacheand then* Connected to example.com (93.184.216.34) port 443. - Certificate verification will pass because the name in the URL remained example.com, SNI went out as example.com, and Host went out as example.com. Only the address the TCP connection was opened to changed.
- Now substitute a deliberately wrong address — say, the address of some other well-known site obtained via nslookup. Run the same
--resolvewith that address. You'll see either a certificate error (the other server presented its own certificate, not matching example.com) or a 421 or 404 response: the server received the SNI example.com but doesn't host that site.
That's exactly the scenario used when migrating a site to a new server: DNS still points to the old address, but you're already testing the new one without touching DNS or hosts.
The --connect-to Flag: Connect to a Completely Different Host
- Run
curl -v --connect-to example.com:443:backend.example.net:443 https://example.com/ -o /dev/null(substitute the real target server name if you have one; for practice, you can use example.com again). - Format:
original_name:port:where_to_connect:port. Unlike--resolve, you can specify not only an address but also a different name, and it will be resolved via DNS. - SNI and Host still come from the URL, that is, they remain example.com.
Separating the SNI Name from the TCP Name in openssl
- Run
openssl s_client -connect 93.184.216.34:443 -servername example.com < /dev/null. - Here we've explicitly separated two things: TCP goes to the address, and the name goes into SNI. The server will receive the SNI and return the correct certificate.
- Now change
-servernameto a nonexistent name:-servername nosuchsite.example. Compare the certificate. This shows you which site the server serves by default for an unfamiliar SNI.
Tip: when debugging a load balancer or multiple servers behind one name, write a small loop that goes through a list of addresses and runs --resolve for each. That way, in a minute, you can see which node is serving an outdated certificate or wrong configuration.
Tip: if you need to substitute an address not for a single curl call but for an entire application or browser, use the hosts file from Step 2. But don't forget to remove the entries later — a forgotten line in hosts can confuse you for weeks.
Check: the command with --resolve and the correct address passes without a certificate error and returns the same response as a normal connection by name. The command with the wrong address yields a certificate error or a 421 status.
Possible Issues
curl ignores --resolve. Check that the port in the flag matches the port in the URL. For https it's 443, for http it's 80. The flag example.com:80:... won't work for an https request.
I want to substitute the address for all ports. Use --resolve example.com:*:93.184.216.34 — the asterisk means any port (supported in modern curl versions).
Step 6: Catching ClientHello in Wireshark and Finding SNI in the Packet
Goal of this stage: see SNI not through utility logs but in the actual bytes that went over the wire. After this step, you'll have no doubts that the name is transmitted in the clear.
- Launch Wireshark. If the system asks about permissions — agree; capturing traffic requires them.
- On the start screen, select the network interface through which you access the internet. Usually it's Wi-Fi or Ethernet; next to the active interface, there's a small activity graph. Double-click it.
- Capture begins — packet lines will start scrolling in the main window. Immediately paste the expression
tls.handshake.type == 1into the filter field at the top (it has the placeholder "Apply a display filter") and press Enter. This will leave only ClientHello packets. - In the terminal, run
curl -s https://example.com/ -o /dev/null. A second later, one or more lines with the descriptionClient Hellowill appear in the Info column in Wireshark. - Click the line. In the middle pane, expand the tree: Transport Layer Security — TLSv1.3 Record Layer: Handshake Protocol: Client Hello — Handshake Protocol: Client Hello.
- Scroll down to the extensions list and expand Extension: server_name. Inside will be Server Name Indication extension, and in it the field Server Name: example.com.
- Click the Server Name field. In the bottom pane with the hex dump, the corresponding bytes will be highlighted, and in the text column on the right you'll read
example.comin plain letters. That's the cleartext transmission of the name. - Now repeat the capture with an IP connection:
curl -sk https://93.184.216.34/ -o /dev/null. Find the new ClientHello and verify that the server_name extension isn't there at all. - Stop the capture with the red button on the toolbar.
A Handy Trick: Display SNI in Its Own Column
- Right-click the Server Name field in the middle pane.
- Select Apply as Column.
- A new column will appear in the packet list, showing the server name for each ClientHello at a glance. That way you can see in a second which sites any application on your machine is contacting.
What's important to understand from this step. Everything that comes after ClientHello and ServerHello is encrypted: the request, the response, and the headers, including Host, Via, and X-Forwarded-For. But SNI sits outside. Any node along the path — a router, an ISP, a corporate gateway — sees the destination IP address and the name from SNI, but doesn't see the URL, headers, or content. This isn't a vulnerability but a design property: the server needs the name before it can decrypt anything.
Check: the capture contains a ClientHello with the Server Name field equal to the name from the URL; when connecting via an IP literal, the field is absent. You can see the bytes of the name in the hex dump.
Possible Issues
No packets appear. The wrong interface is selected. Stop the capture, go back to the interface list, and pick the one with activity.
The filter is highlighted in red. A typo in the filter. Check: two equals signs, the word tls in lowercase.
curl traffic isn't visible because it goes through a proxy. Then ClientHello will be inside the CONNECT tunnel; it's still visible in Wireshark, but the destination address will be the proxy's address. Move on to Step 7 — that's what it's about.
Step 7: Seeing What Goes Into a Request Through a Proxy
Goal of this stage: understand which part of the information — address, name, SNI — the proxy server receives, and which stays only between the client and the target site.
This step requires credentials for any HTTP proxy: address, port, login, password. If you have a mobile proxy from your personal dashboard, that's perfect. If you don't have a proxy, read this step as theory and come back to it later.
HTTPS Through an HTTP Proxy: The CONNECT Tunnel
- Run
curl -v -x http://LOGIN:PASSWORD@PROXY_ADDRESS:PORT https://example.com/ -o /dev/null. Substitute your own data. - The first thing you'll notice: the lines about DNS resolution of example.com are absent. Instead, curl resolves the proxy's name and connects to it:
* Connected to PROXY_ADDRESS (x.x.x.x) port PORT. - Next comes the line
* CONNECT tunnel: HTTP/1.1 negotiatedand the request to the proxy itself:> CONNECT example.com:443 HTTP/1.1,> Host: example.com:443,> Proxy-Authorization: Basic .... - Notice: the name example.com goes into CONNECT, not the address. This means the DNS query will be performed by the proxy, not your machine. That's why you had no resolution lines.
- The proxy responds with
< HTTP/1.1 200 Connection established, and curl writes* CONNECT phase completed. - Only now does TLS begin:
* SSL connection using TLSv1.3...and certificate verificationsubjectAltName: host "example.com" matched. This handshake travels through the proxy, with the target server. The SNI in it is example.com, and the Host inside is example.com.
Summary by layers. The proxy received: your IP address, the name example.com and port 443 from the CONNECT line, and your proxy credentials. The proxy also technically sees the ClientHello bytes passing through it — and therefore the SNI, since it's in the clear; but it's the same name that was already in CONNECT, nothing new. The proxy does not receive: the URL path, request headers, cookies, or response body — all of that is encrypted between you and example.com. The proxy can't add Via and X-Forwarded-For headers in this scheme because it has no access inside the tunnel.
The Same Request but via IP Literal Through a Proxy
- Run
curl -vk -x http://LOGIN:PASSWORD@PROXY_ADDRESS:PORT https://93.184.216.34/ -o /dev/null. - The CONNECT line will be
CONNECT 93.184.216.34:443. The proxy won't resolve anything — the address is already there. - Inside the tunnel, a ClientHello without SNI will go out, along with a request with
Host: 93.184.216.34. The target server will react the same way as in Step 4: default site, error, or refusal.
SOCKS5: Who Resolves the Name
- If you have a SOCKS5 proxy, run
curl -v -x socks5://LOGIN:PASSWORD@ADDRESS:PORT https://example.com/ -o /dev/null. Thesocks5scheme means the name is resolved locally, on your machine, and the address is passed to the proxy. There will be DNS lines in the output. - Now change the scheme to
socks5h:curl -v -x socks5h://LOGIN:PASSWORD@ADDRESS:PORT https://example.com/ -o /dev/null. The letter h means the name is passed to the proxy and resolved on its side. There will be no local DNS lines. - In both cases, the SNI inside the tunnel remains example.com — the proxy scheme doesn't affect it.
The practical takeaway for working with mobile and other proxies: if you want the target site to see an address matching the proxy's region, and for DNS responses to also come from the proxy's region, use HTTP CONNECT or socks5h. The socks5 scheme without h will resolve the name with your local resolver, and the site may get the address of the CDN node nearest to you rather than to the proxy. This shows up in latency and sometimes in how geo-dependent services behave.
Watch out: in the command line with -x, your proxy login and password end up in the terminal history. After your experiments, clear the history or use the https_proxy environment variable, or better yet, a .curlrc file with the proxy parameter that only you can access.
Tip: to confirm that the request really went through the proxy, call any service that shows your IP through it, for example curl -x ... https://api.ipify.org. You should see the proxy's address, not your own. It's a quick way to verify the settings took effect.
Check: curl's output shows CONNECT example.com:443 with the name; no local DNS was performed; after Connection established, a TLS handshake with example.com's certificate took place. For the IP literal, an address went into CONNECT and there was no SNI.
Possible Issues
curl: (56) Received HTTP code 407 from proxy after CONNECT. Wrong login or password. If the password contains special characters, URL-encode them or pass them separately via the -U LOGIN:PASSWORD flag apart from the address.
curl: (56) CONNECT tunnel failed, response 403. The proxy is blocking connections to that host or port. Check your plan's terms and the list of allowed ports.
Verifying the Result: Checklist
Go through the list. Each item is a separate skill that should be locked in.
- For any URL, you can determine the host, port, and host type (IPv4 literal, IPv6 literal, hostname).
- You can get a name's addresses via nslookup or dig and understand that reverse resolution may not match.
- In
curl -voutput, you can find the connection lines, TLS version, certificate, and subjectAltName check. - You know that openssl s_client with
-servernamesends SNI, and with-noservernamedoesn't, and you can see the difference in the certificate. - When connecting via an IP literal, you get error 60 in curl and understand the reason.
- Using
--resolve, you connect to a specified address with correct SNI and Host without certificate errors. - In Wireshark, you find ClientHello, the Server Name field, and can see its absence for an IP literal.
- Through a proxy, you see the CONNECT line with the name and understand what exactly the proxy gets and what it doesn't.
How to Test Yourself
- Pick any website you use.
- Find its addresses via dig.
- Connect by name and by one of the addresses, compare the responses.
- Connect with
--resolveto each address in the list and verify they all serve the same certificate. - Note which address responded faster —
curl -w "%{time_total}"will show the time.
If all five points were completed without looking back at the guide — mission accomplished.
Common Mistakes and Solutions
1. "Certificate Doesn't Match the Name" Error When Accessing by IP
Cause: the certificate's SAN field lists domain names, and the client is looking for an IP address. Solution: connect by name. If DNS isn't set up yet, use --resolve or hosts. Don't disable verification with the -k flag in production scenarios.
2. The Server Serves the Wrong Site or a Default Page
Cause: SNI is absent or doesn't match any configured name, and the web server picks the default virtual host. Solution: check that the client is sending the name. In nginx, check which server block is marked default_server, and if needed, configure a stub with an explicit error for it so such cases are easy to spot.
3. 421 Misdirected Request Status
Cause: SNI and Host (or :authority) don't match. Often it's a consequence of reusing an HTTP/2 connection for a different name or manually overriding the Host header while keeping the same URL. Solution: use --resolve instead of manually setting the Host header — then SNI and Host will be automatically consistent.
4. curl Doesn't Show Name Resolution, and It Seems Like DNS Isn't Working
Cause: the request goes through an HTTP proxy or socks5h, and the name is resolved on the proxy's side. Solution: that's normal behavior. If you need local resolution, use the socks5 scheme without h, or remove the proxy settings from the http_proxy and https_proxy environment variables.
5. Changes to hosts Don't Affect the Browser
Cause: the browser caches DNS and keeps open connections; also, some browsers use DNS-over-HTTPS and bypass the system resolver. Solution: restart the browser, flush the DNS cache with ipconfig /flushdns on Windows, check the "Secure DNS" setting in the browser, and temporarily use the system resolver.
6. openssl s_client Shows Verify return code 20 or 21
Cause: openssl couldn't find the root certificates. Solution: specify the path to the root certificates file via -CAfile. On Linux, it's usually /etc/ssl/certs/ca-certificates.crt. On Windows, use the openssl from Git for Windows, which has its own root set.
7. PowerShell Prints a Strange Response to the curl Command
Cause: in PowerShell, the word curl is an alias for the built-in Invoke-WebRequest command, which has different parameters. Solution: call curl.exe with the extension, or work in the regular cmd command prompt.
8. Wireshark Shows ClientHello but No server_name Extension Inside, Even Though the URL Has a Name
Cause: you either caught a ClientHello from another application, or the client accessed by IP. Solution: add the destination address to the filter: tls.handshake.type == 1 && ip.dst == 93.184.216.34 to filter out other packets.
Extra Possibilities for Advanced Users
Logging SNI on the Server Side
If you administer nginx, add the $ssl_server_name variable next to $host in the log format. The first shows what came in SNI, the second what came in Host. Comparing them, you'll quickly find clients connecting by IP literal or with mismatched fields. For connections without SNI, the variable will be empty.
A Separate Response for Connections Without SNI
In nginx, you can declare a server block with listen 443 ssl default_server and the ssl_reject_handshake on directive. Then any connection without SNI or with an unfamiliar name will be rejected at the handshake stage, and the server won't hand out a single extra certificate. This disciplines clients and protects against accidentally showing the wrong site.
Certificates With an IP Address in SAN
Technically, you can issue a certificate with an IP address in SAN. Public certificate authorities do this rarely and with restrictions, but for internal services with their own certificate authority, it's a viable option. Then a connection by IP literal will pass verification. However, SNI still won't be sent — the standard doesn't allow it — so exactly one service must live on that address.
IPv6 Literals
Everything described also works for IPv6, with one syntax adjustment: in a URL, the address is wrapped in square brackets, but in --resolve it isn't: --resolve example.com:443:2606:2800:220:1:248:1893:25c8:1946. curl understands that everything after the second colon is an address.
HTTP/2 and Connection Reuse
In HTTP/2, a single TLS connection can serve multiple names if they're all listed in one certificate. The client may send a second request with a different :authority on the same connection. The server compares :authority with the certificate's SAN and with SNI; on mismatch, it responds with 421, and the client opens a new connection. The --http1.1 flag in curl lets you disable this behavior for debugging.
Encrypted ClientHello
An extension called Encrypted Client Hello is being developed and deployed that allows encrypting part of ClientHello, including SNI, provided the server supports it and publishes keys in DNS. In 2026, support exists in a number of browsers and CDNs, but far from everywhere, and for command-line tools it must be enabled separately. For the purposes of this guide, it's enough to know: without such an extension, SNI is in the clear, and that's how the vast majority of connections work today.
Measuring Time by Stage
The -w flag in curl lets you output the time of each stage: curl -o /dev/null -s -w "dns %{time_namelookup} tcp %{time_connect} tls %{time_appconnect} total %{time_total}" https://example.com/. That way you'll clearly see how long name resolution took, how long TCP, how long TLS. When connecting by IP literal, the first value will be close to zero.
FAQ: Common Questions
Can I Pass an IP Address in SNI?
No. The standard explicitly forbids IP literals in the server_name field. Clients that follow the standard simply don't include the SNI extension in ClientHello when connecting by address.
If SNI Is in the Clear, Doesn't That Mean HTTPS Doesn't Protect the Site Name?
The server name from SNI and the destination IP address are visible to intermediate nodes. Everything else — the path, request parameters, headers, content — is encrypted. That's how the protocol is designed: the server needs to know the name before it can select a certificate.
How Does Host Differ From SNI If They Contain the Same Name?
SNI is part of TLS, goes out in the clear in the first message, and is needed for certificate selection. Host is part of HTTP, goes inside the encrypted channel, and is needed by the web server for site selection and routing. They usually match, but they're two different fields at two different levels.
Why Doesn't curl With --resolve Complain About the Certificate, but Does With an IP in the URL?
Because with --resolve, the URL still contains a name. curl verifies the certificate against the name from the URL, not against the address it physically connected to.
Who Performs the DNS Query When I'm Working Through a Proxy?
It depends on the type. HTTP CONNECT and socks5h pass the name to the proxy, and it performs the query. socks5 without h, and any schemes where you substitute the address yourself, leave resolution on your side.
Does the Proxy See Which Pages I Open on a Site?
With HTTPS through a CONNECT tunnel — no. The proxy sees the name and port from CONNECT, the address, and the cleartext ClientHello bytes, including SNI. The path, headers, and content are encrypted between you and the site.
Why Does One Site Open Fine When Connecting by IP and Another Doesn't?
On the first address, there's a single site, and the server serves it as the default. On the second address, there are many sites or a strict configuration, and without SNI the server either serves a stub or drops the handshake.
How Do I Make the Browser Send a Different SNI Than What's in the Address Bar?
Through standard means — you can't: the browser always sends the name from the URL in SNI. For tests, use curl with --resolve or --connect-to, or openssl with separate -connect and -servername.
What Should I Do If a Site Stopped Opening After My Experiments?
Check the hosts file and remove your lines, clear the DNS cache of the system and the browser, remove the proxy environment variables, close and reopen the browser. In the vast majority of cases, a forgotten hosts entry is to blame.
Do I Need Wireshark, or Is curl Enough?
For understanding — curl and openssl are enough. Wireshark is needed to see the actual bytes and check the behavior of applications you don't have detailed logs for, such as mobile clients or desktop programs.
Conclusion
You've walked the entire path of a request at the transport level. You parsed URLs and learned to tell an IP literal from a name. You saw how a name turns into an address via DNS and why the reverse path isn't guaranteed. Through curl and openssl, you verified that when connecting by name, SNI goes into ClientHello and the server returns the correct certificate, while connecting by address means no SNI, a certificate mismatch, and the server serving a default site or refusing. You mastered --resolve and --connect-to — working tools for testing servers without touching DNS. In Wireshark, you found the bytes of the name in the clear. And finally, you saw how it all looks through a proxy: what goes into CONNECT, who resolves the name, and what stays encrypted.
Let's sum up the main takeaway in one line: the address delivers packets to the server, and the name explains to the server what you want. They travel by different paths — the address in the IP packet header, the name in SNI and Host — and both are needed for the connection to work as intended.
What to Do Next
- Read the separate article about the Via and X-Forwarded-For headers — now you definitely understand where the transport level ends and the application level begins, and you won't confuse them.
- If you administer a web server, enable
$ssl_server_namelogging and see how many clients arrive without SNI. - If you're writing automation, check which proxy scheme your library uses and where DNS resolution happens — this directly affects which address and region the target service will see.
Where to Grow
The next topics that logically follow this guide: a full breakdown of the TLS handshake and its version 1.3, how HTTP/2 and HTTP/3 work with multiplexing and pseudo-headers, how DNS works with A, AAAA, CNAME, and HTTPS records, and configuring virtual hosts in nginx with certificate selection by SNI. Each of them builds on what you just did with your own hands — and now it'll be noticeably easier.