netsh – other contexts (1/3)
netsh (Network Shell) is the built-in Windows command-line shell whose helper DLLs provide contexts. This part covers winhttp (system proxy), winsock (socket catalog and LSPs), http (HTTP.sys URL reservations and SSL bindings), lan (wired 802.1X), dhcpclient (tracing) and dnsclient (DNS servers per interface).
206.1 Why is it used?
- Fix proxy problems of system services (Windows Update) that ignore the browser proxy.
- Repair socket errors caused by a broken LSP with winsock reset.
- Let a non-admin app listen on a URL and bind an SSL certificate to IP:port for HTTP.sys apps.
- Manage wired 802.1X profiles, DHCP client traces and per-interface DNS servers from scripts.
- set/add/delete need an admin prompt; Microsoft recommends PowerShell for new automation.
206.2 netsh basics
netsh /?netsh ?$ netsh /?Usage: C:\Windows\System32\netsh.exe [-a AliasFile] [-c Context] [-r RemoteMachine] [-u [DomainName\]UserName] [-p Password | *] [Command | -f ScriptFile]The following commands are available:$ netsh ?dhcpclient - Changes to the `netsh dhcpclient' context.dnsclient - Changes to the `netsh dnsclient' context.http - Changes to the `netsh http' context.lan - Changes to the `netsh lan' context.winhttp - Changes to the `netsh winhttp' context.winsock - Changes to the `netsh winsock' context.ztdns - Changes to the `netsh ztdns' context.netsh interactive shell (netsh>)netsh -c interface start in this contextnetsh -r 192.168.1.10 remote PC (needs Remote Registry)netsh -u CONTOSO\admin -p * run as this account, secure promptnetsh -f netcfg.txt run a script and exitnetsh advfirewall show currentprofile one command, back to CMDnetsh> ?Commands in this context:.. - Goes up one context level.abort - Discards changes made while in offline mode.alias - Adds an alias.bye - Exits the program.commit - Commits changes made while in offline mode.offline - Sets the current mode to offline.online - Sets the current mode to online.popd - Pops a context from the stack.pushd - Pushes current context on stack.dump - Displays a configuration script.exec - Runs a script file.unalias - Deletes an alias.- Only help commands were run on the office PC; settings examples come from Microsoft Learn.
- offline queues changes, commit applies them, abort discards them; dump writes a config script.
- -r needs the Remote Registry service, otherwise "Network Path Not Found".
206.3 winhttp: the system proxy
- Step 1
1.Office PC (192.168.1.20): netsh winhttp set proxy proxy.example.com:8080
- Step 2
2.Windows Update uses WinHTTP, not the browser's proxy
- Step 3
3.Update request goes to proxy.example.com:8080
- Step 4
4.Proxy forwards it to the internet update server
- Step 5
5.Intranet server 192.168.1.50 is in the bypass list: goes direct
netsh winhttp show proxynetsh winhttp import proxy source=ienetsh winhttp reset proxynetsh winhttp set proxy proxy-server="http=p1;https=p2:88" bypass-list="<local>;*.foo.com"netsh winhttp set advproxy setting-scope=machine settings="{ \"Proxy\":\"proxy.example.com:8080\", \"ProxyBypass\":\"*.example.com\", \"AutoconfigUrl\":\"http://config.example.com/proxy.pac\", \"AutoDetect\":true}"$ netsh winhttp ?Commands in this context:dump - Displays a configuration script.import - Imports WinHTTP proxy settings.reset - Resets WinHTTP settings.set - Configures WinHTTP settings.show - Displays currents settings.- import proxy source=ie copies the IE/WinINET setting; reset proxy sets it back to DIRECT.
- set advproxy takes proxy, bypass list, PAC URL and AutoDetect together as JSON (or settings-file).
- show proxy was not run because it would expose the office proxy; tracing commands are obsolete (use netsh trace).
Linux equivalent (same idea, not netsh): http_proxy / https_proxy / no_proxy environment variables.
export http_proxy=http://192.168.226.10:3128curl -s http://updates.example.com/export https_proxy=$http_proxycurl -sv https://updates.example.com/export no_proxy=192.168.226.10curl -s http://192.168.226.10:8080/$ export http_proxy=http://192.168.226.10:3128; curl -s http://updates.example.com/n206 proxy stub got: GET http://updates.example.com/ HTTP/1.1$ curl -sv https://updates.example.com/* Uses proxy env variable https_proxy == 'http://192.168.226.10:3128'* Connected to 192.168.226.10 (192.168.226.10) port 3128> CONNECT updates.example.com:443 HTTP/1.1< HTTP/1.1 403 Forbidden* CONNECT tunnel failed, response 403curl: (56) CONNECT tunnel failed, response 403$ export http_proxy=http://192.168.226.10:3128 no_proxy=192.168.226.10; curl -s http://192.168.226.10:8080/hello from n206-web (direct, no proxy)(proxy) $ cat /tmp/proxy.logGET http://updates.example.com/ HTTP/1.1CONNECT updates.example.com:443 HTTP/1.1- The stub's reply shows the full URL, so the HTTP request went through the proxy.
- HTTPS uses CONNECT; the stub blocks it with 403.
- no_proxy works like the bypass list: the request goes directly to the web server.
206.4 winsock: catalog and LSPs
netsh winsock show catalog providers + LSPsnetsh winsock audit trail LSP install/uninstall historynetsh winsock remove provider 1001 remove one LSP by catalog IDnetsh winsock reset catalog to clean state (then reboot)netsh winsock set autotuning on|off send autotuning$ netsh winsock ?Commands in this context:audit - Displays a list of Winsock LSPs that have been installed and removed.dump - Displays a configuration script.remove - Removes a Winsock LSP from the system.reset - Resets the Winsock Catalog to a clean state.set - Sets Winsock options.show - Displays information.- Winsock is the layer through which apps open sockets; antivirus or VPN software can add LSPs (Layered Service Providers).
- reset removes custom LSPs (not namespace providers): use it as a last option, as admin, then reboot.
- show catalog and audit trail were not run because they list the office's security software.
206.5 http: HTTP.sys
- Step 1
1.Browser (192.168.1.30) sends HTTPS to port 443
- Step 2
2.HTTP.sys (kernel listener) looks up the sslcert binding for 0.0.0.0:443
- Step 3
3.Certificate with that certhash is used for TLS
- Step 4
4.URL /api/ matches the urlacl reservation https://+:443/api/
- Step 5
5.Request is handed to MyApp, which listens without admin rights
netsh http add urlacl url=http://example.com:8080/ user=DOMAIN\UserName listen=yesnetsh http show urlacl url=http://+:80/MyAppnetsh http delete urlacl url=http://+:80/MyAppnetsh http add sslcert ipport=1.1.1.1:443 certhash=0102030405060708090A appid={00112233-4455-6677-8899-AABBCCDDEEFF}netsh http add sslcert hostnameport=www.contoso.com:443 certhash=0102030405060708090A appid={00112233-4455-6677-8899-AABBCCDDEEFF} certstorename=MYnetsh http show sslcert ipport=192.168.1.100:443netsh http update sslpropertyex ipport=192.168.1.100:443 propertyid=1 maxsettingsperframe=100 maxsettingsperminute=1000netsh http add timeout timeouttype=idleconnectiontimeout value=120netsh http add iplisten ipaddress=192.168.1.10netsh http flush logbuffer$ netsh http show ?show cacheparam - Shows the cache parameters of HTTP service .show cachestate - Lists cached URI resources and their associated properties.show iplisten - Displays all the IP addresses in the IP listen list.show servicestate - Shows a snapshot of the HTTP service.show setting - Shows the setting values of the service.show sslcert - Displays SSL certificate bindings.show timeout - Shows the timeout values of the service.show urlacl - Displays URL namespace reservations.$ netsh http add sslcert ?Usage: add sslcert [hostnameport=<name:port> | ipport=<ipaddr:port> | ccs=<port>] | json=[filepath] [appid=<GUID>] [certhash=<string>] [certstorename=<string>] certhash: The SHA hash of the certificate. This hash is 20 bytes long and specified as a hex string. appid: GUID to identify the owning application. reject: When enabled, any new matching connection is immediately dropped. disablehttp2: When set, HTTP2 is disabled for new matching connections immediately. disablequic: When set, QUIC is disabled for new matching connections immediately. disablelegacytls: When set, legacy versions of TLS are disabled.| Table | Purpose | Key parameters |
|---|---|---|
| urlacl | Let a non-admin user/group register a URL namespace | url, user or sddl, listen, delegate |
| sslcert | Bind a certificate to IP:port, hostname:port or CCS | ipport/hostnameport/ccs, certhash (20-byte SHA), appid, certstorename |
| sslcert flags | Harden per binding | clientcertnegotiation, reject, disablehttp2, disablequic, disablelegacytls, disabletls13 |
| timeout / iplisten / cacheparam | Service tuning | idleconnectiontimeout, headerwaittimeout, ipaddress, maxcacheresponsesize |
show sslcert was not run on the office PC because it shows hashes of office certificates.
206.6 lan and dhcpclient
- Step 1
1.Switch port starts unauthorized
- Step 2
2.PC (supplicant) sends EAP identity to the switch (authenticator)
- Step 3
3.Switch forwards it to the RADIUS server; access granted, port authorized
- Step 4
4.PC gets its IP and DNS servers from DHCP
- Step 5
5.dnsclient context shows and changes this interface's DNS list
netsh lan show profilesnetsh lan add profile filename=P1.xml interface=Ethnetsh lan set profileparameter interface="Ethernet" authMode=machineOnlynetsh lan set blockperiod value=0-60netsh lan reconnect interface="Ethernet"netsh dhcpclient trace enablenetsh dhcpclient trace dump > C:\NetshTrace\dhcp_trace.txt$ netsh lan ?Commands in this context:add - Adds a configuration entry to a table.delete - Deletes a configuration entry from a table.dump - Displays a configuration script.export - Saves LAN profiles to XML files.reconnect - Reconnects on an interface.set - Configures settings on interfaces.show - Displays information.$ netsh dhcpclient ?list - Lists all the commands available.help - Displays help.? - Displays help.trace - Enable or disable tracing for DHCP client, Dump the last 100 traces.- lan is the wired version of netsh wlan: profiles, export, reconnect.
- authMode = machineOrUser | machineOnly | userOnly | guest; ssoMode = preLogon | postLogon | none.
- blockperiod pauses auto-connect for 0-60 minutes after a failure.
- dhcpclient trace dump saves the last 100 DHCP client traces.
206.7 dnsclient: DNS servers per interface
netsh dnsclient show statenetsh dnsclient add dnsserver name="Ethernet" address=8.8.8.8 index=1netsh dnsclient delete dnsserver name="Ethernet" address=allnetsh dnsclient set dnsserver name=Ethernet source=static address=192.168.10.1 register=primary validate=yesnetsh dnsclient set dnsserver name="Ethernet" source=dhcp$ netsh dnsclient show ?show encryption - Shows an encrypted DNS server template.show global - Shows globally configured DNS settings.show state - Shows the dns state.- index sets the order of preference; validate checks the server (default yes).
- register = none | primary | both controls Dynamic DNS registration.
- source=dhcp returns to DHCP; address=none clears the list.
Linux equivalent: /etc/resolv.conf (resolvectl on systemd).
cat /etc/resolv.confdig +short n206-proxydig n206-proxy | grep -E 'SERVER|status'$ cat /etc/resolv.conf# Generated by Docker Engine.nameserver 127.0.0.11options ndots:0# ExtServers: [1.1.1.1]$ dig +short n206-proxy192.168.226.10$ dig n206-proxy | grep -E 'SERVER|status';; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30947;; SERVER: 127.0.0.11#53(127.0.0.11) (UDP)206.8 Common mistakes
- Thinking the browser proxy applies to all of Windows: WinHTTP is separate; Windows Update may go DIRECT and get blocked by the firewall.
- Running winsock reset first: it removes LSPs and you may need to reinstall VPN/security software.
- Running an HTTP.sys app as admin just to listen: add a urlacl instead.
- Using netsh winhttp tracing: obsolete, use netsh trace.
206.9 Interview tips
- Browser works but Windows Update fails with a proxy error: netsh winhttp show proxy, then import proxy source=ie.
- winsock reset: when ping works but every app gets socket errors; check show catalog, reset as admin, reboot.
- urlacl = URL reservation for non-admin listeners; sslcert = certificate binding on IP:port.
- 802.1X: supplicant -> authenticator (switch) -> RADIUS.