Tag: howto

  • It passed every test, in the wrong place

    It passed every test, in the wrong place

    10 min read

    On the afternoon of 11 October 2026 I ran a script against my OPNsense router’s API from Windows PowerShell 5.1, the PowerShell that comes with Windows. It stopped before it wrote a single line of its own log. The script’s first call to the router comes after that line, so, as far as I can tell, nothing reached the router.

    That was version 2.0. Version 2.4 finished the job at 15:06, 37 minutes after I saved version 2.0. Each version had passed its tests in Claude’s sandbox first. Those tests ran in the wrong place: against a mock router instead of the real one, and under PowerShell 7 instead of Windows PowerShell 5.1. The mock passed all three versions that then failed on the router. Whether the PowerShell difference played a part in failure 1 I do not know. It played none in failure 2, and it broke my test harness later. Three runs failed, each for a different reason. None of them left a change switched on.

    I did this with Claude. I set the rules the script had to follow, created the API key and deleted it afterwards, and ran every version on my own PC against my own router. Claude wrote the script, the mock router it was tested against, and each fix. It tested them under PowerShell 7, the only PowerShell its sandbox had.

    The script, a mock router and a test harness are at the end of this page, under the MIT licence. The script makes a router refuse three common ways around its DNS blocklist: DNS over HTTPS, DNS over TLS or QUIC, and plain DNS sent to another server. This page records the runs and what I would change, and a panel near the end walks through running the script on your own router.

    New to the command line? How to read the boxes

    PS> means: type this in PowerShell on Windows (Start menu → type powershell → Enter). Do not type the PS> itself.

    Each line that starts with PS> is one command. Click that PS> to copy just that line, paste it, press Enter, and wait for it to finish before the next. A box with a Copy button at the top holds one command (or one file), so copy it whole. A dashed box shows what you should see back, or code to read; you do not type it.

    What the script does

    The script applies a DNS fix on an OPNsense 26.7 router. My router’s blocklist only filters devices that ask the router; phones, browsers and some devices ask other servers. The fix involves four objects:

    • an alias, DoH_IPs, that downloads a public list of DNS-over-HTTPS server addresses kept by the Hagezi project (1,434 of them that day);
    • Rule A, which rejects LAN traffic to those addresses on port 443;
    • Rule B, which rejects LAN traffic to any address on port 853, used by DNS over TLS and DNS over QUIC;
    • a NAT redirect that sends any port 53 query aimed past the router back to the router.

    On my router the alias and the redirect rule already existed, and the redirect was switched off. The script cleans the alias, creates the two rules if they are missing, and switches the redirect on. It does not create the redirect rule. The rules cover IPv4 and the LAN interface only; the limits are listed in the step-by-step panel near the end.

    I could have clicked these four objects into place. I scripted it because I wanted the change in a form I could check without changing anything, run again, and switch off in one command.

    The rules it runs under

    1. Three modes. Check reads and reports. Apply makes the change. Rollback switches the two rules and the redirect off and deletes nothing. A command without -Mode runs Check.
    2. Version guard. The script first asks the router what it runs, and stops unless the answer is the 26.7 series.
    3. Backup next. Before it reads or changes any configuration, every run downloads the router’s full configuration into a new file. It refuses to overwrite an existing one.
    4. Test each change. The alias first, then both rules, then the redirect. In version 2.3 a failed test undid everything the run had changed. From version 2.4, if only the redirect fails, only the redirect is switched off, and the rules that passed stay.
    5. No secret in the script. The API key lives in a separate file.

    Thirty-seven minutes

    Started Version Mode What happened Left on the router
    after 14:29 2.0 not logged Stopped before its first log line Nothing
    14:43 2.1 Check Read-only report, complete Nothing
    14:51 2.2 Apply Stopped on its own guard before any save Nothing
    14:56 2.3 Apply Rules worked; redirect test failed; undone Two rules, disabled
    15:04 2.4 Apply Finished at 15:06, every test passed The fix

    Version 2.0 wrote no log, so its time is the minute I saved the file. The other times are from the script’s own logs.

    The order of operations limited the damage. The script checks the version, backs up, and reads before it writes. Failure 1 stopped before any call to the router. Failure 2 stopped before any save, on a guard written for a different problem. Failure 3 happened after changes were made, and that version’s undo switched them off.

    Failure 1: a cause I got wrong

    Version 2.0 took its working folder from a parameter default:

    [string]$WorkDir = $PSScriptRoot

    $PSScriptRoot is the folder the script sits in. The script uses it to build the path for its logs folder, which it creates before it reads the key or calls the router.

    Version 2.1 changed three things. It worked out the folder in the script body, it stopped if that folder did not exist, and it wrapped two counts so that an empty DNS answer counts as zero. Only the folder changes come before the first log line. On the day, Claude and I concluded that Windows PowerShell 5.1 had left $PSScriptRoot empty, and the first drafts of this post said so.

    The test kit for this post checked that, and the conclusion was wrong. On my PC, Windows PowerShell 5.1, started with -File as I start the script, put the folder into $PSScriptRoot in a parameter default. So did PowerShell 7.4.6. I did not test every way of starting a script, so I cannot rule out that some leave it empty. I did not record how I started version 2.0 that afternoon, or the error it showed, so I do not know what stopped it. What the evidence supports is narrower: version 2.0 stopped before its first log line, and so, as far as the evidence shows, before any call to the router. A comment in the published script says the folder can be empty under Windows PowerShell 5.1. That comment repeats my first conclusion; I left the tested file as it was.

    The change in version 2.1 stays. It costs nothing and it works whichever way the script is started:

    if ([string]::IsNullOrWhiteSpace($WorkDir)) {
        if ($MyInvocation.MyCommand.Path) { $WorkDir = Split-Path -Parent $MyInvocation.MyCommand.Path }
        else { $WorkDir = (Get-Location).Path }
    }

    Version 2.1’s Check run at 14:43 completed.

    Failure 2: a mock without the router’s quirks

    To check the alias’s type, version 2.2 called the router’s alias/get_item endpoint. The run log at 14:51:

    14:51:46  Problem: Existing alias DoH_IPs is type '', not urltable. Fix or delete it in the GUI, then rerun.
    14:51:46  Nothing to undo.
    ...
    14:51:47  STOP: Apply did not complete; changes from this run were undone.

    The alias’s type was not empty. The router’s reply contains entries whose name is an empty string ("":). JSON allows that. PowerShell cannot make an object property with an empty name. Microsoft’s documentation for ConvertFrom-Json says so (the PowerShell 7.4 reference), and offers the -AsHashtable switch for such replies. Windows PowerShell 5.1 does not have that switch. Invoke-RestMethod raised no error. It returned the reply as plain text, and the script read the type from that text as nothing.

    This was not a difference between PowerShell versions. The test kit gives the script a reply with an empty key. Under PowerShell 7.4.6, and on my PC under Windows PowerShell 5.1, Invoke-RestMethod returned it as text, with no error. Version 2.2 passed against the mock because the mock’s reply had no empty keys. The router’s reply had them.

    The guard that stopped the run was written for a different problem: an existing alias of the wrong type. It stopped this run because an empty type is not urltable. Without it, the run would have saved the new URL and then, on undo, written an empty string into the alias.

    The Check run at 14:43 had not caught this. Check read the alias through alias/search_item. Only Apply called get_item.

    Version 2.3 makes two changes. The router’s search_item and search_rule endpoints already return the type and contents, and their replies parsed, so the script reads only through them. And every API call now goes through one helper that refuses a reply it could not parse:

    $r = Invoke-RestMethod @p
    if ($r -is [string]) {
        $t = $r.TrimStart()
        if ($t.StartsWith('{') -or $t.StartsWith('[')) { throw "Router reply to $Path could not be read as JSON by this PowerShell; stopping." }
    }

    Failure 3: a redirect tested too soon

    Version 2.3 got further. It cleaned the alias, added both rules and tested them. Then it switched the NAT redirect on and tested it five seconds later:

    14:57:16  Rules A and B verified: DoH and DoT refused, normal HTTPS works.
    14:57:17  NAT rule enabled and applied. Verifying...
    14:57:22  Problem: 8.8.8.8 still returns real ad addresses; the redirect is not taking effect.
    14:57:22  Undoing changes made in this run...

    The test sends two queries to 8.8.8.8: one for example.com and one for an ad domain. The firewall log showed one of the two redirected. The ad domain came back with real addresses, so it was the one not redirected. Thirteen seconds before switching the redirect on, the script’s opening check had sent that same name to 8.8.8.8, to show the bypass was open.

    I have two explanations, and I tested neither. The firewall keeps a state entry for each connection it has seen, and applies a redirect only to new connections. If the second query for the ad domain left my PC from the same source port as the first, it matched the old entry and went out to Google. Or something on my PC answered the repeated question from memory, and the query never left the PC.

    This router’s UDP state timeouts, read from Firewall → Diagnostics → Statistics, are 60 seconds for udp.first and udp.multiple and 30 seconds for udp.single. Version 2.4 waits 70 seconds before testing, and the test passed:

    15:05:08  NAT rule enabled and applied. Waiting 70 s for older DNS states to expire before testing...
    15:06:18  NAT redirect verified: queries to 8.8.8.8 are answered by your router.

    The wait outlasts the firewall’s state entries. Whether it also outlasts an answer remembered on the PC depends on how long that answer is kept, which I did not measure. So the result does not tell the two explanations apart. A test with a name not queried earlier, with the firewall’s state table open, would.

    The undo in version 2.3 switched the redirect off, disabled the two new rules and restored the alias’s contents. It did not delete the rules, and it left the alias’s refresh interval at one day. The backup taken after the undo is 4,788 bytes larger than the one before the run. Version 2.4 began by finding the two rules:

    15:04:56  Rule A: present, enabled=0, sort_order=400000.0000100
    15:04:56  Rule B: present, enabled=0, sort_order=400000.0000200

    So “undone” meant “nothing left switched on”, not “the router as it was”. Version 2.4 switched the two existing rules on instead of adding new copies, because it looks rules up by description before creating them.

    What the mock missed, and a second round of tests

    Claude had run each version against its mock before I ran it against the router. By the record of that session, each version ran once normally and once with a forced failure, to check the undo. Versions 2.0 to 2.3 passed against the mock. Against the router, three of the four failed. The mock never ran under Windows PowerShell 5.1, and its replies did not carry the router’s empty keys.

    The script at the end of this page is version 2.5.1, not 2.4. Before publishing, I had Claude review the script again, and version 2.5 fixes what that review found: messages that could describe the router’s state wrongly, stops that were not written to the log, an undo that did not restore the alias’s enabled flag, and runs that could start on a router without the redirect rule or the LAN allow-all rule. It also refuses a router address that does not start with https://, except one on the PC itself, which the test kit uses. Version 2.4 is the one that ran on my router. Version 2.5.1, which differs from 2.5 in its header comments only, has run only against the mock.

    The second round of tests used a new mock, built to misbehave the way a router can, including a reply with an empty key. A harness ran a copy of the script against it once for each of 30 cases. Under PowerShell 7.4.6, all 30 passed.

    The first run under Windows PowerShell 5.1 on my PC failed two cases. The script’s logs showed it had done the right thing; the harness had not. When a PowerShell function returns a list with one item, the caller gets the item itself. PowerShell 7 lets you count and index that item as if it were a list. Windows PowerShell 5.1 does not, for this kind of object. The harness had run only under PowerShell 7. With that fixed, all 30 cases passed under Windows PowerShell 5.1 too, on the published version of the script.

    To check the harness itself, Claude broke the script ten ways, for example by removing the undo, the JSON check or the HTTPS check. Each break made at least one case fail. That check ran under PowerShell 7.4.6 against version 2.5, with an earlier version of the harness.

    What I would take to the next script

    1. Test on the PowerShell that will run the script, and run the tests there too. The harness passed under PowerShell 7 and failed its first run under 5.1.
    2. Build the mock’s replies from real ones. A reply saved from the router’s get_item would have caught failure 2 before the router saw the script.
    3. Make the read-only mode make every read the write mode will make. Here, Check and Apply read the alias through different endpoints.
    4. Treat a string from Invoke-RestMethod as a failure when you expected an object. It does not always raise an error.
    5. After switching on a redirect, wait longer than the firewall’s state timeout, and test with a name you have not queried before.
    6. If the undo disables instead of deleting, make the next run look for what the last one left.
    7. Break the script on purpose to check that the tests can fail.
    8. Keep the API key out of the script and delete it when the work is done. I used the root user’s key. A user with only the privileges the script needs would be better; I have not tried that.
    Run it on your own router, step by step

    Before you start. You need:

    • a Windows PC on the same network as the router. You type in two places: PowerShell on the PC, and the router’s web page in a browser;
    • OPNsense 26.7. The script stops on any other series, because its API paths were read from that series’ own pages;
    • the DNS blocklist switched on, under Services → Unbound DNS → Blocklist (the OPNsense documentation names that page), and your devices asking the router for DNS;
    • a Destination NAT rule that sends DNS queries (port 53) aimed anywhere but the router back to the router, already made, with the description “Redirect non-local DNS to Local”. The script switches it on. It does not build it. The script does not create this rule, this panel does not cover making one, and without it Apply stops. A community how-to on the OPNsense forum shows one way;
    • a LAN rule called “Default allow LAN to any rule”, which OPNsense creates by default. The script checks that its two new rules sit above it.

    Version 2.5.1, the script in this panel, has run only against the mock router in the test kit. Version 2.4 is the one that ran on my router.

    Allow about 20 minutes; the change itself takes about two. The first change to the router is the API key in step 3. The Check run in step 5 changes nothing on it. Apply in step 6 changes it. Step 8 switches the fix off and shows how to restore the whole configuration. Every run saves a backup of the router’s configuration on the PC before it reads the configuration.

    Read the limits next. If one describes your network, the script does not suit it, so do not go on.

    Limits

    • IPv4 only. Rules A and B are created for IPv4, and every test uses an IPv4 address. If your LAN has IPv6, DoH and DoT over IPv6 are neither blocked nor tested. (Interfaces → LAN shows an IPv6 Configuration Type; None means no IPv6.)
    • LAN interface only. Other interfaces and VLANs are not covered.
    • Every LAN host. A Pi-hole or AdGuard Home on the LAN that uses DoH or DoT upstream loses its upstream. If it sends plain DNS to a public server, your redirect rule may catch that too, depending on how the rule is built.
    • Devices that insist on encrypted DNS. A device set to use only an encrypted DNS provider, for example a phone with Private DNS set to a hostname, may lose name lookups on this network once the rules refuse its route. Change that setting on the device.
    • The redirect rule must exist in Firewall → NAT → Destination NAT, with the description “Redirect non-local DNS to Local” or whatever you set in $NatDesc. It is not created or checked for how it is built.
    • The alias is overwritten with the Hagezi URL. The old contents are written to the log.
    • The test domain in $AdTestDomain must be blocked by your router’s blocklist, answered as 0.0.0.0 or with no address, or the redirect test fails.
    • A LAN you trust. The script’s certificate check accepts any certificate presented for the router’s address, so a device on the LAN posing as the router would receive the key. Run it only on a network you control.
    • The wait in $NatWaitSeconds should be longer than your router’s UDP state timeouts.
    • Rollback switches the two rules and the redirect rule off, even if the redirect was on before you first ran Apply. It does not restore the alias.
    1. Open PowerShell and make a folder. Open the Start menu, type powershell and press Enter. A window titled Windows PowerShell opens, and its prompt starts with PS. If the prompt has no PS, you are in Command Prompt: close it and open PowerShell instead, because the commands below work only in PowerShell. Click inside the window. Use the two lines below one at a time: click the PS> to copy a line, paste it (Ctrl + V, or right-click), and press Enter.

      New-Item -ItemType Directory -Path "$env:USERPROFILE\opnsense-dns"
      Set-Location "$env:USERPROFILE\opnsense-dns"

      The first line makes a folder called opnsense-dns inside your user folder and prints a short listing; the second moves PowerShell into it, and the prompt then ends with opnsense-dns>. Each takes under a second. If the first line says the folder exists, go on. Keep this window open, and keep the folder out of OneDrive, Dropbox and shared locations: the backups saved here hold the router’s whole configuration.

    2. Save the script. Scroll to The script, the mock router and the test harness at the end of this page, open opnsense-dns-bypass.ps1 (version 2.5.1), read it, and click Copy. It is 491 lines. It will use your router’s key, so read it before you run it. Windows marks files a browser downloads as coming from the internet; a file written by the command below has no such mark, so Unblock-File is not needed. The command replaces a file of the same name in this folder. In the PowerShell window:

      Get-Clipboard -Raw | Set-Content -Encoding Ascii .\opnsense-dns-bypass.ps1

      Get-Clipboard reads what you copied and Set-Content writes it to a file; the script is plain ASCII, so that encoding is safe. It takes under a second and prints nothing. Check that all of it arrived:

      (Get-Content .\opnsense-dns-bypass.ps1).Count
      491

      A different number suggests the copy was cut short or changed. Go back to the page, click Copy again and repeat the first command.

    3. Create an API key on the router. In a web browser, type https:// and the address you use for the router’s settings page (for example https://192.168.1.1), and press Enter. The browser may warn that the connection is not private, because the router signs its own certificate. Choose the option that continues to the address (in Chrome: Advanced, then Proceed). Log in with your own router login. Then:

      1. In the menu on the left, click System, then Access, then Users.
      2. Click the pencil (edit) icon at the end of the row of the administrator you log in as.
      3. Find the API keys section in the user’s settings (the OPNsense documentation calls it the ApiKeys tab) and use the button in its grid that creates a key.
      4. The browser downloads a small text file within a few seconds. It has a key= line and a secret= line. The documentation says the secret is generated only once; if the file is lost, make a new key.

      A key acts as the user it belongs to. I used the root user’s key and deleted it afterwards; the root key gives full control of the router. A user limited to the firewall, NAT and backup pages would hold less power, but the script downloads the router’s whole configuration, so that user can still read the password hashes and private keys in it. I have not tried a limited user. If your menu looks different, the OPNsense documentation on local users describes the same step. Do not paste the key file anywhere: the secret in it gives control of the router.

    4. Put the key file in the folder. Back in PowerShell, list the newest text files in your Downloads folder:

      Get-ChildItem "$env:USERPROFILE\Downloads" -Filter *.txt | Sort-Object LastWriteTime -Descending | Select-Object -First 3 Name, LastWriteTime
      Name                  LastWriteTime
      ----                  -------------
      example_apikey.txt    <date and time>

      If the list is empty, your browser saved the file somewhere else: press Ctrl + J in the browser to see where. Now move the file into the folder under the name the script expects. Replace <file-name>, angle brackets included, with the name from the list:

      Move-Item -LiteralPath "$env:USERPROFILE\Downloads\<file-name>" -Destination .\apikey.txt

      It takes under a second and prints nothing. It will not overwrite an apikey.txt already in the folder; if it refuses for that reason, an earlier key file is there. Remove that key on the router (step 8 shows where), run Remove-Item .\apikey.txt, and repeat this step. If it reports an error about the path, the path may still hold <file-name>, or the name may differ from the one in the list. Now check the key file has its two lines. This prints only the word before each =, never the values:

      Get-Content .\apikey.txt | ForEach-Object { ($_ -split '=')[0] }
      key
      secret

      If you see other words, this is probably not the key file. Download a new key (step 3).

    5. Run Check. It only reads. First tell PowerShell your router’s address. Click the PS> to copy the line, paste it, and do not press Enter yet. Replace <router-ip-address>, angle brackets included, with the numbers of the address from step 3 (for example 192.168.1.1), and leave https:// as it is. Move the cursor with the arrow keys, because a mouse click does not move it in PowerShell; Backspace deletes. Then press Enter. The script stops if the angle brackets are still there.

      $RouterUrl = 'https://<router-ip-address>'

      This remembers the address for this window only. If you close the window, repeat it.

      Now run the script. powershell -ExecutionPolicy Bypass -File starts a fresh Windows PowerShell 5.1 that runs the file. -ExecutionPolicy Bypass on the command line lasts for that one run, and Microsoft’s documentation on execution policies says it is not stored. It does not override a Group Policy set by an employer. Without -Mode the script runs Check.

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl

      It takes 10 to 60 seconds and changes nothing on the router. It saves a backup of the router’s configuration in the router-backups folder inside opnsense-dns, a log in logs, and runs five live tests. The lines that matter:

      HH:MM:SS  Router reports: OPNsense series 26.7, amd64
      HH:MM:SS  Backup (before) saved: C:\Users\<you>\opnsense-dns\router-backups\config-Check-before-<timestamp>.xml (NNN,NNN bytes)
      ...
      HH:MM:SS  Router resolves example.com            : True   (want True)
      HH:MM:SS  Router blocks the ad domain (blocklist) : True   (want True)
      HH:MM:SS  Bypass DoH  1.1.1.1:443 reachable       : True   (want False after Apply)
      HH:MM:SS  Bypass DoT  9.9.9.9:853 reachable       : True   (want False after Apply)
      HH:MM:SS  Bypass 8.8.8.8 gives real ad IPs        : True   (want False after Apply)
      HH:MM:SS  Check mode: nothing was changed on the router.
      HH:MM:SS  Log file: C:\Users\<you>\opnsense-dns\logs\run-Check-<timestamp>.log

      Both “want True” lines must be True. If “Router blocks the ad domain” is False, your blocklist does not block the test domain and the redirect test in step 6 would fail. Set $AdTestDomain near the top of the script to a domain your blocklist blocks, or switch the blocklist on. If a yellow line starts Apply would stop:, it names a missing rule: the redirect rule or the LAN allow-all rule. Fix that on the router before step 6.

      If something went wrong. The script prints a red line (most contain the word STOP) and changes nothing on the router. What the line says, and what it means:

      • Set -Router to your router’s address: the angle brackets are still in the address from this step.
      • Missing an argument for parameter ‘Router’: probably the address line above was not run in this window. Run it again.
      • -Router must start with https://: the address begins with http://. Use https://.
      • STOP: Key file not found: apikey.txt is not in the opnsense-dns folder. Redo step 4.
      • STOP: Cannot reach the router API with this key: the address is wrong, the key was removed, or the PC is not on the router’s network. Open the address in the browser to test it.
      • STOP: Script was built for OPNsense 26.7: your router runs another series, and the script’s API paths were read from 26.7. Stop here.
      • PowerShell says running scripts is disabled: a policy on your PC blocks scripts, and the command-line option cannot override it. Stop here.
    6. Run Apply. This changes the router. It overwrites the alias DoH_IPs with the Hagezi list address (the old contents go to the log), adds the two reject rules if they are missing, and switches the redirect rule on. Devices on your network that talk to a DNS-over-HTTPS or DNS-over-TLS server directly lose that route; that is the purpose. Run the same command with -Mode Apply added:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl -Mode Apply

      It takes about two minutes, and up to four if the alias has to download its list first. One line says Waiting 70 s for older DNS states to expire before testing...; wait for it and do not close the window. The last lines should read:

      HH:MM:SS  Bypass DoH  1.1.1.1:443 reachable       : False   (want False after Apply)
      HH:MM:SS  Bypass DoT  9.9.9.9:853 reachable       : False   (want False after Apply)
      HH:MM:SS  Bypass 8.8.8.8 gives real ad IPs        : False   (want False after Apply)
      HH:MM:SS  Backup (after) saved: C:\Users\<you>\opnsense-dns\router-backups\config-Apply-after-<timestamp>.xml (NNN,NNN bytes)
      HH:MM:SS  Apply finished. Expected: router tests True, all three bypass tests False.
      HH:MM:SS  Log file: C:\Users\<you>\opnsense-dns\logs\run-Apply-<timestamp>.log

      If something went wrong. Apply did not complete; changes from this run were undone: a test failed, and the script switched off what it had changed. Rules it added stay, switched off. It saved a backup of the result. Read the line that starts Problem: for the reason. If any line says UNDO STEP FAILED, restore the “before” backup as step 8 describes. Apply PARTLY finished (in yellow): the alias and the two rules are in place and tested, and the redirect did not pass; the line says whether the redirect was left on or off. To switch the fix off, use step 8.

    7. Check that it worked. Run the Check command from step 5 again:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl

      Now the three Bypass lines read False and the two Router lines read True. In the router’s web page you can also look at Firewall → Rules (choose LAN in the interface selector), where the two rules Reject DoH to known resolvers (A) and Reject DoT/DoQ 853 from LAN (B) now appear, and at Firewall → NAT → Destination NAT, where Redirect non-local DNS to Local is enabled.

    8. Switch it off, restore if you need to, and remove the key. To switch the fix off, run the command with -Mode Rollback:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl -Mode Rollback

      It takes under a minute. It disables the two rules and the redirect and deletes nothing. The alias stays as Apply left it. If the redirect was on before you started, it is now off: switch it back on in Firewall → NAT → Destination NAT.

      To put the whole configuration back as it was before Apply, restore the backup on the router: go to System → Configuration → Backups, choose the file named config-Apply-before-<timestamp>.xml from the router-backups folder, and restore it. Each Apply run saves one such file; the earliest holds the configuration from before your first Apply. That also undoes any other change made on the router since.

      When you have finished with the script, whether you keep the fix or not, remove the key. On the router go to System → Access → Users, click the pencil on the same user, and remove the key in the API keys section (the ApiKeys tab). Then delete the key file from the PC:

      Remove-Item .\apikey.txt

      This deletes the file at once, with no recycle bin. When you no longer need the backups, delete the router-backups folder too: it holds password hashes and private keys.

    Security notes. The script sends the key with every request. It does not print or log the secret, and the test kit checks that in each of its 30 cases. Its certificate check accepts any certificate presented for the router’s address, so a device on the LAN posing as the router would receive the key. I deleted my key on 13 October 2026, two days after the run, and the router’s configuration history records the deletion.

    The backups are the router’s whole configuration: password hashes, and the private keys of its certificates and VPN tunnels. Keep that folder private, and do not attach a backup to a forum post.

    Deep dive: the script’s other checks
    • The backup must look like a backup. After downloading, the script checks the file is at least 50,000 bytes and has <opnsense> in its first three lines.
    • A failed save is caught. A reply carrying validations counts as a failed save, as it does in the router’s own web pages; so does a result of failed. Alias and redirect changes are read back. Rule changes are checked by the rules’ presence and order, and by live connection tests.
    • Rule order. After adding Rules A and B, the script stops if either sorts after “Default allow LAN to any rule”, because a rule below the allow-all rule would never match.
    • The alias must fill. It polls the alias every 5 seconds for up to 90 seconds and stops unless it holds at least 500 addresses.
    • Normal browsing must still work. Before declaring the rules good, it opens a connection to www.google.com:443.
    • A partial result says so. If only the redirect stage fails, the run ends Apply PARTLY finished, says what state it left the redirect in, and exits with code 2.
    Deep dive: accepting a bad certificate only for the router’s address

    The router’s web interface uses a self-signed certificate. PowerShell 7 has -SkipCertificateCheck, which the script uses there. Windows PowerShell 5.1 has no such switch. A common workaround is a callback that accepts every certificate for the whole session. The script’s callback accepts a failed certificate check only when the request’s host is the router’s address:

    public static bool Check(object sender, X509Certificate c, X509Chain ch, SslPolicyErrors e) {
        if (e == SslPolicyErrors.None) return true;
        HttpWebRequest r = sender as HttpWebRequest;
        return r != null && r.RequestUri.Host == Host;
    }

    This narrows the exception. It does not pin the certificate: any certificate presented for that address passes. Checking the certificate’s thumbprint would close that gap. The script also sets TLS 1.2 for 5.1.

    Deep dive: a precaution, not a failure: Expect: 100-continue

    Check mode sends only GET requests. Apply sends POSTs. Windows PowerShell 5.1 runs on the .NET Framework, where ServicePointManager.Expect100Continue is true by default and adds an Expect: 100-continue header to POST requests that carry a body (Microsoft’s documentation). Version 2.2 switches the header off before the first request:

    [Net.ServicePointManager]::Expect100Continue = $false

    I did not test whether the router’s web server would have objected to the header.

    Deep dive: the finished run, line by line

    The log of the 15:04 run. The router’s address and the name of one of its interfaces are replaced with placeholders in angle brackets; the local folder and the PowerShell build number are removed, and the digits in the byte counts are grouped in threes. The opening tests show all three ways around the blocklist open; the closing tests show them shut, for the three IPv4 addresses tested.

    15:04:49  Mode: Apply   Router: https://<router-ip-address>   PowerShell 5.1
    15:04:55  Router reports: OPNsense series 26.7, amd64
    15:04:55  Backup (before) saved: ...\config-Apply-before-20261011-150449.xml (404,269 bytes)
    15:04:56  Alias DoH_IPs: present, enabled=1, entries loaded=1434, content=[__<interface>_network | https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt]
    15:04:56  Rule A: present, enabled=0, sort_order=400000.0000100
    15:04:56  Rule B: present, enabled=0, sort_order=400000.0000200
    15:04:56  'Default allow LAN to any rule': sort_order=400000.1000023
    15:04:56  NAT 'Redirect non-local DNS to Local': disabled=1
    15:04:56  Router resolves example.com            : True   (want True)
    15:04:56  Router blocks the ad domain (blocklist) : True   (want True)
    15:04:56  Bypass DoH  1.1.1.1:443 reachable       : True   (want False after Apply)
    15:04:56  Bypass DoT  9.9.9.9:853 reachable       : True   (want False after Apply)
    15:04:56  Bypass 8.8.8.8 gives real ad IPs        : True   (want False after Apply)
    15:04:56  Alias DoH_IPs set to the URL only (was: __<interface>_network | https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt).
    15:04:58  Alias DoH_IPs holds 1434 addresses.
    15:04:58  Rule 'Reject DoH to known resolvers (A)' enabled.
    15:04:58  Rule 'Reject DoT/DoQ 853 from LAN (B)' enabled.
    15:04:58  Firewall rules applied. Verifying...
    15:05:08  Rules A and B verified: DoH and DoT refused, normal HTTPS works.
    15:05:08  NAT rule enabled and applied. Waiting 70 s for older DNS states to expire before testing...
    15:06:18  NAT redirect verified: queries to 8.8.8.8 are answered by your router.
    15:06:19  Alias DoH_IPs: present, enabled=1, entries loaded=1434, content=[https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt]
    15:06:19  Rule A: present, enabled=1, sort_order=400000.0000100
    15:06:19  Rule B: present, enabled=1, sort_order=400000.0000200
    15:06:19  'Default allow LAN to any rule': sort_order=400000.1000023
    15:06:19  NAT 'Redirect non-local DNS to Local': disabled=0
    15:06:23  Router resolves example.com            : True   (want True)
    15:06:23  Router blocks the ad domain (blocklist) : True   (want True)
    15:06:23  Bypass DoH  1.1.1.1:443 reachable       : False   (want False after Apply)
    15:06:23  Bypass DoT  9.9.9.9:853 reachable       : False   (want False after Apply)
    15:06:23  Bypass 8.8.8.8 gives real ad IPs        : False   (want False after Apply)
    15:06:23  Backup (after) saved: ...\config-Apply-after-20261011-150449.xml (404,254 bytes)
    15:06:23  Apply finished. Expected: router tests True, all three bypass tests False.

    The alias held one entry I had not put there on purpose: the network of one of the router’s interfaces, ahead of the URL. The run printed the old contents before replacing them, so they can be restored from the log.

    Deep dive: what the test kit checks, and what it cannot

    The mock answers the script’s API paths, keeps the router’s state in memory, records every call, and can be set to misbehave: a wrong version, a bad API key, a small backup, a backup that fails after changes, an alias of the wrong type, a reply with an empty key, a save the router rejects, an alias that does not fill, rules that sort below the allow-all rule, DoH still reachable, normal HTTPS broken, a missing redirect rule or allow rule, a redirect that does not take effect, and a redirect that was already on. It also plays the states my router went through: the alias with a stray entry, the two rules left disabled by version 2.3, and everything already applied. Its reply with an empty key is written by hand, after the router’s get_item reply, and served on the endpoint the script reads.

    The harness runs the script once per case, as a separate process, and checks the exit code, the log, the backup files, every call the mock received, and the mock router’s state at the end. In every case it checks that neither the secret nor the encoded key appears in the output or the log, that nothing was deleted, and that a stop after the log is opened is written to the log.

    The harness tests a copy of the script, not the script itself. In the copy, the two network tests ask the mock instead of the internet, and every wait is cut to a millisecond; before any case runs, the harness checks that each of those patterns matched the expected number of times. The copy talks to the mock over plain HTTP on the PC; the script accepts plain HTTP only for an address on the PC itself.

    So the kit does not test: the certificate check and TLS; the real network tests; failure 3, because the mock has no state table and the waits are cut; replies from a real router, apart from the one hand-written empty-key reply; the script’s refusal to overwrite a backup; the fallback for the work folder, because every case names one; or an undo step that itself fails.

    The ten deliberate breaks and the cases each one made fail are listed with the kit at the end of the page.

    Deep dive: OPNsense 26.7 API notes
    • The script’s header records that each configuration path was taken from the router’s own web pages on the day: alias/search_item, alias/add_item, alias/set_item, alias/reconfigure, filter/search_rule, filter/add_rule, filter/set_rule, filter/apply, d_nat/search_rule, d_nat/set_rule, d_nat/apply, alias_util/list and core/backup/download/this. It also calls core/firmware/info for the version and core/firmware/status as a reachability check.
    • The search endpoints answer a GET with ?rowCount=-1&current=1 and return every row, with the fields the script needs.
    • alias/get_item returns option lists with empty-named keys, which PowerShell cannot turn into object properties.
    • GET /api/core/backup/download/this returns the full configuration as XML.
    • POST bodies are JSON with Content-Type: application/json. Rule changes take effect after the matching apply; alias changes after reconfigure.
    Glossary
    • Windows PowerShell 5.1: the PowerShell that comes with Windows, built on the .NET Framework. Started as powershell.
    • PowerShell 7: the newer PowerShell, installed separately, built on modern .NET. Started as pwsh.
    • REST API: a set of web addresses a program calls to read or change settings; OPNsense’s replies are JSON.
    • JSON: a text format for structured data.
    • Mock: a stand-in for a real system, used for testing; here, a small web server that answers like the router.
    • Test harness: a script that runs another script in many set situations and checks the results.
    • API key: a key and secret that let a script act as a router user without a password.
    • Alias (URL table): an OPNsense list of addresses that the router downloads from a web address and refreshes.
    • NAT redirect: a rule that changes where matching traffic goes; here it sends stray DNS queries to the router.
    • State table: the firewall’s list of connections it has already seen. Later packets of a known connection follow the decision made for the first.
    • DoH, DoT: DNS over HTTPS (port 443) and DNS over TLS (port 853), two ways for a device to look up names without asking the router.
    • Expect: 100-continue: an HTTP header that asks the server to approve a request before its body is sent.

    Script हर test में पास हुई, ग़लत जगह पर

    10 मिनट में पढ़ें · अंग्रेज़ी मूल से अनूदित। Code, commands और तकनीकी नाम अंग्रेज़ी में रखे गए हैं।

    11 अक्टूबर 2026 की दोपहर मैंने अपने OPNsense router की API पर एक script चलाई, Windows PowerShell 5.1 से, यानी वह PowerShell जो Windows के साथ आता है। Script अपने log की पहली line लिखने से पहले ही रुक गई। Router को script की पहली call उस line के बाद आती है, इसलिए, जहाँ तक मैं बता सकता हूँ, router तक कुछ नहीं पहुँचा।

    वह वर्ज़न 2.0 था। वर्ज़न 2.4 ने काम 15:06 पर पूरा किया, वर्ज़न 2.0 save करने के 37 मिनट बाद। हर वर्ज़न पहले Claude के sandbox में अपने tests पास कर चुका था। वे tests ग़लत जगह पर चले थे: असली router की जगह एक mock router पर, और Windows PowerShell 5.1 की जगह PowerShell 7 पर। Mock ने उन तीनों वर्ज़नों को पास किया जो बाद में router पर fail हुए। PowerShell के फ़र्क़ की failure 1 में कोई भूमिका थी या नहीं, मुझे नहीं पता। Failure 2 में उसकी कोई भूमिका नहीं थी, और बाद में उसकी वजह से मेरा test harness fail हुआ। तीन runs fail हुए, हर एक अलग वजह से। किसी ने भी कोई बदलाव चालू नहीं छोड़ा।

    यह काम मैंने Claude के साथ किया। Script को किन नियमों पर चलना है, यह मैंने तय किया, API key बनाई और बाद में delete की, और हर वर्ज़न अपने PC से अपने router पर चलाया। Script, जिस mock router पर उसे test किया गया, और हर fix, Claude ने लिखे। उसने इन्हें PowerShell 7 पर test किया, जो उसके sandbox में मौजूद अकेला PowerShell था।

    Script, एक mock router और एक test harness इस पेज के आख़िर में हैं, MIT licence के तहत। Script router से उसकी DNS blocklist को bypass करने के तीन आम तरीक़े बंद करवाती है: DNS over HTTPS, DNS over TLS या QUIC, और किसी दूसरे server को भेजा गया सादा DNS। यह पेज runs का record और मैं क्या बदलूँगा, यह बताता है, और आख़िर के पास एक panel आपके अपने router पर script चलाने के चरण समझाता है।

    Command line आपके लिए नई है? Boxes को कैसे पढ़ें

    PS> का मतलब है: इसे Windows में PowerShell में type करें (Start menu → powershell type करें → Enter)। PS> को ख़ुद type न करें।

    जिस भी line की शुरुआत PS> से होती है, वह एक command है। सिर्फ़ उस line को copy करने के लिए उसके PS> पर click करें, उसे paste करें, Enter दबाएँ, और अगली command से पहले उसके पूरा होने का इंतज़ार करें। ऊपर Copy button वाला box एक command (या एक file) रखता है, इसलिए उसे पूरा copy करें। टूटी (dashed) रेखा वाला box दिखाता है कि जवाब में आपको क्या दिखना चाहिए, या पढ़ने के लिए code; उसे आप type नहीं करते।

    Script क्या करती है

    Script एक OPNsense 26.7 router पर DNS का एक fix लगाती है। मेरे router की blocklist सिर्फ़ उन devices को filter करती है जो router से पूछते हैं; फ़ोन, browsers और कुछ devices दूसरे servers से पूछते हैं। इस fix में चार objects हैं:

    • एक alias, DoH_IPs, जो Hagezi project की रखी DNS-over-HTTPS servers के पतों की एक public list download करता है (उस दिन 1,434 पते);
    • Rule A, जो उन पतों पर port 443 की LAN traffic को reject करता है;
    • Rule B, जो किसी भी पते पर port 853 की LAN traffic को reject करता है, जिसे DNS over TLS और DNS over QUIC इस्तेमाल करते हैं;
    • एक NAT redirect, जो router को छोड़कर कहीं और जाने वाली port 53 की हर query को वापस router पर भेजता है।

    मेरे router पर alias और redirect rule पहले से मौजूद थे, और redirect बंद था। Script alias को साफ़ करती है, दोनों rules न हों तो बनाती है, और redirect को चालू करती है। वह redirect rule नहीं बनाती। Rules सिर्फ़ IPv4 और LAN interface को cover करते हैं; सीमाएँ आख़िर के पास step-by-step panel में दी गई हैं।

    ये चार objects मैं click करके भी लगा सकता था। Script इसलिए लिखी क्योंकि मुझे यह बदलाव ऐसे रूप में चाहिए था जिसे मैं कुछ बदले बिना जाँच सकूँ, दोबारा चला सकूँ, और एक command से बंद कर सकूँ।

    किन नियमों पर चलती है

    1. तीन modes। Check पढ़ता है और report देता है। Apply बदलाव करता है। Rollback दोनों rules और redirect को बंद करता है और कुछ delete नहीं करता। -Mode के बिना command Check चलाती है।
    2. वर्ज़न की जाँच। Script पहले router से पूछती है कि उस पर क्या चल रहा है, और जवाब 26.7 series न हो तो रुक जाती है।
    3. उसके बाद backup। कोई भी configuration पढ़ने या बदलने से पहले, हर run router की पूरी configuration एक नई file में download करता है। वह किसी मौजूदा file को overwrite करने से मना करता है।
    4. हर बदलाव का test। पहले alias, फिर दोनों rules, फिर redirect। वर्ज़न 2.3 में एक fail हुआ test उस run के सारे बदलाव undo कर देता था। वर्ज़न 2.4 से, अगर सिर्फ़ redirect fail हो, तो सिर्फ़ redirect बंद होता है, और जो rules पास हुए वे बने रहते हैं।
    5. Script में कोई secret नहीं। API key एक अलग file में रहती है।

    सैंतीस मिनट

    शुरू वर्ज़न Mode क्या हुआ Router पर क्या बचा
    14:29 के बाद 2.0 log नहीं हुआ अपनी पहली log line से पहले रुकी कुछ नहीं
    14:43 2.1 Check सिर्फ़ पढ़ने वाली report, पूरी कुछ नहीं
    14:51 2.2 Apply किसी save से पहले अपनी ही सुरक्षा-जाँच पर रुकी कुछ नहीं
    14:56 2.3 Apply Rules चले; redirect test fail; undo हुआ दो rules, बंद
    15:04 2.4 Apply 15:06 पर पूरी, हर test पास Fix

    वर्ज़न 2.0 ने कोई log नहीं लिखा, इसलिए उसका समय वह मिनट है जब मैंने file save की। बाक़ी समय script के अपने logs से हैं।

    कामों के क्रम ने नुक़सान सीमित रखा। Script वर्ज़न जाँचती है, backup लेती है, और लिखने से पहले पढ़ती है। Failure 1 router को कोई भी call जाने से पहले रुका। Failure 2 किसी भी save से पहले रुका, एक ऐसी जाँच पर जो किसी दूसरी समस्या के लिए लिखी गई थी। Failure 3 बदलाव होने के बाद हुआ, और उस वर्ज़न के undo ने उन्हें बंद कर दिया।

    Failure 1: एक वजह जो मैंने ग़लत समझी

    वर्ज़न 2.0 अपना working folder एक parameter default से लेता था:

    [string]$WorkDir = $PSScriptRoot

    $PSScriptRoot वह folder है जिसमें script रखी है। Script इससे अपने logs folder का path बनाती है, जिसे वह key पढ़ने या router को call करने से पहले बनाती है।

    वर्ज़न 2.1 ने तीन चीज़ें बदलीं। उसने folder script के body में तय किया, वह folder मौजूद न होने पर रुकने लगी, और दो गिनतियों को wrap किया ताकि DNS का ख़ाली जवाब शून्य गिना जाए। इनमें से सिर्फ़ folder वाले बदलाव पहली log line से पहले आते हैं। उस दिन Claude और मैंने यह नतीजा निकाला कि Windows PowerShell 5.1 ने $PSScriptRoot ख़ाली छोड़ दिया था, और इस post के पहले drafts में यही लिखा था।

    इस post के test kit ने इसकी जाँच की, और वह नतीजा ग़लत निकला। मेरे PC पर Windows PowerShell 5.1 ने, -File के साथ शुरू करने पर, जैसे मैं script शुरू करता हूँ, parameter default में $PSScriptRoot में folder डाल दिया। PowerShell 7.4.6 ने भी। मैंने script शुरू करने के हर तरीक़े को test नहीं किया, इसलिए मैं इस संभावना को ख़ारिज नहीं कर सकता कि कुछ तरीक़ों में वह ख़ाली रहता है। उस दोपहर मैंने वर्ज़न 2.0 को कैसे शुरू किया, या उसने कौन-सा error दिखाया, यह मैंने दर्ज नहीं किया, इसलिए मुझे नहीं पता कि उसे किस चीज़ ने रोका। सबूत इससे कम बात का समर्थन करते हैं: वर्ज़न 2.0 अपनी पहली log line से पहले रुका, और इसलिए, जहाँ तक सबूत दिखाते हैं, router को कोई भी call जाने से पहले रुका। प्रकाशित script की एक comment कहती है कि Windows PowerShell 5.1 में folder ख़ाली हो सकता है। वह comment मेरे पहले नतीजे को दोहराती है; मैंने test की हुई file को वैसा ही रहने दिया।

    वर्ज़न 2.1 का बदलाव बना रहता है। इसकी कोई क़ीमत नहीं है और script किसी भी तरह शुरू हो, यह काम करता है:

    if ([string]::IsNullOrWhiteSpace($WorkDir)) {
        if ($MyInvocation.MyCommand.Path) { $WorkDir = Split-Path -Parent $MyInvocation.MyCommand.Path }
        else { $WorkDir = (Get-Location).Path }
    }

    वर्ज़न 2.1 का Check run 14:43 पर पूरा हुआ।

    Failure 2: router की ख़ासियतों के बिना एक mock

    Alias का type जाँचने के लिए वर्ज़न 2.2 ने router का alias/get_item endpoint call किया। 14:51 का run log:

    14:51:46  Problem: Existing alias DoH_IPs is type '', not urltable. Fix or delete it in the GUI, then rerun.
    14:51:46  Nothing to undo.
    ...
    14:51:47  STOP: Apply did not complete; changes from this run were undone.

    Alias का type ख़ाली नहीं था। Router के जवाब में ऐसी entries हैं जिनका नाम एक ख़ाली string है ("":)। JSON इसकी इजाज़त देता है। PowerShell ख़ाली नाम वाली object property नहीं बना सकता। ConvertFrom-Json के लिए Microsoft के दस्तावेज़ यही कहते हैं (PowerShell 7.4 का reference), और ऐसे जवाबों के लिए -AsHashtable switch देते हैं। Windows PowerShell 5.1 में यह switch नहीं है। Invoke-RestMethod ने कोई error नहीं दिया। उसने जवाब सादे text के रूप में लौटाया, और script को उस text से type ख़ाली मिला।

    यह PowerShell वर्ज़नों का फ़र्क़ नहीं था। Test kit script को ख़ाली key वाला एक जवाब देता है। PowerShell 7.4.6 पर, और मेरे PC पर Windows PowerShell 5.1 में, Invoke-RestMethod ने उसे text के रूप में लौटाया, बिना किसी error के। वर्ज़न 2.2 mock पर इसलिए पास हुआ क्योंकि mock के जवाब में कोई ख़ाली key नहीं थी। Router के जवाब में थीं।

    जिस सुरक्षा-जाँच ने run रोका वह एक दूसरी समस्या के लिए लिखी गई थी: ग़लत type का पहले से मौजूद alias। उसने यह run इसलिए रोका क्योंकि ख़ाली type urltable नहीं है। उसके बिना, run नया URL save कर देता और फिर undo पर alias में एक ख़ाली string लिख देता।

    14:43 के Check run ने यह नहीं पकड़ा था। Check alias को alias/search_item से पढ़ता था। सिर्फ़ Apply ने get_item call किया।

    वर्ज़न 2.3 दो बदलाव करता है। Router के search_item और search_rule endpoints पहले से type और contents लौटाते हैं, और उनके जवाब parse हो गए थे, इसलिए script सिर्फ़ उन्हीं से पढ़ती है। और अब हर API call एक helper से होकर जाती है जो ऐसा जवाब मानने से मना करता है जिसे वह parse न कर सके:

    $r = Invoke-RestMethod @p
    if ($r -is [string]) {
        $t = $r.TrimStart()
        if ($t.StartsWith('{') -or $t.StartsWith('[')) { throw "Router reply to $Path could not be read as JSON by this PowerShell; stopping." }
    }

    Failure 3: बहुत जल्दी test किया गया redirect

    वर्ज़न 2.3 आगे पहुँचा। उसने alias साफ़ किया, दोनों rules जोड़े और उन्हें test किया। फिर उसने NAT redirect चालू किया और पाँच सेकंड बाद उसे test किया:

    14:57:16  Rules A and B verified: DoH and DoT refused, normal HTTPS works.
    14:57:17  NAT rule enabled and applied. Verifying...
    14:57:22  Problem: 8.8.8.8 still returns real ad addresses; the redirect is not taking effect.
    14:57:22  Undoing changes made in this run...

    Test 8.8.8.8 को दो queries भेजता है: एक example.com के लिए और एक किसी ad domain के लिए। Firewall के log में दोनों में से एक redirect हुई दिखी। Ad domain असली पतों के साथ लौटा, इसलिए redirect न होने वाली query वही थी। Redirect चालू करने से तेरह सेकंड पहले, script की शुरुआती जाँच ने यही नाम 8.8.8.8 को भेजा था, यह दिखाने के लिए कि bypass खुला है।

    मेरे पास दो व्याख्याएँ हैं, और मैंने किसी को test नहीं किया। Firewall हर उस connection की state entry रखता है जो वह देख चुका है, और redirect सिर्फ़ नए connections पर लागू करता है। अगर ad domain की दूसरी query मेरे PC से उसी source port से निकली जिससे पहली, तो वह पुरानी entry से match हुई और Google तक चली गई। या मेरे PC पर किसी चीज़ ने दोहराए गए सवाल का जवाब याद से दे दिया, और query PC से बाहर निकली ही नहीं।

    इस router के UDP state timeouts, जो Firewall → Diagnostics → Statistics से पढ़े, udp.first और udp.multiple के लिए 60 सेकंड और udp.single के लिए 30 सेकंड हैं। वर्ज़न 2.4 test करने से पहले 70 सेकंड रुकता है, और test पास हुआ:

    15:05:08  NAT rule enabled and applied. Waiting 70 s for older DNS states to expire before testing...
    15:06:18  NAT redirect verified: queries to 8.8.8.8 are answered by your router.

    यह इंतज़ार firewall की state entries से लंबा है। क्या यह PC पर याद रखे गए जवाब से भी लंबा है, यह इस पर निर्भर है कि वह जवाब कितनी देर रखा जाता है, जो मैंने नहीं मापा। इसलिए यह नतीजा दोनों व्याख्याओं में फ़र्क़ नहीं करता। पहले न पूछे गए किसी नाम के साथ, firewall की state table खोलकर किया गया test यह फ़र्क़ कर सकेगा।

    वर्ज़न 2.3 के undo ने redirect बंद किया, दोनों नए rules disable किए और alias के contents वापस रखे। उसने rules delete नहीं किए, और alias का refresh interval एक दिन पर छोड़ दिया। Undo के बाद लिया गया backup run से पहले वाले backup से 4,788 bytes बड़ा है। वर्ज़न 2.4 ने शुरुआत में ही उन दोनों rules को ढूँढ लिया:

    15:04:56  Rule A: present, enabled=0, sort_order=400000.0000100
    15:04:56  Rule B: present, enabled=0, sort_order=400000.0000200

    तो “undo हुआ” का मतलब था “कुछ भी चालू नहीं बचा”, न कि “router जैसा था वैसा”। वर्ज़न 2.4 ने नई copies जोड़ने की जगह दोनों मौजूदा rules चालू किए, क्योंकि वह rules बनाने से पहले उन्हें description से ढूँढता है।

    Mock से क्या छूटा, और tests का दूसरा दौर

    मेरे router पर चलाने से पहले Claude हर वर्ज़न अपने mock पर चला चुका था। उस session के record के अनुसार, हर वर्ज़न एक बार सामान्य रूप से चला और एक बार ज़बरदस्ती कराई गई failure के साथ, undo जाँचने के लिए। वर्ज़न 2.0 से 2.3 mock पर पास हुए। Router पर चार में से तीन fail हुए। Mock कभी Windows PowerShell 5.1 पर नहीं चला, और उसके जवाबों में router की ख़ाली keys नहीं थीं।

    इस पेज के आख़िर में दी गई script वर्ज़न 2.5.1 है, 2.4 नहीं। Publish करने से पहले मैंने Claude से script का फिर review कराया, और वर्ज़न 2.5 उस review में मिली चीज़ें ठीक करता है: ऐसे messages जो router की state को ग़लत बता सकते थे, ऐसे stops जो log में नहीं लिखे जाते थे, एक undo जो alias का enabled flag वापस नहीं रखता था, और ऐसे runs जो redirect rule या LAN allow-all rule के बिना वाले router पर शुरू हो सकते थे। यह ऐसे router पते को भी मना करता है जो https:// से शुरू न हो, सिवाय PC पर ही मौजूद पते के, जिसे test kit इस्तेमाल करता है। मेरे router पर वर्ज़न 2.4 चला था। वर्ज़न 2.5.1, जो 2.5 से सिर्फ़ अपनी header comments में अलग है, सिर्फ़ mock पर चला है।

    Tests के दूसरे दौर में एक नया mock इस्तेमाल हुआ, जो उसी तरह गड़बड़ करने के लिए बनाया गया था जैसे कोई router कर सकता है, ख़ाली key वाले जवाब समेत। एक harness ने script की एक copy उस पर 30 cases में से हर एक के लिए एक बार चलाई। PowerShell 7.4.6 पर सभी 30 पास हुए।

    मेरे PC पर Windows PowerShell 5.1 के तहत पहले run में दो cases fail हुए। Script के logs दिखाते थे कि उसने सही काम किया था; harness ने नहीं। जब कोई PowerShell function एक item वाली list लौटाता है, तो call करने वाले को वह item ही मिलता है। PowerShell 7 आपको उस item को list की तरह गिनने और index करने देता है। Windows PowerShell 5.1 इस तरह के object के लिए ऐसा नहीं करता। Harness सिर्फ़ PowerShell 7 पर चला था। यह ठीक करने के बाद, script के publish किए गए वर्ज़न पर Windows PowerShell 5.1 में भी सभी 30 cases पास हुए।

    ख़ुद harness को जाँचने के लिए Claude ने script को दस तरह से तोड़ा, जैसे undo, JSON की जाँच या HTTPS की जाँच हटाकर। हर बिगाड़ से कम से कम एक case fail हुआ। यह जाँच PowerShell 7.4.6 पर, वर्ज़न 2.5 के विरुद्ध, harness के एक पहले वर्ज़न के साथ चली थी।

    अगली script के लिए मैं क्या साथ ले जाऊँगा

    1. उसी PowerShell पर test करें जिस पर script चलेगी, और tests भी वहीं चलाएँ। मेरा harness PowerShell 7 पर पास हुआ और 5.1 पर अपने पहले run में fail हुआ।
    2. Mock के जवाब असली जवाबों से बनाएँ। Router के get_item से save किया गया एक जवाब failure 2 को router तक script पहुँचने से पहले पकड़ लेता।
    3. सिर्फ़ पढ़ने वाला mode वे सारे reads करे जो लिखने वाला mode करेगा। यहाँ Check और Apply alias को अलग-अलग endpoints से पढ़ते थे।
    4. जब आप object की उम्मीद कर रहे हों, तो Invoke-RestMethod से मिली string को failure मानें। वह हमेशा error नहीं देता।
    5. Redirect चालू करने के बाद firewall के state timeout से ज़्यादा इंतज़ार करें, और ऐसे नाम से test करें जो आपने पहले query न किया हो।
    6. अगर undo delete करने की जगह disable करता है, तो अगला run वह ढूँढे जो पिछला छोड़ गया।
    7. Script को जान-बूझकर तोड़ें, यह जाँचने के लिए कि tests fail हो सकते हैं।
    8. API key को script से बाहर रखें और काम पूरा होने पर उसे delete करें। मैंने root user की key इस्तेमाल की। सिर्फ़ उतने privileges वाला user बेहतर होगा जितने script को चाहिए; यह मैंने आज़माया नहीं है।
    अपने router पर चरण-दर-चरण चलाएँ

    शुरू करने से पहले। आपको चाहिए:

    • एक Windows PC, जो router वाले ही network पर हो। आप दो जगह type करेंगे: PC पर PowerShell में, और browser में router के web page पर;
    • OPNsense 26.7। Script किसी दूसरी series पर रुक जाती है, क्योंकि उसके API paths उसी series के अपने pages से पढ़े गए थे;
    • DNS blocklist चालू, Services → Unbound DNS → Blocklist में (OPNsense के दस्तावेज़ उस page का नाम देते हैं), और आपके devices DNS के लिए router से पूछते हों;
    • एक Destination NAT rule जो router को छोड़कर कहीं और जाने वाली DNS queries (port 53) को वापस router पर भेजता है, पहले से बना हुआ, description “Redirect non-local DNS to Local” के साथ। Script उसे चालू करती है। वह उसे बनाती नहीं है। Script यह rule नहीं बनाती, यह panel भी इसे बनाना नहीं बताता, और इसके बिना Apply रुक जाता है। OPNsense forum पर एक community how-to एक तरीक़ा दिखाता है;
    • एक LAN rule जिसका नाम “Default allow LAN to any rule” है, जिसे OPNsense default रूप से बनाता है। Script जाँचती है कि उसके दो नए rules उसके ऊपर बैठते हैं।

    वर्ज़न 2.5.1, यानी इस panel की script, सिर्फ़ test kit के mock router पर चली है। मेरे router पर वर्ज़न 2.4 चला था।

    लगभग 20 मिनट रखें; बदलाव ख़ुद लगभग दो मिनट लेता है। Router में पहला बदलाव step 3 की API key है। Step 5 का Check run उसमें कुछ नहीं बदलता। Step 6 का Apply बदलता है। Step 8 fix को बंद करता है और पूरी configuration restore करना दिखाता है। हर run router की configuration पढ़ने से पहले उसका backup PC पर save करता है।

    पहले सीमाएँ पढ़ें। अगर उनमें से कोई आपके network का वर्णन करती है, तो script आपके लिए ठीक नहीं है, इसलिए आगे न बढ़ें।

    सीमाएँ

    • सिर्फ़ IPv4। Rules A और B IPv4 के लिए बनते हैं, और हर test एक IPv4 पता इस्तेमाल करता है। अगर आपके LAN पर IPv6 है, तो IPv6 पर DoH और DoT न block होते हैं, न test। (Interfaces → LAN में एक IPv6 Configuration Type दिखता है; None का मतलब IPv6 नहीं है।)
    • सिर्फ़ LAN interface। दूसरे interfaces और VLANs cover नहीं होते।
    • LAN का हर host। LAN पर कोई Pi-hole या AdGuard Home जो upstream के लिए DoH या DoT इस्तेमाल करता है, अपना upstream खो देता है। अगर वह किसी public server को सादा DNS भेजता है, तो आपका redirect rule उसे भी पकड़ सकता है, यह इस पर निर्भर है कि rule कैसे बना है।
    • जो devices encrypted DNS पर ही अड़े रहते हैं। जो device सिर्फ़ किसी encrypted DNS provider के लिए set है, जैसे Private DNS में hostname वाला फ़ोन, उसका DNS lookup इस network पर बंद हो सकता है, जब rules उसका रास्ता refuse कर दें। वह setting device पर बदलें।
    • Redirect rule मौजूद होना चाहिए Firewall → NAT → Destination NAT में, description “Redirect non-local DNS to Local” के साथ, या जो भी आप $NatDesc में रखें। वह बनाया नहीं जाता, और यह जाँचा नहीं जाता कि वह कैसे बना है।
    • Alias overwrite होता है Hagezi URL से। पुराने contents log में लिखे जाते हैं।
    • Test domain जो $AdTestDomain में है, आपके router की blocklist से block होना चाहिए, यानी उसका जवाब 0.0.0.0 या बिना किसी पते का हो, वरना redirect test fail होता है।
    • भरोसे का LAN। Script की certificate जाँच router के पते के लिए पेश किया गया कोई भी certificate मान लेती है, इसलिए LAN पर router होने का दिखावा करने वाले device को key मिल जाएगी। इसे सिर्फ़ ऐसे network पर चलाएँ जो आपके नियंत्रण में हो।
    • इंतज़ार जो $NatWaitSeconds में है, आपके router के UDP state timeouts से लंबा होना चाहिए।
    • Rollback दोनों rules और redirect rule को बंद कर देता है, भले ही redirect आपके पहली बार Apply चलाने से पहले चालू रहा हो। वह alias को restore नहीं करता।
    1. PowerShell खोलें और एक folder बनाएँ। Start menu खोलें, powershell type करें और Enter दबाएँ। Windows PowerShell नाम की एक window खुलती है, और उसका prompt PS से शुरू होता है। अगर prompt में PS नहीं है, तो आप Command Prompt में हैं: उसे बंद करें और उसकी जगह PowerShell खोलें, क्योंकि नीचे के commands सिर्फ़ PowerShell में चलते हैं। Window के अंदर click करें। नीचे की दो lines एक-एक करके इस्तेमाल करें: एक line copy करने के लिए PS> पर click करें, उसे paste करें (Ctrl + V, या right-click), और Enter दबाएँ।

      New-Item -ItemType Directory -Path "$env:USERPROFILE\opnsense-dns"
      Set-Location "$env:USERPROFILE\opnsense-dns"

      पहली line आपके user folder के अंदर opnsense-dns नाम का folder बनाती है और एक छोटी listing print करती है; दूसरी PowerShell को उसके अंदर ले जाती है, और तब prompt opnsense-dns> पर ख़त्म होता है। हर एक एक सेकंड से कम लेती है। अगर पहली line कहे कि folder पहले से है, तो आगे बढ़ें। यह window खुली रखें, और folder को OneDrive, Dropbox और shared जगहों से बाहर रखें: यहाँ save होने वाले backups में router की पूरी configuration होती है।

    2. Script save करें। इस page के आख़िर में The script, the mock router and the test harness तक scroll करें, opnsense-dns-bypass.ps1 (version 2.5.1) खोलें, उसे पढ़ें, और Copy पर click करें। वह 491 lines की है। वह आपके router की key इस्तेमाल करेगी, इसलिए चलाने से पहले उसे पढ़ें। Browser से download की गई files पर Windows निशान लगाता है कि वे internet से आई हैं; नीचे के command से लिखी गई file पर ऐसा कोई निशान नहीं होता, इसलिए Unblock-File की ज़रूरत नहीं है। Command इस folder में उसी नाम की file को replace कर देता है। PowerShell की window में:

      Get-Clipboard -Raw | Set-Content -Encoding Ascii .\opnsense-dns-bypass.ps1

      Get-Clipboard वह पढ़ता है जो आपने copy किया और Set-Content उसे file में लिखता है; script सादी ASCII है, इसलिए वह encoding सुरक्षित है। यह एक सेकंड से कम लेता है और कुछ print नहीं करता। जाँचें कि सब कुछ पहुँच गया:

      (Get-Content .\opnsense-dns-bypass.ps1).Count
      491

      अलग संख्या का मतलब हो सकता है कि copy बीच में कट गई या बदल गई। Page पर वापस जाएँ, दोबारा Copy पर click करें और पहला command दोहराएँ।

    3. Router पर एक API key बनाएँ। Web browser में https:// type करें और वह पता जो आप router के settings page के लिए इस्तेमाल करते हैं (जैसे https://192.168.1.1), और Enter दबाएँ। Browser चेतावनी दे सकता है कि connection private नहीं है, क्योंकि router अपना certificate ख़ुद sign करता है। वह विकल्प चुनें जो उस पते तक जारी रखता है (Chrome में: Advanced, फिर Proceed)। अपने router के login से log in करें। फिर:

      1. बाईं ओर के menu में System पर click करें, फिर Access, फिर Users।
      2. जिस administrator के रूप में आप log in करते हैं, उसकी row के आख़िर में pencil (edit) icon पर click करें।
      3. User की settings में API keys वाला section ढूँढें (OPNsense के दस्तावेज़ उसे ApiKeys tab कहते हैं) और उसके grid में key बनाने वाले button का इस्तेमाल करें।
      4. Browser कुछ सेकंड के भीतर एक छोटी text file download करता है। उसमें एक key= line और एक secret= line होती है। दस्तावेज़ कहते हैं कि secret सिर्फ़ एक बार बनता है; file खो जाए तो नई key बनाएँ।

      Key उसी user की तरह काम करती है जिसकी वह है। मैंने root user की key इस्तेमाल की और बाद में उसे delete कर दिया; root key router का पूरा नियंत्रण देती है। सिर्फ़ firewall, NAT और backup pages तक सीमित user के पास कम अधिकार होगा, पर script router की पूरी configuration download करती है, इसलिए वह user भी उसमें के password hashes और private keys पढ़ सकता है। मैंने सीमित user आज़माया नहीं है। अगर आपका menu अलग दिखता है, तो local users पर OPNsense के दस्तावेज़ यही step बताते हैं। Key file को कहीं paste न करें: उसमें का secret router का नियंत्रण देता है।

    4. Key file को folder में रखें। PowerShell में वापस आकर, अपने Downloads folder की सबसे नई text files की list निकालें:

      Get-ChildItem "$env:USERPROFILE\Downloads" -Filter *.txt | Sort-Object LastWriteTime -Descending | Select-Object -First 3 Name, LastWriteTime
      Name                  LastWriteTime
      ----                  -------------
      example_apikey.txt    <date and time>

      अगर list ख़ाली है, तो आपके browser ने file कहीं और save की है: browser में Ctrl + J दबाकर देखें कि कहाँ। अब file को उस नाम से folder में ले जाएँ जो script उम्मीद करती है। <file-name> को, angle brackets समेत, list के नाम से बदलें:

      Move-Item -LiteralPath "$env:USERPROFILE\Downloads\<file-name>" -Destination .\apikey.txt

      यह एक सेकंड से कम लेता है और कुछ print नहीं करता। यह folder में पहले से मौजूद apikey.txt को overwrite नहीं करेगा; अगर वह इसी कारण मना करे, तो वहाँ पहले की कोई key file है। उस key को router पर हटाएँ (step 8 बताता है कहाँ), Remove-Item .\apikey.txt चलाएँ, और यह step दोहराएँ। अगर वह path के बारे में error बताए, तो हो सकता है path में अब भी <file-name> हो, या नाम list के नाम से अलग हो। अब जाँचें कि key file में उसकी दो lines हैं। यह हर = से पहले का सिर्फ़ शब्द print करता है, मान कभी नहीं:

      Get-Content .\apikey.txt | ForEach-Object { ($_ -split '=')[0] }
      key
      secret

      अगर आपको दूसरे शब्द दिखें, तो शायद यह key file नहीं है। नई key download करें (step 3)।

    5. Check चलाएँ। यह सिर्फ़ पढ़ता है। पहले PowerShell को अपने router का पता बताएँ। Line copy करने के लिए PS> पर click करें, उसे paste करें, और अभी Enter न दबाएँ। <router-ip-address> को, angle brackets समेत, step 3 के पते की संख्याओं से बदलें (जैसे 192.168.1.1), और https:// को वैसा ही रहने दें। Cursor को arrow keys से हिलाएँ, क्योंकि PowerShell में mouse click से cursor नहीं हिलता; Backspace मिटाता है। फिर Enter दबाएँ। अगर angle brackets अब भी वहाँ हैं तो script रुक जाती है।

      $RouterUrl = 'https://<router-ip-address>'

      यह पता सिर्फ़ इस window के लिए याद रखा जाता है। Window बंद करें तो इसे दोहराएँ।

      अब script चलाएँ। powershell -ExecutionPolicy Bypass -File एक नया Windows PowerShell 5.1 शुरू करता है जो file चलाता है। Command line पर दिया गया -ExecutionPolicy Bypass सिर्फ़ उसी एक run के लिए रहता है, और execution policies पर Microsoft के दस्तावेज़ कहते हैं कि वह store नहीं होता। यह किसी employer की लगाई Group Policy को override नहीं करता। -Mode के बिना script Check चलाती है।

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl

      यह 10 से 60 सेकंड लेता है और router पर कुछ नहीं बदलता। यह router की configuration का backup router-backups folder में, जो opnsense-dns के अंदर है, एक log logs में save करता है, और पाँच live tests चलाता है। ज़रूरी lines:

      HH:MM:SS  Router reports: OPNsense series 26.7, amd64
      HH:MM:SS  Backup (before) saved: C:\Users\<you>\opnsense-dns\router-backups\config-Check-before-<timestamp>.xml (NNN,NNN bytes)
      ...
      HH:MM:SS  Router resolves example.com            : True   (want True)
      HH:MM:SS  Router blocks the ad domain (blocklist) : True   (want True)
      HH:MM:SS  Bypass DoH  1.1.1.1:443 reachable       : True   (want False after Apply)
      HH:MM:SS  Bypass DoT  9.9.9.9:853 reachable       : True   (want False after Apply)
      HH:MM:SS  Bypass 8.8.8.8 gives real ad IPs        : True   (want False after Apply)
      HH:MM:SS  Check mode: nothing was changed on the router.
      HH:MM:SS  Log file: C:\Users\<you>\opnsense-dns\logs\run-Check-<timestamp>.log

      दोनों “want True” lines True होनी चाहिए। अगर “Router blocks the ad domain” False है, तो आपकी blocklist test domain को block नहीं करती और step 6 का redirect test fail होगा। Script के ऊपरी हिस्से में $AdTestDomain को ऐसे domain पर set करें जिसे आपकी blocklist block करती है, या blocklist चालू करें। अगर कोई पीली line Apply would stop: से शुरू होती है, तो वह किसी ग़ायब rule का नाम बताती है: redirect rule या LAN allow-all rule। Step 6 से पहले उसे router पर ठीक करें।

      अगर कुछ गड़बड़ हुई। Script एक लाल line print करती है (ज़्यादातर में शब्द STOP होता है) और router पर कुछ नहीं बदलती। Line क्या कहती है, और उसका मतलब क्या है:

      • Set -Router to your router’s address: इस step के पते में angle brackets अब भी हैं।
      • Missing an argument for parameter ‘Router’: शायद ऊपर की पते वाली line इस window में चलाई नहीं गई। उसे फिर चलाएँ।
      • -Router must start with https://: पता http:// से शुरू होता है। https:// इस्तेमाल करें।
      • STOP: Key file not found: apikey.txt opnsense-dns folder में नहीं है। Step 4 फिर करें।
      • STOP: Cannot reach the router API with this key: पता ग़लत है, key हटा दी गई थी, या PC router के network पर नहीं है। पते को browser में खोलकर जाँचें।
      • STOP: Script was built for OPNsense 26.7: आपका router दूसरी series पर है, और script के API paths 26.7 से पढ़े गए थे। यहीं रुक जाएँ।
      • PowerShell कहता है कि scripts चलाना बंद है: आपके PC की एक policy scripts को रोकती है, और command-line option उसे override नहीं कर सकता। यहीं रुक जाएँ।
    6. Apply चलाएँ। यह router को बदलता है। यह alias DoH_IPs को Hagezi list के पते से overwrite करता है (पुराने contents log में जाते हैं), दो reject rules जोड़ता है अगर वे न हों, और redirect rule को चालू करता है। आपके network के जो devices किसी DNS-over-HTTPS या DNS-over-TLS server से सीधे बात करते हैं, वे वह रास्ता खो देते हैं; यही मक़सद है। वही command चलाएँ, -Mode Apply जोड़कर:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl -Mode Apply

      यह लगभग दो मिनट लेता है, और चार तक, अगर alias को पहले अपनी list download करनी पड़े। एक line कहती है Waiting 70 s for older DNS states to expire before testing...; उसका इंतज़ार करें और window बंद न करें। आख़िरी lines ऐसी होनी चाहिए:

      HH:MM:SS  Bypass DoH  1.1.1.1:443 reachable       : False   (want False after Apply)
      HH:MM:SS  Bypass DoT  9.9.9.9:853 reachable       : False   (want False after Apply)
      HH:MM:SS  Bypass 8.8.8.8 gives real ad IPs        : False   (want False after Apply)
      HH:MM:SS  Backup (after) saved: C:\Users\<you>\opnsense-dns\router-backups\config-Apply-after-<timestamp>.xml (NNN,NNN bytes)
      HH:MM:SS  Apply finished. Expected: router tests True, all three bypass tests False.
      HH:MM:SS  Log file: C:\Users\<you>\opnsense-dns\logs\run-Apply-<timestamp>.log

      अगर कुछ गड़बड़ हुई। Apply did not complete; changes from this run were undone: कोई test fail हुआ, और script ने जो बदला था उसे बंद कर दिया। जो rules उसने जोड़े वे बंद हालत में रहते हैं। उसने नतीजे का backup save किया। कारण के लिए वह line पढ़ें जो Problem: से शुरू होती है। अगर कोई line UNDO STEP FAILED कहे, तो “before” backup को restore करें, जैसा step 8 बताता है। Apply PARTLY finished (पीले में): alias और दोनों rules लग चुके हैं और test हो चुके हैं, और redirect पास नहीं हुआ; line बताती है कि redirect चालू छोड़ा गया या बंद। Fix को बंद करने के लिए step 8 इस्तेमाल करें।

    7. जाँचें कि काम हुआ। Step 5 का Check command फिर चलाएँ:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl

      अब तीनों Bypass lines False दिखाती हैं और दोनों Router lines True। Router के web page में आप Firewall → Rules भी देख सकते हैं (interface selector में LAN चुनें), जहाँ दोनों rules Reject DoH to known resolvers (A) और Reject DoT/DoQ 853 from LAN (B) अब दिखते हैं, और Firewall → NAT → Destination NAT में, जहाँ Redirect non-local DNS to Local चालू है।

    8. इसे बंद करें, ज़रूरत हो तो restore करें, और key हटाएँ। Fix को बंद करने के लिए command को -Mode Rollback के साथ चलाएँ:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl -Mode Rollback

      यह एक मिनट से कम लेता है। यह दोनों rules और redirect को disable करता है और कुछ delete नहीं करता। Alias वैसा ही रहता है जैसा Apply ने छोड़ा। अगर redirect आपके शुरू करने से पहले चालू था, तो वह अब बंद है: उसे Firewall → NAT → Destination NAT में फिर चालू करें।

      पूरी configuration को Apply से पहले जैसी थी वैसी वापस लाने के लिए, router पर backup restore करें: System → Configuration → Backups पर जाएँ, config-Apply-before-<timestamp>.xml नाम की file चुनें, जो router-backups folder में है, और उसे restore करें। हर Apply run ऐसी एक file save करता है; सबसे पुरानी में आपके पहले Apply से पहले की configuration है। इससे router पर उसके बाद किया गया कोई भी दूसरा बदलाव भी undo हो जाता है।

      जब script का काम पूरा हो जाए, चाहे fix रखें या नहीं, key हटा दें। Router पर System → Access → Users पर जाएँ, उसी user पर pencil पर click करें, और API keys वाले section में key हटा दें (ApiKeys tab)। फिर key file को PC से delete करें:

      Remove-Item .\apikey.txt

      यह file को तुरंत delete कर देता है, recycle bin के बिना। जब आपको backups की ज़रूरत न रहे, तो router-backups folder भी delete करें: उसमें password hashes और private keys हैं।

    सुरक्षा संबंधी नोट। Script हर request के साथ key भेजती है। वह secret को print या log नहीं करती, और test kit अपने 30 cases में से हर एक में यह जाँचता है। उसकी certificate जाँच router के पते के लिए पेश किया गया कोई भी certificate मान लेती है, इसलिए LAN पर router होने का दिखावा करने वाले device को key मिल जाएगी। मैंने अपनी key 13 अक्टूबर 2026 को delete की, run के दो दिन बाद, और router की configuration का history इस deletion को दर्ज करता है।

    Backups router की पूरी configuration हैं: password hashes, और उसके certificates और VPN tunnels की private keys। उस folder को निजी रखें, और किसी forum post के साथ backup attach न करें।

    विस्तार से: script की दूसरी जाँचें
    • Backup, backup जैसा दिखना चाहिए। Download के बाद script जाँचती है कि file कम से कम 50,000 bytes की है और उसकी पहली तीन lines में <opnsense> है।
    • Fail हुआ save पकड़ा जाता है। validations वाला जवाब fail हुआ save गिना जाता है, जैसा router के अपने web pages में होता है; result का failed होना भी। Alias और redirect के बदलाव वापस पढ़े जाते हैं। Rule के बदलाव rules की मौजूदगी और क्रम से, और live connection tests से जाँचे जाते हैं।
    • Rule का क्रम। Rules A और B जोड़ने के बाद, अगर दोनों में से कोई “Default allow LAN to any rule” के बाद sort होता है तो script रुक जाती है, क्योंकि allow-all rule के नीचे का rule कभी match नहीं होगा।
    • Alias भरना चाहिए। यह alias को हर 5 सेकंड पर, 90 सेकंड तक poll करती है और जब तक उसमें कम से कम 500 पते न हों, रुक जाती है।
    • सामान्य browsing चलती रहनी चाहिए। Rules को ठीक घोषित करने से पहले, यह www.google.com:443 से एक connection खोलती है।
    • अधूरा नतीजा अधूरा ही बताया जाता है। अगर सिर्फ़ redirect वाला चरण fail होता है, तो run Apply PARTLY finished पर ख़त्म होता है, बताता है कि redirect को किस state में छोड़ा, और code 2 के साथ exit करता है।
    विस्तार से: ख़राब certificate सिर्फ़ router के पते के लिए मानना

    Router का web interface एक self-signed certificate इस्तेमाल करता है। PowerShell 7 में -SkipCertificateCheck है, जिसे script वहाँ इस्तेमाल करती है। Windows PowerShell 5.1 में ऐसा कोई switch नहीं है। एक आम workaround एक callback है जो पूरे session के लिए हर certificate मान लेता है। Script का callback fail हुई certificate जाँच को सिर्फ़ तब मानता है जब request का host router का पता हो:

    public static bool Check(object sender, X509Certificate c, X509Chain ch, SslPolicyErrors e) {
        if (e == SslPolicyErrors.None) return true;
        HttpWebRequest r = sender as HttpWebRequest;
        return r != null && r.RequestUri.Host == Host;
    }

    यह छूट को सीमित करता है। यह certificate को pin नहीं करता: उस पते के लिए पेश किया गया कोई भी certificate पास हो जाता है। Certificate का thumbprint जाँचने से यह कमी बंद हो जाएगी। Script 5.1 के लिए TLS 1.2 भी set करती है।

    विस्तार से: एक एहतियात, failure नहीं: Expect: 100-continue

    Check mode सिर्फ़ GET requests भेजता है। Apply POSTs भेजता है। Windows PowerShell 5.1 .NET Framework पर चलता है, जहाँ ServicePointManager.Expect100Continue default रूप से true होता है और body वाली POST requests में एक Expect: 100-continue header जोड़ता है (Microsoft के दस्तावेज़)। वर्ज़न 2.2 पहली request से पहले यह header बंद कर देता है:

    [Net.ServicePointManager]::Expect100Continue = $false

    मैंने test नहीं किया कि router का web server इस header पर आपत्ति करता या नहीं।

    विस्तार से: पूरा हुआ run, line दर line

    15:04 वाले run का log। Router का पता और उसके एक interface का नाम angle brackets में placeholders से बदले गए हैं; local folder और PowerShell का build number हटाए गए हैं, और bytes की गिनती के अंक तीन-तीन के समूहों में रखे गए हैं। शुरुआती tests blocklist से बचने के तीनों रास्ते खुले दिखाते हैं; आख़िरी tests उन्हें बंद दिखाते हैं, test किए गए तीन IPv4 पतों के लिए।

    15:04:49  Mode: Apply   Router: https://<router-ip-address>   PowerShell 5.1
    15:04:55  Router reports: OPNsense series 26.7, amd64
    15:04:55  Backup (before) saved: ...\config-Apply-before-20261011-150449.xml (404,269 bytes)
    15:04:56  Alias DoH_IPs: present, enabled=1, entries loaded=1434, content=[__<interface>_network | https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt]
    15:04:56  Rule A: present, enabled=0, sort_order=400000.0000100
    15:04:56  Rule B: present, enabled=0, sort_order=400000.0000200
    15:04:56  'Default allow LAN to any rule': sort_order=400000.1000023
    15:04:56  NAT 'Redirect non-local DNS to Local': disabled=1
    15:04:56  Router resolves example.com            : True   (want True)
    15:04:56  Router blocks the ad domain (blocklist) : True   (want True)
    15:04:56  Bypass DoH  1.1.1.1:443 reachable       : True   (want False after Apply)
    15:04:56  Bypass DoT  9.9.9.9:853 reachable       : True   (want False after Apply)
    15:04:56  Bypass 8.8.8.8 gives real ad IPs        : True   (want False after Apply)
    15:04:56  Alias DoH_IPs set to the URL only (was: __<interface>_network | https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt).
    15:04:58  Alias DoH_IPs holds 1434 addresses.
    15:04:58  Rule 'Reject DoH to known resolvers (A)' enabled.
    15:04:58  Rule 'Reject DoT/DoQ 853 from LAN (B)' enabled.
    15:04:58  Firewall rules applied. Verifying...
    15:05:08  Rules A and B verified: DoH and DoT refused, normal HTTPS works.
    15:05:08  NAT rule enabled and applied. Waiting 70 s for older DNS states to expire before testing...
    15:06:18  NAT redirect verified: queries to 8.8.8.8 are answered by your router.
    15:06:19  Alias DoH_IPs: present, enabled=1, entries loaded=1434, content=[https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt]
    15:06:19  Rule A: present, enabled=1, sort_order=400000.0000100
    15:06:19  Rule B: present, enabled=1, sort_order=400000.0000200
    15:06:19  'Default allow LAN to any rule': sort_order=400000.1000023
    15:06:19  NAT 'Redirect non-local DNS to Local': disabled=0
    15:06:23  Router resolves example.com            : True   (want True)
    15:06:23  Router blocks the ad domain (blocklist) : True   (want True)
    15:06:23  Bypass DoH  1.1.1.1:443 reachable       : False   (want False after Apply)
    15:06:23  Bypass DoT  9.9.9.9:853 reachable       : False   (want False after Apply)
    15:06:23  Bypass 8.8.8.8 gives real ad IPs        : False   (want False after Apply)
    15:06:23  Backup (after) saved: ...\config-Apply-after-20261011-150449.xml (404,254 bytes)
    15:06:23  Apply finished. Expected: router tests True, all three bypass tests False.

    Alias में एक entry थी जो मैंने जान-बूझकर नहीं डाली थी: router के एक interface का network, URL से पहले। Run ने बदलने से पहले पुराने contents print किए, इसलिए उन्हें log से वापस लाया जा सकता है।

    विस्तार से: test kit क्या जाँचता है, और क्या नहीं जाँच सकता

    Mock script के API paths का जवाब देता है, router की state memory में रखता है, हर call दर्ज करता है, और गड़बड़ करने के लिए set किया जा सकता है: ग़लत वर्ज़न, ख़राब API key, छोटा backup, बदलावों के बाद fail होने वाला backup, ग़लत type का alias, ख़ाली key वाला जवाब, ऐसा save जिसे router reject करे, ऐसा alias जो न भरे, allow-all rule के नीचे sort होने वाले rules, DoH का फिर भी पहुँच में होना, सामान्य HTTPS का टूटना, redirect rule या allow rule का न होना, ऐसा redirect जो असर न करे, और ऐसा redirect जो पहले से चालू था। यह उन states को भी दोहराता है जिनसे मेरा router गुज़रा: एक भटकी हुई entry वाला alias, वर्ज़न 2.3 के disable छोड़े गए दो rules, और सब कुछ पहले से लागू (applied)। इसका ख़ाली key वाला जवाब हाथ से लिखा गया है, router के get_item जवाब के आधार पर, और उस endpoint पर दिया जाता है जिसे script पढ़ती है।

    Harness script को हर case के लिए एक बार, अलग process के रूप में चलाता है, और exit code, log, backup files, mock को मिली हर call, और आख़िर में mock router की state जाँचता है। हर case में यह जाँचता है कि न secret और न encoded key output या log में दिखे, कि कुछ भी delete न हुआ हो, और कि log खुलने के बाद का कोई भी stop log में लिखा जाए।

    Harness script की एक copy को test करता है, ख़ुद script को नहीं। Copy में दोनों network tests internet की जगह mock से पूछते हैं, और हर इंतज़ार एक millisecond कर दिया जाता है; कोई भी case चलने से पहले harness जाँचता है कि इनमें से हर pattern उम्मीद जितनी बार match हुआ। Copy PC पर सादे HTTP से mock से बात करती है; script सादा HTTP सिर्फ़ PC पर ही मौजूद पते के लिए मानती है।

    तो kit ये चीज़ें test नहीं करता: certificate जाँच और TLS; असली network tests; failure 3, क्योंकि mock में कोई state table नहीं है और इंतज़ार छोटे कर दिए गए हैं; असली router के जवाब, हाथ से लिखे एक ख़ाली key वाले जवाब के सिवा; script का backup overwrite करने से मना करना; work folder का fallback, क्योंकि हर case एक folder का नाम देता है; या ऐसा undo step जो ख़ुद fail हो जाए।

    script में जान-बूझकर किए गए दस बिगाड़ और हर एक से fail हुए cases, पेज के आख़िर में kit के साथ दिए गए हैं।

    विस्तार से: OPNsense 26.7 API पर टिप्पणियाँ
    • Script का header दर्ज करता है कि हर configuration path उस दिन router के अपने web pages से लिया गया था: alias/search_item, alias/add_item, alias/set_item, alias/reconfigure, filter/search_rule, filter/add_rule, filter/set_rule, filter/apply, d_nat/search_rule, d_nat/set_rule, d_nat/apply, alias_util/list और core/backup/download/this। यह वर्ज़न के लिए core/firmware/info और पहुँच की जाँच के लिए core/firmware/status भी call करती है।
    • Search endpoints ?rowCount=-1&current=1 वाली GET का जवाब देते हैं और हर row लौटाते हैं, उन fields के साथ जो script को चाहिए।
    • alias/get_item ख़ाली नाम वाली keys के साथ option lists लौटाता है, जिन्हें PowerShell object properties में नहीं बदल सकता।
    • GET /api/core/backup/download/this पूरी configuration XML के रूप में लौटाता है।
    • POST bodies Content-Type: application/json के साथ JSON होती हैं। Rule के बदलाव मेल खाते apply के बाद असर करते हैं; alias के बदलाव reconfigure के बाद।
    शब्दावली
    • Windows PowerShell 5.1: वह PowerShell जो Windows के साथ आता है, .NET Framework पर बना। powershell से शुरू होता है।
    • PowerShell 7: नया PowerShell, अलग से install होता है, आधुनिक .NET पर बना। pwsh से शुरू होता है।
    • REST API: web पतों का एक set जिसे कोई program settings पढ़ने या बदलने के लिए call करता है; OPNsense के जवाब JSON में होते हैं।
    • JSON: structured data के लिए एक text format।
    • Mock: किसी असली system की जगह खड़ा किया गया नक़ली system, testing के लिए; यहाँ, एक छोटा web server जो router की तरह जवाब देता है।
    • Test harness: एक script जो किसी दूसरी script को कई तय स्थितियों में चलाती है और नतीजे जाँचती है।
    • API key: एक key और secret जो script को बिना password के router user की तरह काम करने देते हैं।
    • Alias (URL table): पतों की एक OPNsense list जिसे router एक web पते से download करता है और refresh करता है।
    • NAT redirect: एक rule जो match होने वाली traffic की मंज़िल बदलता है; यहाँ यह भटकी DNS queries को router पर भेजता है।
    • State table: firewall की वह list जिसमें उन connections का हिसाब रहता है जिन्हें वह पहले देख चुका है। किसी जाने-पहचाने connection के बाद के packets पहले packet के लिए लिए गए फ़ैसले के हिसाब से चलते हैं।
    • DoH, DoT: DNS over HTTPS (port 443) और DNS over TLS (port 853), किसी device के लिए router से पूछे बिना नामों का पता लगाने (DNS lookup) के दो तरीक़े।
    • Expect: 100-continue: एक HTTP header जो server से कहता है कि request की body भेजे जाने से पहले उसे मंज़ूरी दे।

    ప్రతి టెస్ట్‌లోనూ పాసైంది, తప్పు చోట

    చదవడానికి 10 నిమిషాలు · ఇంగ్లీష్ మూలం నుంచి అనువదించినది. Code, commands, సాంకేతిక పేర్లు ఇంగ్లీష్‌లోనే ఉన్నాయి.

    11 అక్టోబర్ 2026 మధ్యాహ్నం నా OPNsense router API మీద Windows PowerShell 5.1 నుంచి ఒక script నడిపాను. ఇది Windows తో పాటు వచ్చే PowerShell. script తన log లో ఒక్క లైన్ కూడా రాయకముందే ఆగిపోయింది. router కి script చేసే మొదటి call ఆ లైన్ తర్వాత వస్తుంది. కాబట్టి, నాకు తెలిసినంతవరకు, router వరకు ఏదీ చేరలేదు.

    అది వెర్షన్ 2.0. వెర్షన్ 2.4 పనిని 15:06 కి పూర్తి చేసింది, నేను వెర్షన్ 2.0 ని save చేసిన 37 నిమిషాల తర్వాత. ప్రతి వెర్షన్ ముందుగా Claude sandbox లో తన టెస్ట్‌లను పాసైంది. ఆ టెస్ట్‌లు తప్పు చోట నడిచాయి: నిజమైన router కి బదులు ఒక mock router మీద, Windows PowerShell 5.1 కి బదులు PowerShell 7 కింద. తర్వాత router మీద ఫెయిల్ అయిన మూడు వెర్షన్లనూ mock పాస్ చేసింది. వైఫల్యం 1 లో PowerShell తేడా పాత్ర పోషించిందో లేదో నాకు తెలియదు. వైఫల్యం 2 లో అది ఏ పాత్రా పోషించలేదు, తర్వాత నా test harness ని ఫెయిల్ చేసింది. మూడు రన్‌లు ఫెయిల్ అయ్యాయి, ఒక్కొక్కటి వేరే కారణంతో. వాటిలో ఏదీ ఏ మార్పునూ on లో వదిలిపెట్టలేదు.

    ఈ పని Claude తో కలిసి చేశాను. script పాటించాల్సిన rules నేను నిర్ణయించాను, API key సృష్టించాను, తర్వాత దాన్ని delete చేశాను, ప్రతి వెర్షన్‌నీ నా సొంత PC లో, నా సొంత router మీద నడిపాను. script, దాన్ని టెస్ట్ చేసిన mock router, ప్రతి fix Claude రాసింది. వాటిని PowerShell 7 కింద టెస్ట్ చేసింది. దాని sandbox లో ఉన్న PowerShell అదొక్కటే.

    script, ఒక mock router, ఒక test harness ఈ పేజీ చివర MIT licence కింద ఉన్నాయి. router తన DNS blocklist ని తప్పించుకునే మూడు సాధారణ మార్గాలను నిరాకరించేలా script చేస్తుంది: DNS over HTTPS, DNS over TLS లేదా QUIC, వేరే server కి పంపే plain DNS. ఈ పేజీ రన్‌లను, నేను ఏం మారుస్తానో నమోదు చేస్తుంది; చివర దగ్గర ఉన్న ఒక panel మీ సొంత router మీద script ని ఎలా నడపాలో step by step చెబుతుంది.

    command line కి కొత్తవారా? boxes ని ఎలా చదవాలి

    PS> అంటే: దీన్ని Windows లోని PowerShell లో టైప్ చేయండి (Start menu → powershell అని టైప్ చేయండి → Enter). PS> ని మాత్రం టైప్ చేయవద్దు.

    PS> తో మొదలయ్యే ప్రతి లైన్ ఒక command. ఆ PS> మీద click చేస్తే ఆ లైన్ మాత్రమే copy అవుతుంది; దాన్ని paste చేసి, Enter నొక్కి, అది పూర్తయ్యే వరకు ఆగి, ఆ తర్వాతే తర్వాతి దాన్ని చేయండి. పైన Copy button ఉన్న box లో ఒక command (లేదా ఒక file) ఉంటుంది, కాబట్టి దాన్ని పూర్తిగా copy చేయండి. చుక్కల గీతల (dashed) box మీరు తిరిగి చూడాల్సినదాన్ని, లేదా చదవాల్సిన code ని చూపుతుంది; దాన్ని టైప్ చేయరు.

    ఈ script ఏం చేస్తుంది

    ఈ script ఒక OPNsense 26.7 router మీద ఒక DNS fix ని అమలు చేస్తుంది. నా router blocklist, router ని అడిగే devices ని మాత్రమే filter చేస్తుంది; phones, browsers, కొన్ని devices వేరే servers ని అడుగుతాయి. ఈ fix లో నాలుగు objects ఉంటాయి:

    • DoH_IPs అనే alias. ఇది Hagezi project నిర్వహించే DNS-over-HTTPS server అడ్రసుల public జాబితాను download చేస్తుంది (ఆ రోజు అందులో 1,434 అడ్రసులు);
    • Rule A. ఆ అడ్రసులకు port 443 మీద వెళ్లే LAN traffic ని reject చేస్తుంది;
    • Rule B. ఏ అడ్రసుకైనా port 853 మీద వెళ్లే LAN traffic ని reject చేస్తుంది. DNS over TLS, DNS over QUIC ఈ port వాడతాయి;
    • ఒక NAT redirect. router ని దాటి వెళ్లే ఏ port 53 query నైనా తిరిగి router కే పంపుతుంది.

    నా router లో alias, redirect rule ముందే ఉన్నాయి; redirect off లో ఉంది. script alias ని శుభ్రం చేస్తుంది, రెండు rules లేకపోతే సృష్టిస్తుంది, redirect ని on చేస్తుంది. redirect rule ని అది సృష్టించదు. rules IPv4 ని, LAN interface ని మాత్రమే cover చేస్తాయి; పరిమితులు చివర దగ్గర ఉన్న step-by-step panel లో ఉన్నాయి.

    ఈ నాలుగు objects ని click చేసి పెట్టడం నాకు సాధ్యమే. అయినా script రాశాను, ఎందుకంటే ఈ మార్పు ఒక రూపంలో ఉండాలనుకున్నాను: ఏదీ మార్చకుండా చెక్ చేయగలిగేలా, మళ్లీ నడపగలిగేలా, ఒక్క command తో off చేయగలిగేలా.

    అది పాటించే rules

    1. మూడు modes. Check చదివి report ఇస్తుంది. Apply మార్పు చేస్తుంది. Rollback రెండు rules నీ redirect నీ off చేస్తుంది, దేన్నీ delete చేయదు. -Mode లేని command Check నడుపుతుంది.
    2. వెర్షన్ guard. script ముందుగా router ఏం నడుపుతోందో అడుగుతుంది. జవాబు 26.7 series కాకపోతే ఆగిపోతుంది.
    3. వెర్షన్ guard తర్వాత backup. ఏ configuration ని చదవడానికి గానీ మార్చడానికి గానీ ముందే, ప్రతి రన్ router పూర్తి configuration ని ఒక కొత్త file లోకి download చేస్తుంది. ఉన్న file ని overwrite చేయడానికి నిరాకరిస్తుంది.
    4. ప్రతి మార్పునూ టెస్ట్ చేయండి. ముందు alias, తర్వాత రెండు rules, తర్వాత redirect. వెర్షన్ 2.3 లో ఒక టెస్ట్ ఫెయిల్ అయితే ఆ రన్ చేసిన మార్పులన్నీ undo అయ్యేవి. వెర్షన్ 2.4 నుంచి, redirect ఒక్కటే ఫెయిల్ అయితే redirect ఒక్కటే off అవుతుంది; పాసైన rules అలాగే ఉంటాయి.
    5. script లో secret ఉండదు. API key వేరే file లో ఉంటుంది.

    ముప్పై ఏడు నిమిషాలు

    మొదలైన సమయం వెర్షన్ Mode ఏం జరిగింది router మీద మిగిలింది
    14:29 తర్వాత 2.0 log కాలేదు మొదటి log లైన్ కంటే ముందే ఆగింది ఏమీ లేదు
    14:43 2.1 Check read-only report, పూర్తైంది ఏమీ లేదు
    14:51 2.2 Apply ఏ save కంటే ముందే తన సొంత guard వల్ల ఆగింది ఏమీ లేదు
    14:56 2.3 Apply rules పనిచేశాయి; redirect టెస్ట్ ఫెయిల్; undo అయింది రెండు rules, disabled
    15:04 2.4 Apply 15:06 కి పూర్తైంది, ప్రతి టెస్ట్ పాసైంది fix

    వెర్షన్ 2.0 log రాయలేదు, కాబట్టి దాని సమయం నేను file ని save చేసిన నిమిషం. మిగతా సమయాలు script సొంత logs నుంచి.

    పనుల క్రమం నష్టాన్ని పరిమితం చేసింది. script వెర్షన్ చెక్ చేస్తుంది, backup తీసుకుంటుంది, రాసే ముందు చదువుతుంది. వైఫల్యం 1 router కి ఏ call కంటే ముందే ఆగింది. వైఫల్యం 2 ఏ save కంటే ముందే ఆగింది, వేరే సమస్య కోసం రాసిన guard వల్ల. వైఫల్యం 3 మార్పులు జరిగిన తర్వాత వచ్చింది; ఆ వెర్షన్ undo వాటిని off చేసింది.

    వైఫల్యం 1: నేను తప్పుగా గుర్తించిన కారణం

    వెర్షన్ 2.0 తన working folder ని ఒక parameter default నుంచి తీసుకుంది:

    [string]$WorkDir = $PSScriptRoot

    $PSScriptRoot అంటే script ఉన్న folder. script దాన్ని తన logs folder path కట్టడానికి వాడుతుంది. ఆ folder ని key చదవడానికి, router ని call చేయడానికి ముందే సృష్టిస్తుంది.

    వెర్షన్ 2.1 మూడు విషయాలు మార్చింది. folder ని script body లో లెక్కించింది. ఆ folder లేకపోతే ఆగింది. ఖాళీ DNS జవాబు సున్నాగా లెక్కకు వచ్చేలా రెండు counts ని wrap చేసింది. వీటిలో folder మార్పులు మాత్రమే మొదటి log లైన్ కంటే ముందు వస్తాయి. ఆ రోజు Windows PowerShell 5.1 $PSScriptRoot ని ఖాళీగా వదిలిందనే నిర్ధారణకు Claude, నేను వచ్చాం. ఈ post మొదటి drafts కూడా అదే చెప్పాయి.

    ఈ post కోసం తయారు చేసిన test kit దాన్ని చెక్ చేసింది, ఆ నిర్ధారణ తప్పు. నా PC లో, నేను script ని మొదలుపెట్టే విధంగానే -File తో మొదలుపెట్టిన Windows PowerShell 5.1, parameter default లో $PSScriptRoot లోకి folder ని పెట్టింది. PowerShell 7.4.6 కూడా అలాగే చేసింది. script ని మొదలుపెట్టే పద్ధతుల్లో కొన్నింటినే టెస్ట్ చేశాను, కాబట్టి కొన్ని పద్ధతుల్లో అది ఖాళీగా ఉండే అవకాశాన్ని కొట్టిపారేయలేను. ఆ మధ్యాహ్నం వెర్షన్ 2.0 ని ఎలా మొదలుపెట్టానో, అది చూపిన error ఏమిటో నేను record చేయలేదు, కాబట్టి దాన్ని ఏది ఆపిందో నాకు తెలియదు. ఆధారాలు సమర్థించేది ఇంతకంటే పరిమితమైనది: వెర్షన్ 2.0 తన మొదటి log లైన్ కంటే ముందే ఆగింది, కాబట్టి, ఆధారాలు చూపినంతవరకు, router కి ఏ call కంటే ముందే. ప్రచురించిన script లోని ఒక comment, Windows PowerShell 5.1 కింద ఆ folder ఖాళీగా ఉండవచ్చని చెబుతుంది. ఆ comment నా మొదటి నిర్ధారణనే పునరావృతం చేస్తుంది; టెస్ట్ చేసిన file ని నేను అలాగే వదిలేశాను.

    వెర్షన్ 2.1 లోని మార్పు అలాగే ఉంటుంది. దానికి ఖర్చు ఏమీ లేదు. script ని ఏ విధంగా మొదలుపెట్టినా అది పనిచేస్తుంది:

    if ([string]::IsNullOrWhiteSpace($WorkDir)) {
        if ($MyInvocation.MyCommand.Path) { $WorkDir = Split-Path -Parent $MyInvocation.MyCommand.Path }
        else { $WorkDir = (Get-Location).Path }
    }

    వెర్షన్ 2.1 యొక్క Check రన్ 14:43 కి పూర్తైంది.

    వైఫల్యం 2: router విచిత్రాలు లేని mock

    alias type చెక్ చేయడానికి వెర్షన్ 2.2 router alias/get_item endpoint ని call చేసింది. 14:51 నాటి run log:

    14:51:46  Problem: Existing alias DoH_IPs is type '', not urltable. Fix or delete it in the GUI, then rerun.
    14:51:46  Nothing to undo.
    ...
    14:51:47  STOP: Apply did not complete; changes from this run were undone.

    alias type ఖాళీ కాదు. router జవాబులో పేరు ఖాళీ string గా ఉన్న entries ఉన్నాయి ("":). JSON దీన్ని అనుమతిస్తుంది. ఖాళీ పేరుతో object property ని PowerShell తయారు చేయలేదు. ConvertFrom-Json గురించి Microsoft documentation ఇదే చెబుతుంది (PowerShell 7.4 reference), అలాంటి జవాబుల కోసం -AsHashtable switch ని సూచిస్తుంది. Windows PowerShell 5.1 లో ఆ switch లేదు. Invoke-RestMethod ఏ error నూ ఇవ్వలేదు. జవాబును plain text గా తిరిగి ఇచ్చింది, script ఆ text నుంచి type ని ఏమీ లేనిదిగా చదివింది.

    ఇది PowerShell వెర్షన్ల మధ్య తేడా కాదు. test kit script కి ఖాళీ key ఉన్న జవాబును ఇస్తుంది. PowerShell 7.4.6 కింద, నా PC లో Windows PowerShell 5.1 కింద కూడా, Invoke-RestMethod దాన్ని text గా, error లేకుండా తిరిగి ఇచ్చింది. వెర్షన్ 2.2 mock మీద పాసైంది, ఎందుకంటే mock జవాబులో ఖాళీ keys లేవు. router జవాబులో ఉన్నాయి.

    రన్‌ని ఆపిన guard వేరే సమస్య కోసం రాసినది: తప్పు type తో ముందే ఉన్న alias. ఖాళీ type urltable కాదు కాబట్టి అది ఈ రన్‌ని ఆపింది. అది లేకపోతే రన్ కొత్త URL ని save చేసి ఉండేది, తర్వాత undo లో alias లోకి ఖాళీ string రాసి ఉండేది.

    14:43 Check రన్ దీన్ని పట్టుకోలేదు. Check alias ని alias/search_item ద్వారా చదివింది. Apply మాత్రమే get_item ని call చేసింది.

    వెర్షన్ 2.3 రెండు మార్పులు చేస్తుంది. router search_item, search_rule endpoints ఇప్పటికే type నీ contents నీ ఇస్తాయి, వాటి జవాబులు parse అయ్యాయి. కాబట్టి script వాటి ద్వారా మాత్రమే చదువుతుంది. ఇంకా, ప్రతి API call ఇప్పుడు ఒకే helper ద్వారా వెళ్తుంది. parse చేయలేని జవాబును ఆ helper తిరస్కరిస్తుంది:

    $r = Invoke-RestMethod @p
    if ($r -is [string]) {
        $t = $r.TrimStart()
        if ($t.StartsWith('{') -or $t.StartsWith('[')) { throw "Router reply to $Path could not be read as JSON by this PowerShell; stopping." }
    }

    వైఫల్యం 3: మరీ త్వరగా టెస్ట్ చేసిన redirect

    వెర్షన్ 2.3 ఇంకా ముందుకు వెళ్లింది. alias ని శుభ్రం చేసింది, రెండు rules జోడించి టెస్ట్ చేసింది. తర్వాత NAT redirect ని on చేసి, ఐదు సెకన్ల తర్వాత దాన్ని టెస్ట్ చేసింది:

    14:57:16  Rules A and B verified: DoH and DoT refused, normal HTTPS works.
    14:57:17  NAT rule enabled and applied. Verifying...
    14:57:22  Problem: 8.8.8.8 still returns real ad addresses; the redirect is not taking effect.
    14:57:22  Undoing changes made in this run...

    టెస్ట్ 8.8.8.8 కి రెండు queries పంపుతుంది: ఒకటి example.com కోసం, ఒకటి ఒక ad domain కోసం. firewall log లో రెండింటిలో ఒకటి redirect అయినట్లు కనిపించింది. ad domain నిజమైన అడ్రసులతో తిరిగి వచ్చింది, కాబట్టి redirect కానిది అదే. redirect ని on చేయడానికి పదమూడు సెకన్ల ముందు, bypass తెరిచి ఉందని చూపడానికి script ప్రారంభ చెక్ అదే పేరును 8.8.8.8 కి పంపింది.

    నా దగ్గర రెండు వివరణలు ఉన్నాయి, రెండింటినీ నేను టెస్ట్ చేయలేదు. firewall తాను చూసిన ప్రతి connection కీ ఒక state entry ఉంచుకుంటుంది, redirect ని కొత్త connections కి మాత్రమే వర్తింపజేస్తుంది. ad domain కోసం రెండో query మొదటిదాని source port నుంచే నా PC ని వదిలి ఉంటే, అది పాత entry తో match అయి Google కి వెళ్లి ఉంటుంది. లేదా నా PC లో ఏదో ఒకటి మళ్లీ అడిగిన ప్రశ్నకు cache నుంచి జవాబిచ్చి ఉంటుంది; అప్పుడు query PC ని వదిలి వెళ్లనే లేదు.

    ఈ router లోని UDP state timeouts, Firewall → Diagnostics → Statistics నుంచి చదివినవి: udp.first, udp.multiple కి 60 సెకన్లు, udp.single కి 30 సెకన్లు. వెర్షన్ 2.4 టెస్ట్ చేసే ముందు 70 సెకన్లు ఆగుతుంది, టెస్ట్ పాసైంది:

    15:05:08  NAT rule enabled and applied. Waiting 70 s for older DNS states to expire before testing...
    15:06:18  NAT redirect verified: queries to 8.8.8.8 are answered by your router.

    ఈ ఆగే సమయం firewall state entries కంటే ఎక్కువ సేపు ఉంటుంది. PC లో గుర్తుంచుకున్న జవాబు కంటే కూడా ఎక్కువ సేపు ఉంటుందా అన్నది ఆ జవాబును ఎంత సేపు ఉంచుకుంటారనే దానిపై ఆధారపడుతుంది; అది నేను కొలవలేదు. కాబట్టి ఈ ఫలితం రెండు వివరణల మధ్య తేడాను చెప్పదు. ఇంతకు ముందు query చేయని పేరుతో, firewall state table తెరిచి పెట్టి చేసే టెస్ట్ తేడాను చెప్పగలదు.

    వెర్షన్ 2.3 లోని undo redirect ని off చేసింది, రెండు కొత్త rules ని disable చేసింది, alias contents ని పునరుద్ధరించింది. rules ని delete చేయలేదు, alias refresh interval ని ఒక రోజుగానే వదిలేసింది. undo తర్వాత తీసిన backup రన్ ముందు తీసినదాని కంటే 4,788 bytes పెద్దది. వెర్షన్ 2.4 మొదట ఆ రెండు rules ని కనుగొంది:

    15:04:56  Rule A: present, enabled=0, sort_order=400000.0000100
    15:04:56  Rule B: present, enabled=0, sort_order=400000.0000200

    కాబట్టి “undone” అంటే “on లో ఏదీ మిగల్లేదు” అని, “router ముందున్నట్లే ఉంది” అని కాదు. వెర్షన్ 2.4 కొత్త copies జోడించకుండా, ఉన్న రెండు rules నే on చేసింది, ఎందుకంటే అది rules ని సృష్టించే ముందు description తో వెతుకుతుంది.

    mock పట్టుకోనివి, రెండో రౌండ్ టెస్ట్‌లు

    నేను router మీద నడపక ముందే Claude ప్రతి వెర్షన్‌నీ తన mock మీద నడిపింది. ఆ session record ప్రకారం, undo ని చెక్ చేయడానికి ప్రతి వెర్షన్ ఒకసారి మామూలుగా, ఒకసారి బలవంతంగా కలిగించిన failure తో నడిచింది. వెర్షన్లు 2.0 నుంచి 2.3 వరకు mock మీద పాసయ్యాయి. router మీద, ఆ నాలుగింటిలో మూడు ఫెయిల్ అయ్యాయి. mock ఎప్పుడూ Windows PowerShell 5.1 కింద నడవలేదు, దాని జవాబుల్లో router జవాబుల్లోని ఖాళీ keys లేవు.

    ఈ పేజీ చివర ఉన్న script వెర్షన్ 2.5.1, 2.4 కాదు. publish చేసే ముందు Claude తో script ని మళ్లీ review చేయించాను. ఆ review కనుగొన్నవాటిని వెర్షన్ 2.5 సరిచేస్తుంది: router స్థితిని తప్పుగా వర్ణించగల messages, log లో రాయని stops, alias enabled flag ని పునరుద్ధరించని undo, redirect rule గానీ LAN allow-all rule గానీ లేని router మీద మొదలవగల runs. https:// తో మొదలుకాని router అడ్రసును కూడా అది తిరస్కరిస్తుంది, PC మీదే ఉన్న అడ్రసు తప్ప; test kit దాన్ని వాడుతుంది. నా router మీద నడిచింది వెర్షన్ 2.4. వెర్షన్ 2.5.1, వెర్షన్ 2.5 కి header comments లో మాత్రమే భిన్నంగా ఉంటుంది; అది mock మీద మాత్రమే నడిచింది.

    రెండో రౌండ్ టెస్ట్‌లు ఒక కొత్త mock ని వాడాయి. router తప్పుగా ప్రవర్తించగల విధంగానే అది తప్పుగా ప్రవర్తించేలా తయారైంది, ఖాళీ key ఉన్న జవాబుతో సహా. ఒక harness 30 cases లో ప్రతిదానికీ ఒకసారి script copy ని దానిపై నడిపింది. PowerShell 7.4.6 కింద 30 అన్నీ పాసయ్యాయి.

    నా PC లో Windows PowerShell 5.1 కింద మొదటి రన్‌లో రెండు cases ఫెయిల్ అయ్యాయి. script logs ప్రకారం script సరైన పనే చేసింది; harness చేయలేదు. ఒక PowerShell function ఒకే item ఉన్న list ని return చేస్తే, caller కి ఆ item నేరుగా వస్తుంది. PowerShell 7 ఆ item ని list లాగే count చేయడానికి, index చేయడానికి అనుమతిస్తుంది. ఈ రకమైన object కి Windows PowerShell 5.1 అనుమతించదు. harness PowerShell 7 కింద మాత్రమే నడిచింది. అది సరిచేశాక, publish చేసిన script వెర్షన్‌పై Windows PowerShell 5.1 కింద కూడా 30 cases అన్నీ పాసయ్యాయి.

    harness నే చెక్ చేయడానికి, Claude script ని పది రకాలుగా పాడుచేసింది, ఉదాహరణకు undo ని, JSON చెక్‌ని లేదా HTTPS చెక్‌ని తీసేయడం. ప్రతి పాడుచేత కనీసం ఒక case ని ఫెయిల్ చేసింది. ఆ చెక్ PowerShell 7.4.6 కింద, వెర్షన్ 2.5 మీద, harness యొక్క ఒక పాత వెర్షన్‌తో నడిచింది.

    తర్వాతి script కి నేను తీసుకెళ్లేవి

    1. script ని నడపబోయే PowerShell మీదే టెస్ట్ చేయండి, టెస్ట్‌లను కూడా అక్కడే నడపండి. నా harness PowerShell 7 కింద పాసైంది, 5.1 కింద మొదటి రన్‌లో ఫెయిల్ అయింది.
    2. mock జవాబులను నిజమైన జవాబుల నుంచి కట్టండి. router get_item నుంచి save చేసిన ఒక జవాబు ఉండి ఉంటే, router script ని చూడక ముందే వైఫల్యం 2 పట్టుబడేది.
    3. write mode చేసే ప్రతి read నీ read-only mode కూడా చేసేలా చూడండి. ఇక్కడ Check, Apply alias ని వేర్వేరు endpoints ద్వారా చదివాయి.
    4. object ఆశించినప్పుడు Invoke-RestMethod నుంచి string వస్తే దాన్ని failure గా చూడండి. అది ప్రతిసారీ error ఇవ్వదు.
    5. redirect ని on చేశాక, firewall state timeout కంటే ఎక్కువ సేపు ఆగండి. ఇంతకు ముందు query చేయని పేరుతో టెస్ట్ చేయండి.
    6. undo delete చేయకుండా disable చేస్తే, గత రన్ వదిలినవాటి కోసం తర్వాతి రన్ వెతికేలా చేయండి.
    7. టెస్ట్‌లు ఫెయిల్ కాగలవని చెక్ చేయడానికి script ని కావాలని పాడుచేయండి.
    8. API key ని script బయట ఉంచండి, పని అయ్యాక దాన్ని delete చేయండి. నేను root user key వాడాను. script కి కావాల్సిన privileges మాత్రమే ఉన్న user మంచిది; అది నేను ప్రయత్నించలేదు.
    మీ router మీద దశల వారీగా నడపండి

    మొదలుపెట్టే ముందు. మీకు ఇవి కావాలి:

    • router ఉన్న network లోనే ఉన్న ఒక Windows PC. మీరు రెండు చోట్ల type చేస్తారు: PC లో PowerShell, browser లో router web page;
    • OPNsense 26.7. ఇతర series లో script ఆగిపోతుంది, ఎందుకంటే దాని API paths ఆ series సొంత pages నుంచి తీసుకున్నవి;
    • DNS blocklist on లో, Services → Unbound DNS → Blocklist కింద (OPNsense documentation ఆ page పేరు చెబుతుంది), మీ devices DNS కోసం router నే అడుగుతూ ఉండాలి;
    • port 53 మీద router కాకుండా ఇంకెక్కడికైనా వెళ్లే DNS queries ని తిరిగి router కే పంపే Destination NAT rule, ముందే సృష్టించినది, “Redirect non-local DNS to Local” అనే description తో. script దాన్ని on చేస్తుంది. సృష్టించదు. ఈ rule ని script సృష్టించదు, ఒకటి సృష్టించడం ఈ panel లో లేదు, అది లేకపోతే Apply ఆగిపోతుంది. OPNsense forum లోని ఒక community how-to ఒక పద్ధతి చూపిస్తుంది;
    • “Default allow LAN to any rule” అనే LAN rule, OPNsense దాన్ని default గా సృష్టిస్తుంది. దాని పైన తన రెండు కొత్త rules ఉన్నాయో లేదో script చెక్ చేస్తుంది.

    వెర్షన్ 2.5.1, ఈ panel లోని script, test kit లోని mock router మీద మాత్రమే నడిచింది. నా router మీద నడిచింది వెర్షన్ 2.4.

    సుమారు 20 నిమిషాలు కేటాయించండి; మార్పుకే సుమారు రెండు నిమిషాలు పడుతుంది. router కి చేసే మొదటి మార్పు 3వ దశలోని API key. 5వ దశలోని Check రన్ దానిపై ఏదీ మార్చదు. 6వ దశలోని Apply మారుస్తుంది. 8వ దశ fix ని off చేయడాన్ని, మొత్తం configuration ను ఎలా restore చేయాలో చూపిస్తుంది. ప్రతి రన్, configuration ను చదివే ముందు router configuration backup ను PC లో save చేస్తుంది.

    ఇప్పుడు పరిమితులు చదవండి. వాటిలో ఒకటి మీ network ని వర్ణిస్తే, script మీకు సరిపోదు, కాబట్టి ముందుకు వెళ్లకండి.

    పరిమితులు

    • IPv4 మాత్రమే. Rules A, B ను script IPv4 కోసమే సృష్టిస్తుంది, ప్రతి టెస్ట్ IPv4 అడ్రసు వాడుతుంది. మీ LAN లో IPv6 ఉంటే, IPv6 మీద DoH, DoT block కావు, టెస్ట్ కూడా కావు. (Interfaces → LAN లో IPv6 Configuration Type కనిపిస్తుంది; None అంటే IPv6 లేదు.)
    • LAN interface మాత్రమే. ఇతర interfaces, VLANs cover కావు.
    • LAN లో ప్రతి host. upstream కోసం DoH లేదా DoT వాడే LAN లోని Pi-hole లేదా AdGuard Home తన upstream ని కోల్పోతుంది. అది plain DNS ని ఒక public server కి పంపితే, మీ redirect rule ఎలా కట్టబడిందో దాన్ని బట్టి, ఆ rule దాన్ని కూడా పట్టుకోవచ్చు.
    • encrypted DNS నే కోరే devices. encrypted DNS provider ని మాత్రమే వాడేలా set చేసిన device, ఉదాహరణకు Private DNS ని ఒక hostname కి set చేసిన phone, rules దాని దారిని తిరస్కరించాక ఈ network లో పేర్లను వెతకలేకపోవచ్చు. ఆ setting ని device మీద మార్చండి.
    • redirect rule ముందే ఉండాలి Firewall → NAT → Destination NAT లో, “Redirect non-local DNS to Local” description తో, లేదా మీరు $NatDesc లో పెట్టిన దానితో. script దాన్ని సృష్టించదు, అది ఎలా కట్టబడిందో చెక్ చేయదు.
    • alias overwrite అవుతుంది Hagezi URL తో. పాత contents ను script log లో రాస్తుంది.
    • టెస్ట్ domain $AdTestDomain లోది. మీ router blocklist దాన్ని block చేసి, 0.0.0.0 గా లేదా అడ్రసు లేకుండా జవాబివ్వాలి; లేకపోతే redirect టెస్ట్ ఫెయిల్ అవుతుంది.
    • మీరు నమ్మే LAN. script certificate చెక్ router అడ్రసు కోసం చూపిన ఏ certificate నైనా అంగీకరిస్తుంది, కాబట్టి LAN లో router లా నటించే device కి key అందుతుంది. మీరు నియంత్రించే network లోనే నడపండి.
    • ఆగే సమయం $NatWaitSeconds లోది. ఇది మీ router UDP state timeouts కంటే ఎక్కువ ఉండాలి.
    • Rollback రెండు rules నీ redirect rule నీ off చేస్తుంది, మీరు మొదటిసారి Apply నడపక ముందే redirect on లో ఉన్నా. alias ని పునరుద్ధరించదు.
    1. PowerShell తెరిచి ఒక folder సృష్టించండి. Start menu తెరిచి, powershell అని type చేసి Enter నొక్కండి. Windows PowerShell అనే title తో ఒక window తెరుచుకుంటుంది, దాని prompt PS తో మొదలవుతుంది. prompt లో PS లేకపోతే మీరు Command Prompt లో ఉన్నారు: దాన్ని మూసి బదులుగా PowerShell తెరవండి, ఎందుకంటే కింది commands PowerShell లో మాత్రమే పనిచేస్తాయి. window లోపల click చేయండి. కింది రెండు లైన్లను ఒక్కొక్కటిగా వాడండి: లైన్‌ను copy చేయడానికి PS> మీద click చేయండి, paste చేయండి (Ctrl + V, లేదా right-click), Enter నొక్కండి.

      New-Item -ItemType Directory -Path "$env:USERPROFILE\opnsense-dns"
      Set-Location "$env:USERPROFILE\opnsense-dns"

      మొదటి లైన్ మీ user folder లోపల opnsense-dns అనే folder ను సృష్టించి, చిన్న listing ను print చేస్తుంది; రెండోది PowerShell ని అందులోకి తీసుకెళ్తుంది, తర్వాత prompt opnsense-dns> తో ముగుస్తుంది. ఒక్కొక్కటి ఒక సెకను కంటే తక్కువ పడుతుంది. మొదటి లైన్ folder ఉందని చెబితే, ముందుకు వెళ్లండి. ఈ window ని తెరిచి ఉంచండి, ఈ folder ని OneDrive, Dropbox, shared locations బయట ఉంచండి: ఇక్కడ save అయ్యే backups లో router మొత్తం configuration ఉంటుంది.

    2. script ని save చేయండి. ఈ page చివర ఉన్న The script, the mock router and the test harness దగ్గరికి scroll చేసి, opnsense-dns-bypass.ps1 (version 2.5.1) ను తెరిచి, చదివి, Copy మీద click చేయండి. అది 491 లైన్లు. ఇది మీ router key ని వాడుతుంది, కాబట్టి నడపక ముందు చదవండి. browser download చేసిన files ని Windows internet నుంచి వచ్చినవిగా గుర్తు పెడుతుంది; కింది command రాసిన file కి ఆ గుర్తు ఉండదు, కాబట్టి Unblock-File అవసరం లేదు. ఈ command ఈ folder లో అదే పేరున్న file ను భర్తీ చేస్తుంది. PowerShell window లో:

      Get-Clipboard -Raw | Set-Content -Encoding Ascii .\opnsense-dns-bypass.ps1

      Get-Clipboard మీరు copy చేసినదాన్ని చదువుతుంది, Set-Content దాన్ని ఒక file లో రాస్తుంది; script plain ASCII, కాబట్టి ఆ encoding సురక్షితం. ఇది ఒక సెకను కంటే తక్కువ పడుతుంది, ఏదీ print చేయదు. అంతా వచ్చిందో చెక్ చేయండి:

      (Get-Content .\opnsense-dns-bypass.ps1).Count
      491

      వేరే సంఖ్య వస్తే, copy మధ్యలోనే ఆగిపోయిందని లేదా మారిందని అనిపిస్తుంది. page కి తిరిగి వెళ్లి, Copy మీద మళ్లీ click చేసి, మొదటి command ను మళ్లీ నడపండి.

    3. router మీద API key సృష్టించండి. web browser లో https:// అని, మీరు router settings page కోసం వాడే అడ్రసును (ఉదాహరణకు https://192.168.1.1) type చేసి Enter నొక్కండి. router తన certificate ని తానే sign చేస్తుంది కాబట్టి, connection private కాదని browser హెచ్చరించవచ్చు. ఆ అడ్రసుకు కొనసాగించే ఎంపికను ఎంచుకోండి (Chrome లో: Advanced, తర్వాత Proceed). మీ సొంత router login తో log in అవండి. తర్వాత:

      1. ఎడమవైపు menu లో System మీద, తర్వాత Access మీద, తర్వాత Users మీద click చేయండి.
      2. మీరు log in అయ్యే administrator వరుస చివర ఉన్న పెన్సిల్ (edit) icon మీద click చేయండి.
      3. user settings లో API keys section ను కనుక్కోండి (OPNsense documentation దాన్ని ApiKeys tab అంటుంది), దాని grid లో key ను సృష్టించే button ను వాడండి.
      4. కొన్ని సెకన్లలో browser ఒక చిన్న text file ను download చేస్తుంది. అందులో key= లైన్, secret= లైన్ ఉంటాయి. secret ఒక్కసారి మాత్రమే generate అవుతుందని documentation చెబుతుంది; file పోతే కొత్త key సృష్టించండి.

      key తన user లాగే పనిచేస్తుంది. నేను root user key వాడి, తర్వాత దాన్ని delete చేశాను; root key router మీద పూర్తి నియంత్రణ ఇస్తుంది. firewall, NAT, backup pages కి మాత్రమే పరిమితమైన user కి తక్కువ అధికారం ఉంటుంది, కానీ script router మొత్తం configuration ను download చేస్తుంది, కాబట్టి ఆ user కూడా అందులోని password hashes, private keys ను చదవగలడు. పరిమిత user ను నేను ప్రయత్నించలేదు. మీ menu వేరేగా కనిపిస్తే, local users మీద OPNsense documentation అదే దశను వివరిస్తుంది. key file ను ఎక్కడా paste చేయకండి: అందులోని secret router మీద నియంత్రణ ఇస్తుంది.

    4. key file ను folder లో పెట్టండి. PowerShell కి తిరిగి వచ్చి, మీ Downloads folder లోని కొత్త text files జాబితా చూడండి:

      Get-ChildItem "$env:USERPROFILE\Downloads" -Filter *.txt | Sort-Object LastWriteTime -Descending | Select-Object -First 3 Name, LastWriteTime
      Name                  LastWriteTime
      ----                  -------------
      example_apikey.txt    <date and time>

      జాబితా ఖాళీగా ఉంటే, browser ఆ file ను వేరే చోట save చేసింది: ఎక్కడ save అయిందో చూడటానికి browser లో Ctrl + J నొక్కండి. ఇప్పుడు ఆ file ను script ఆశించే పేరుతో folder లోకి తరలించండి. <file-name> ను, angle brackets తో సహా, జాబితాలోని పేరుతో మార్చండి:

      Move-Item -LiteralPath "$env:USERPROFILE\Downloads\<file-name>" -Destination .\apikey.txt

      ఇది ఒక సెకను కంటే తక్కువ పడుతుంది, ఏదీ print చేయదు. folder లో ముందే ఉన్న apikey.txt ను ఇది overwrite చేయదు; ఆ కారణంతో నిరాకరిస్తే, ఇంతకు ముందటి key file అక్కడ ఉంది. ఆ key ను router మీద తీసేసి (ఆ key ఎక్కడ ఉందో 8వ దశ చూపిస్తుంది), Remove-Item .\apikey.txt నడిపి, ఈ దశను మళ్లీ చేయండి. path గురించి error వస్తే, path లో ఇంకా <file-name> ఉండి ఉండవచ్చు, లేదా పేరు జాబితాలోని పేరుతో సరిపోకపోవచ్చు. ఇప్పుడు key file లో రెండు లైన్లు ఉన్నాయో చెక్ చేయండి. ఇది ప్రతి = కి ముందున్న పదాన్ని మాత్రమే print చేస్తుంది, విలువలను ఎప్పుడూ కాదు:

      Get-Content .\apikey.txt | ForEach-Object { ($_ -split '=')[0] }
      key
      secret

      వేరే పదాలు కనిపిస్తే, ఇది బహుశా key file కాదు. కొత్త key ను download చేయండి (3వ దశ).

    5. Check నడపండి. ఇది చదువుతుంది మాత్రమే. ముందు PowerShell కి మీ router అడ్రసు చెప్పండి. లైన్‌ను copy చేయడానికి PS> మీద click చేసి, paste చేయండి, ఇంకా Enter నొక్కకండి. <router-ip-address> ను, angle brackets తో సహా, 3వ దశలోని అడ్రసు సంఖ్యలతో మార్చండి (ఉదాహరణకు 192.168.1.1), https:// ను అలాగే ఉంచండి. cursor ను arrow keys తో కదిలించండి, ఎందుకంటే PowerShell లో mouse click cursor ను కదిలించదు; Backspace తీసేస్తుంది. తర్వాత Enter నొక్కండి. angle brackets ఇంకా ఉంటే script ఆగిపోతుంది.

      $RouterUrl = 'https://<router-ip-address>'

      ఇది అడ్రసును ఈ window కి మాత్రమే గుర్తుంచుకుంటుంది. window ను మూసేస్తే, దీన్ని మళ్లీ చేయండి.

      ఇప్పుడు script ను నడపండి. powershell -ExecutionPolicy Bypass -File ఆ file ను నడిపే కొత్త Windows PowerShell 5.1 ను మొదలుపెడుతుంది. command line మీది -ExecutionPolicy Bypass ఆ ఒక్క రన్ కి మాత్రమే ఉంటుంది, execution policies మీద Microsoft documentation అది store కాదని చెబుతుంది. మీ సంస్థ set చేసిన Group Policy ని అది override చేయదు. -Mode లేకుండా script Check నడుపుతుంది.

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl

      ఇది 10 నుంచి 60 సెకన్లు పడుతుంది, router మీద ఏదీ మార్చదు. router configuration backup ను router-backups folder లో (అది opnsense-dns లోపల ఉంటుంది), log ను logs లో save చేసి, ఐదు live టెస్ట్‌లు నడుపుతుంది. ముఖ్యమైన లైన్లు:

      HH:MM:SS  Router reports: OPNsense series 26.7, amd64
      HH:MM:SS  Backup (before) saved: C:\Users\<you>\opnsense-dns\router-backups\config-Check-before-<timestamp>.xml (NNN,NNN bytes)
      ...
      HH:MM:SS  Router resolves example.com            : True   (want True)
      HH:MM:SS  Router blocks the ad domain (blocklist) : True   (want True)
      HH:MM:SS  Bypass DoH  1.1.1.1:443 reachable       : True   (want False after Apply)
      HH:MM:SS  Bypass DoT  9.9.9.9:853 reachable       : True   (want False after Apply)
      HH:MM:SS  Bypass 8.8.8.8 gives real ad IPs        : True   (want False after Apply)
      HH:MM:SS  Check mode: nothing was changed on the router.
      HH:MM:SS  Log file: C:\Users\<you>\opnsense-dns\logs\run-Check-<timestamp>.log

      రెండు “want True” లైన్లూ True అయి ఉండాలి. “Router blocks the ad domain” False అయితే, మీ blocklist టెస్ట్ domain ను block చేయడం లేదు, 6వ దశలోని redirect టెస్ట్ ఫెయిల్ అవుతుంది. script పైభాగంలోని $AdTestDomain ను మీ blocklist block చేసే domain కి set చేయండి, లేదా blocklist ను on చేయండి. పసుపు లైన్ Apply would stop: తో మొదలైతే, అది లేని rule ను చెబుతుంది: redirect rule లేదా LAN allow-all rule. 6వ దశకు ముందు router మీద దాన్ని సరిచేయండి.

      ఏదైనా తప్పు జరిగితే. script ఎరుపు లైన్ print చేస్తుంది (చాలావాటిలో STOP అనే పదం ఉంటుంది), router మీద ఏదీ మార్చదు. లైన్ ఏం చెబుతుంది, దాని అర్థం ఏమిటి:

      • Set -Router to your router’s address: ఈ దశలోని అడ్రసులో angle brackets ఇంకా ఉన్నాయి.
      • Missing an argument for parameter ‘Router’: బహుశా పై అడ్రసు లైన్‌ను ఈ window లో నడపలేదు. దాన్ని మళ్లీ నడపండి.
      • -Router must start with https://: అడ్రసు http:// తో మొదలవుతోంది. https:// వాడండి.
      • STOP: Key file not found: apikey.txt opnsense-dns folder లో లేదు. 4వ దశను మళ్లీ చేయండి.
      • STOP: Cannot reach the router API with this key: అడ్రసు తప్పు, key ను తీసేశారు, లేదా PC router network లో లేదు. చెక్ చేయడానికి browser లో అడ్రసును తెరవండి.
      • STOP: Script was built for OPNsense 26.7: మీ router వేరే series నడుపుతోంది, script API paths 26.7 నుంచి తీసుకున్నవి. ఇక్కడే ఆగండి.
      • scripts నడపడం disabled అని PowerShell చెబుతుంది: మీ PC లోని policy scripts ను block చేస్తోంది, command-line option దాన్ని override చేయలేదు. ఇక్కడే ఆగండి.
    6. Apply నడపండి. ఇది router ను మారుస్తుంది. ఇది DoH_IPs alias ను Hagezi list అడ్రసుతో overwrite చేస్తుంది (పాత contents log కి వెళ్తాయి), రెండు reject rules లేకపోతే జోడిస్తుంది, redirect rule ను on చేస్తుంది. DNS-over-HTTPS లేదా DNS-over-TLS server తో నేరుగా మాట్లాడే మీ network లోని devices ఆ దారిని కోల్పోతాయి; అదే ఉద్దేశం. అదే command ను -Mode Apply జోడించి నడపండి:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl -Mode Apply

      ఇది సుమారు రెండు నిమిషాలు పడుతుంది, alias ముందుగా తన list ను download చేయాల్సి వస్తే నాలుగు నిమిషాల వరకు. ఒక లైన్ Waiting 70 s for older DNS states to expire before testing... అని ఉంటుంది; దాని కోసం ఆగండి, window ను మూసేయకండి. చివరి లైన్లు ఇలా ఉండాలి:

      HH:MM:SS  Bypass DoH  1.1.1.1:443 reachable       : False   (want False after Apply)
      HH:MM:SS  Bypass DoT  9.9.9.9:853 reachable       : False   (want False after Apply)
      HH:MM:SS  Bypass 8.8.8.8 gives real ad IPs        : False   (want False after Apply)
      HH:MM:SS  Backup (after) saved: C:\Users\<you>\opnsense-dns\router-backups\config-Apply-after-<timestamp>.xml (NNN,NNN bytes)
      HH:MM:SS  Apply finished. Expected: router tests True, all three bypass tests False.
      HH:MM:SS  Log file: C:\Users\<you>\opnsense-dns\logs\run-Apply-<timestamp>.log

      ఏదైనా తప్పు జరిగితే. Apply did not complete; changes from this run were undone: ఒక టెస్ట్ ఫెయిల్ అయింది, script తాను మార్చినదాన్ని off చేసింది. అది జోడించిన rules off స్థితిలో అలాగే ఉంటాయి. ఫలితం యొక్క backup ను save చేసింది. కారణం కోసం Problem: తో మొదలయ్యే లైన్ చదవండి. ఏ లైన్ అయినా UNDO STEP FAILED అంటే, 8వ దశ వివరించినట్లు “before” backup ను restore చేయండి. Apply PARTLY finished (పసుపు రంగులో): alias, రెండు rules అమల్లో ఉన్నాయి, టెస్ట్ అయ్యాయి, redirect పాసవ్వలేదు; redirect ను on లో వదిలిందో off లో వదిలిందో లైన్ చెబుతుంది. fix ను off చేయడానికి 8వ దశ వాడండి.

    7. అది పనిచేసిందో చెక్ చేయండి. 5వ దశలోని Check command ను మళ్లీ నడపండి:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl

      ఇప్పుడు మూడు Bypass లైన్లు False, రెండు Router లైన్లు True అని చూపిస్తాయి. router web page లో Firewall → Rules (interface selector లో LAN ఎంచుకోండి) చూడవచ్చు; అక్కడ Reject DoH to known resolvers (A), Reject DoT/DoQ 853 from LAN (B) అనే రెండు rules ఇప్పుడు కనిపిస్తాయి. Firewall → NAT → Destination NAT లో Redirect non-local DNS to Local enabled గా ఉంటుంది.

    8. దాన్ని off చేయండి, అవసరమైతే restore చేయండి, key ను తీసేయండి. fix ను off చేయడానికి command ను -Mode Rollback తో నడపండి:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl -Mode Rollback

      ఇది ఒక నిమిషం కంటే తక్కువ పడుతుంది. రెండు rules నీ redirect నీ disable చేస్తుంది, దేన్నీ delete చేయదు. alias Apply వదిలినట్లే ఉంటుంది. మీరు మొదలుపెట్టే ముందే redirect on లో ఉంటే, ఇప్పుడు అది off: Firewall → NAT → Destination NAT లో దాన్ని మళ్లీ on చేయండి.

      మొత్తం configuration ను Apply కి ముందున్నట్లు తిరిగి పెట్టడానికి, router మీద backup ను restore చేయండి: System → Configuration → Backups కి వెళ్లి, config-Apply-before-<timestamp>.xml అనే file ను router-backups folder నుంచి ఎంచుకుని restore చేయండి. ప్రతి Apply రన్ ఇలాంటి ఒక file ను save చేస్తుంది; అన్నిటికంటే పాతది మీ మొదటి Apply కి ముందున్న configuration ను కలిగి ఉంటుంది. అది అప్పటి నుంచి router మీద చేసిన ఇతర మార్పులనూ undo చేస్తుంది.

      script తో పని అయ్యాక, fix ను ఉంచుకున్నా లేకపోయినా, key ను తీసేయండి. router మీద System → Access → Users కి వెళ్లి, అదే user మీద పెన్సిల్ click చేసి, API keys section లో key ను తీసేయండి (ApiKeys tab). తర్వాత key file ను PC నుంచి delete చేయండి:

      Remove-Item .\apikey.txt

      ఇది file ను వెంటనే delete చేస్తుంది, recycle bin ఉండదు. backups అవసరం లేనప్పుడు router-backups folder ను కూడా delete చేయండి: అందులో password hashes, private keys ఉన్నాయి.

    భద్రతా గమనికలు. script ప్రతి request తో key ను పంపుతుంది. secret ను print చేయదు, log చేయదు, test kit తన 30 cases లో ప్రతిదానిలో అది చెక్ చేస్తుంది. దాని certificate చెక్ router అడ్రసు కోసం చూపిన ఏ certificate నైనా అంగీకరిస్తుంది, కాబట్టి LAN లో router లా నటించే device కి key అందుతుంది. నా key ను 13 అక్టోబర్ 2026 న, రన్ తర్వాత రెండు రోజులకు delete చేశాను, router configuration history ఆ deletion ను record చేస్తుంది.

    backups అంటే router మొత్తం configuration: password hashes, దాని certificates, VPN tunnels private keys. ఆ folder ను private గా ఉంచండి, forum post కి backup ను attach చేయకండి.

    లోతుగా: script చేసే ఇతర చెక్‌లు
    • backup, backup లాగే కనిపించాలి. download చేశాక, file కనీసం 50,000 bytes ఉందో, మొదటి మూడు లైన్లలో <opnsense> ఉందో script చెక్ చేస్తుంది.
    • ఫెయిల్ అయిన save పట్టుబడుతుంది. validations ఉన్న జవాబు ఫెయిల్ అయిన save గా లెక్క, router సొంత web pages లో లాగే; result విలువ failed అయినా అంతే. alias, redirect మార్పులను తిరిగి చదువుతుంది. rule మార్పులను rules ఉనికి, క్రమం ద్వారా, live connection టెస్ట్‌ల ద్వారా చెక్ చేస్తుంది.
    • Rule క్రమం. Rules A, B జోడించాక, వాటిలో ఏదైనా “Default allow LAN to any rule” తర్వాత sort అయితే script ఆగుతుంది. ఎందుకంటే allow-all rule కింద ఉన్న rule ఎప్పుడూ match కాదు.
    • alias నిండాలి. ప్రతి 5 సెకన్లకు, 90 సెకన్ల వరకు alias ని poll చేస్తుంది. కనీసం 500 అడ్రసులు లేకపోతే ఆగుతుంది.
    • మామూలు browsing పనిచేస్తూనే ఉండాలి. rules బాగున్నాయని ప్రకటించే ముందు, www.google.com:443 కి ఒక connection తెరుస్తుంది.
    • పాక్షిక ఫలితం ఆ మాటే చెబుతుంది. redirect దశ ఒక్కటే ఫెయిల్ అయితే, రన్ Apply PARTLY finished తో ముగుస్తుంది, redirect ని ఏ స్థితిలో వదిలిందో చెబుతుంది, code 2 తో exit అవుతుంది.
    లోతుగా: router అడ్రసుకు మాత్రమే చెడ్డ certificate ని అంగీకరించడం

    router web interface ఒక self-signed certificate వాడుతుంది. PowerShell 7 లో -SkipCertificateCheck ఉంది; అక్కడ script దాన్ని వాడుతుంది. Windows PowerShell 5.1 లో అలాంటి switch లేదు. సాధారణంగా వాడే workaround, మొత్తం session కి ప్రతి certificate నీ అంగీకరించే callback. script callback, request host router అడ్రసు అయినప్పుడు మాత్రమే ఫెయిల్ అయిన certificate చెక్‌ని అంగీకరిస్తుంది:

    public static bool Check(object sender, X509Certificate c, X509Chain ch, SslPolicyErrors e) {
        if (e == SslPolicyErrors.None) return true;
        HttpWebRequest r = sender as HttpWebRequest;
        return r != null && r.RequestUri.Host == Host;
    }

    ఇది మినహాయింపును పరిమితం చేస్తుంది. certificate ని pin చేయదు: ఆ అడ్రసు కోసం చూపిన ఏ certificate అయినా పాసవుతుంది. certificate thumbprint ని చెక్ చేస్తే ఆ లోపం మూసుకుంటుంది. 5.1 కోసం script TLS 1.2 ని కూడా set చేస్తుంది.

    లోతుగా: వైఫల్యం కాదు, ముందు జాగ్రత్త: Expect: 100-continue

    Check mode GET requests మాత్రమే పంపుతుంది. Apply POSTs పంపుతుంది. Windows PowerShell 5.1 .NET Framework మీద నడుస్తుంది. అక్కడ ServicePointManager.Expect100Continue default గా true. body ఉన్న POST requests కి అది Expect: 100-continue header జోడిస్తుంది (Microsoft documentation). వెర్షన్ 2.2 మొదటి request కంటే ముందే ఆ header ని off చేస్తుంది:

    [Net.ServicePointManager]::Expect100Continue = $false

    router web server ఆ header కి అభ్యంతరం చెప్పి ఉండేదా అని నేను టెస్ట్ చేయలేదు.

    లోతుగా: పూర్తైన రన్, లైన్ వారీగా

    15:04 రన్ log. router అడ్రసు, దాని interfaces లో ఒకదాని పేరు స్థానంలో angle brackets లో placeholders పెట్టాను; local folder, PowerShell build number తీసేశాను, byte counts లోని అంకెలను మూడేసి చొప్పున group చేశాను. ప్రారంభ టెస్ట్‌లు blocklist ని దాటే మూడు దారులూ తెరిచి ఉన్నాయని చూపుతాయి. ముగింపు టెస్ట్‌లు, టెస్ట్ చేసిన మూడు IPv4 అడ్రసుల వరకు, అవి మూసుకున్నాయని చూపుతాయి.

    15:04:49  Mode: Apply   Router: https://<router-ip-address>   PowerShell 5.1
    15:04:55  Router reports: OPNsense series 26.7, amd64
    15:04:55  Backup (before) saved: ...\config-Apply-before-20261011-150449.xml (404,269 bytes)
    15:04:56  Alias DoH_IPs: present, enabled=1, entries loaded=1434, content=[__<interface>_network | https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt]
    15:04:56  Rule A: present, enabled=0, sort_order=400000.0000100
    15:04:56  Rule B: present, enabled=0, sort_order=400000.0000200
    15:04:56  'Default allow LAN to any rule': sort_order=400000.1000023
    15:04:56  NAT 'Redirect non-local DNS to Local': disabled=1
    15:04:56  Router resolves example.com            : True   (want True)
    15:04:56  Router blocks the ad domain (blocklist) : True   (want True)
    15:04:56  Bypass DoH  1.1.1.1:443 reachable       : True   (want False after Apply)
    15:04:56  Bypass DoT  9.9.9.9:853 reachable       : True   (want False after Apply)
    15:04:56  Bypass 8.8.8.8 gives real ad IPs        : True   (want False after Apply)
    15:04:56  Alias DoH_IPs set to the URL only (was: __<interface>_network | https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt).
    15:04:58  Alias DoH_IPs holds 1434 addresses.
    15:04:58  Rule 'Reject DoH to known resolvers (A)' enabled.
    15:04:58  Rule 'Reject DoT/DoQ 853 from LAN (B)' enabled.
    15:04:58  Firewall rules applied. Verifying...
    15:05:08  Rules A and B verified: DoH and DoT refused, normal HTTPS works.
    15:05:08  NAT rule enabled and applied. Waiting 70 s for older DNS states to expire before testing...
    15:06:18  NAT redirect verified: queries to 8.8.8.8 are answered by your router.
    15:06:19  Alias DoH_IPs: present, enabled=1, entries loaded=1434, content=[https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt]
    15:06:19  Rule A: present, enabled=1, sort_order=400000.0000100
    15:06:19  Rule B: present, enabled=1, sort_order=400000.0000200
    15:06:19  'Default allow LAN to any rule': sort_order=400000.1000023
    15:06:19  NAT 'Redirect non-local DNS to Local': disabled=0
    15:06:23  Router resolves example.com            : True   (want True)
    15:06:23  Router blocks the ad domain (blocklist) : True   (want True)
    15:06:23  Bypass DoH  1.1.1.1:443 reachable       : False   (want False after Apply)
    15:06:23  Bypass DoT  9.9.9.9:853 reachable       : False   (want False after Apply)
    15:06:23  Bypass 8.8.8.8 gives real ad IPs        : False   (want False after Apply)
    15:06:23  Backup (after) saved: ...\config-Apply-after-20261011-150449.xml (404,254 bytes)
    15:06:23  Apply finished. Expected: router tests True, all three bypass tests False.

    alias లో నేను కావాలని పెట్టని ఒక entry ఉంది: URL కంటే ముందు, router interfaces లో ఒకదాని network. రన్ పాత contents ని మార్చే ముందు print చేసింది, కాబట్టి వాటిని log నుంచి పునరుద్ధరించవచ్చు.

    లోతుగా: test kit ఏం చెక్ చేస్తుంది, ఏం చెక్ చేయలేదు

    mock script API paths కి జవాబిస్తుంది, router స్థితిని memory లో ఉంచుకుంటుంది, తనకు వచ్చిన ప్రతి call నీ record చేస్తుంది. దాన్ని తప్పుగా ప్రవర్తించేలా set చేయవచ్చు: తప్పు వెర్షన్, చెడ్డ API key, చిన్న backup, మార్పుల తర్వాత ఫెయిల్ అయ్యే backup, తప్పు type ఉన్న alias, ఖాళీ key ఉన్న జవాబు, router తిరస్కరించే save, నిండని alias, allow-all rule కింద sort అయ్యే rules, ఇంకా చేరగలిగే DoH, పాడైన మామూలు HTTPS, లేని redirect rule లేదా allow rule, ప్రభావం చూపని redirect, ముందే on లో ఉన్న redirect. నా router గడిచిన స్థితులను కూడా ఇది అనుకరిస్తుంది: అదనపు entry ఉన్న alias, వెర్షన్ 2.3 disable చేసి వదిలిన రెండు rules, అన్నీ ముందే apply అయిన స్థితి. ఖాళీ key ఉన్న దాని జవాబు router get_item జవాబు ఆధారంగా చేతితో రాసినది. script చదివే endpoint మీదే అది serve అవుతుంది.

    harness ప్రతి case కీ script ని ఒకసారి, వేరే process గా నడుపుతుంది. exit code, log, backup files, mock కి వచ్చిన ప్రతి call, చివర్లో mock router స్థితి చెక్ చేస్తుంది. ప్రతి case లో ఇవి చెక్ చేస్తుంది: secret గానీ encoded key గానీ output లో, log లో కనిపించలేదని; ఏదీ delete కాలేదని; log తెరిచిన తర్వాత జరిగే stop log లో రాయబడిందని.

    harness script నే కాదు, దాని copy ని టెస్ట్ చేస్తుంది. copy లో, రెండు network టెస్ట్‌లు internet ని కాకుండా mock ని అడుగుతాయి. ప్రతి ఆగే సమయాన్ని ఒక millisecond కి తగ్గిస్తారు. ఏ case నడవక ముందే, ఆ patterns లో ప్రతిదీ ఆశించిన సంఖ్యలో match అయిందని harness చెక్ చేస్తుంది. copy PC మీద plain HTTP ద్వారా mock తో మాట్లాడుతుంది; script plain HTTP ని PC మీదే ఉన్న అడ్రసుకు మాత్రమే అంగీకరిస్తుంది.

    కాబట్టి kit టెస్ట్ చేయనివి: certificate చెక్, TLS; నిజమైన network టెస్ట్‌లు; వైఫల్యం 3, ఎందుకంటే mock కి state table లేదు, ఆగే సమయాలు తగ్గించబడ్డాయి; నిజమైన router నుంచి జవాబులు, చేతితో రాసిన ఒక ఖాళీ-key జవాబు తప్ప; backup ని overwrite చేయడానికి script నిరాకరించడం; work folder fallback, ఎందుకంటే ప్రతి case ఒక folder పేరు ఇస్తుంది; లేదా తానే ఫెయిల్ అయ్యే undo దశ.

    కావాలని చేసిన పది పాడుచేతలు, ఒక్కొక్కటి ఫెయిల్ చేసిన cases, పేజీ చివర kit తో పాటు జాబితాగా ఉన్నాయి.

    లోతుగా: OPNsense 26.7 API గమనికలు
    • script header ప్రకారం, ప్రతి configuration path ఆ రోజు router సొంత web pages నుంచి తీసుకున్నది: alias/search_item, alias/add_item, alias/set_item, alias/reconfigure, filter/search_rule, filter/add_rule, filter/set_rule, filter/apply, d_nat/search_rule, d_nat/set_rule, d_nat/apply, alias_util/list, core/backup/download/this. వెర్షన్ కోసం core/firmware/info ని, reachability చెక్ గా core/firmware/status ని కూడా call చేస్తుంది.
    • search endpoints ?rowCount=-1&current=1 తో GET కి జవాబిస్తాయి. ప్రతి row నీ, script కి కావాల్సిన fields తో తిరిగి ఇస్తాయి.
    • alias/get_item ఖాళీ పేరున్న keys తో option lists ఇస్తుంది. వాటిని PowerShell object properties గా మార్చలేదు.
    • GET /api/core/backup/download/this పూర్తి configuration ని XML గా ఇస్తుంది.
    • POST bodies Content-Type: application/json తో JSON. Rule మార్పులు సరిపోయే apply తర్వాత అమల్లోకి వస్తాయి; alias మార్పులు reconfigure తర్వాత.
    పదకోశం
    • Windows PowerShell 5.1: Windows తో పాటు వచ్చే PowerShell, .NET Framework మీద కట్టినది. powershell గా మొదలవుతుంది.
    • PowerShell 7: కొత్త PowerShell, విడిగా install చేసేది, modern .NET మీద కట్టినది. pwsh గా మొదలవుతుంది.
    • REST API: settings చదవడానికి లేదా మార్చడానికి ఒక program call చేసే web అడ్రసుల సమితి; OPNsense జవాబులు JSON.
    • JSON: structured data కోసం ఒక text format.
    • Mock: టెస్టింగ్ కోసం నిజమైన system స్థానంలో వాడేది; ఇక్కడ, router లా జవాబిచ్చే ఒక చిన్న web server.
    • Test harness: మరొక script ని నిర్ణయించిన అనేక పరిస్థితుల్లో నడిపి ఫలితాలు చెక్ చేసే script.
    • API key: password లేకుండా ఒక script router user లా పనిచేయడానికి అనుమతించే key, secret.
    • Alias (URL table): router ఒక web అడ్రసు నుంచి download చేసి refresh చేసే అడ్రసుల OPNsense జాబితా.
    • NAT redirect: match అయిన traffic ఎక్కడికి వెళ్లాలో మార్చే rule; ఇక్కడ దారి తప్పిన DNS queries ని router కి పంపుతుంది.
    • State table: firewall ఇప్పటికే చూసిన connections జాబితా. తెలిసిన connection తర్వాతి packets మొదటిదానికి తీసుకున్న నిర్ణయాన్నే పాటిస్తాయి.
    • DoH, DoT: DNS over HTTPS (port 443), DNS over TLS (port 853). router ని అడగకుండా ఒక device పేర్లను వెతకడానికి రెండు దారులు.
    • Expect: 100-continue: request body పంపే ముందు దాన్ని ఆమోదించమని server ని అడిగే HTTP header.

    ผ่านทุกการทดสอบ ในที่ที่ผิด

    อ่าน 10 นาที · แปลจากต้นฉบับภาษาอังกฤษ; โค้ด คำสั่ง และชื่อทางเทคนิคคงไว้เป็นภาษาอังกฤษ

    บ่ายวันที่ 11 ตุลาคม 2026 ผมรัน script ตัวหนึ่งกับ API ของ router OPNsense ของผม จาก Windows PowerShell 5.1 ซึ่งเป็น PowerShell ที่มากับ Windows มันหยุดก่อนจะเขียน log ของตัวเองได้แม้แต่บรรทัดเดียว การเรียก router ครั้งแรกของ script อยู่หลังบรรทัดนั้น จึงเท่าที่ผมดูออก ไม่มีอะไรไปถึง router

    นั่นคือเวอร์ชัน 2.0 เวอร์ชัน 2.4 ทำงานเสร็จเมื่อ 15:06 คือ 37 นาทีหลังจากผมบันทึกเวอร์ชัน 2.0 ทุกเวอร์ชันผ่านการทดสอบใน sandbox ของ Claude ก่อน แต่การทดสอบเหล่านั้นทำในที่ที่ผิด คือรันกับ mock router แทน router ตัวจริง และรันบน PowerShell 7 แทน Windows PowerShell 5.1 เวอร์ชันทั้งสามที่ต่อมาล้มเหลวบน router ผ่านการทดสอบกับ mock ความต่างของ PowerShell มีส่วนในความล้มเหลวครั้งที่ 1 หรือไม่ ผมไม่รู้ ในครั้งที่ 2 ไม่มีส่วน และภายหลังมันทำให้ test harness ของผมพัง มีสามครั้งที่รันแล้วล้มเหลว แต่ละครั้งด้วยสาเหตุต่างกัน ไม่มีครั้งไหนทิ้งการเปลี่ยนแปลงที่เปิดใช้งานค้างไว้

    ผมทำงานนี้ร่วมกับ Claude ผมเป็นคนกำหนดกฎที่ script ต้องทำตาม สร้าง API key และลบมันทิ้งหลังเสร็จงาน และรันทุกเวอร์ชันบน PC ของผมเองกับ router ของผมเอง Claude เขียน script, mock router ที่ใช้ทดสอบ และการแก้ไขแต่ละครั้ง Claude ทดสอบทั้งหมดบน PowerShell 7 ซึ่งเป็น PowerShell ตัวเดียวที่ sandbox ของมันมี

    script, mock router และ test harness อยู่ท้ายหน้านี้ ภายใต้สัญญาอนุญาต MIT script นี้ทำให้ router ปฏิเสธสามวิธีทั่วไปที่ใช้เลี่ยง blocklist ของ DNS คือ DNS over HTTPS, DNS over TLS หรือ QUIC และ DNS ธรรมดาที่ส่งไปยัง server อื่น หน้านี้บันทึกการรันและสิ่งที่ผมจะเปลี่ยน และแผงใกล้ท้ายหน้าแสดงขั้นตอนการรัน script บน router ของคุณเอง ทีละขั้น

    ไม่คุ้นกับ command line? วิธีอ่านกล่องคำสั่ง

    PS> หมายถึง: พิมพ์คำสั่งนี้ใน PowerShell บน Windows (เมนู Start → พิมพ์ powershell → Enter) อย่าพิมพ์ PS> เอง

    แต่ละบรรทัดที่ขึ้นต้นด้วย PS> คือหนึ่งคำสั่ง คลิกที่ PS> เพื่อคัดลอกเฉพาะบรรทัดนั้น วางลงไป กด Enter และรอให้ทำงานเสร็จก่อนจะไปคำสั่งถัดไป กล่องที่มีปุ่ม Copy อยู่ด้านบนใส่หนึ่งคำสั่ง (หรือหนึ่งไฟล์) จึงให้คัดลอกทั้งกล่อง กล่องเส้นประแสดงสิ่งที่คุณควรเห็นตอบกลับมา หรือโค้ดไว้อ่าน คุณไม่ต้องพิมพ์

    สิ่งที่ script ทำ

    script นี้ใช้แก้ปัญหา DNS บน router OPNsense 26.7 blocklist ของ router ผมกรองได้เฉพาะอุปกรณ์ที่ถาม router ส่วนโทรศัพท์ เบราว์เซอร์ และอุปกรณ์บางตัวไปถาม server อื่น การแก้นี้เกี่ยวกับ object สี่ตัว:

    • alias ชื่อ DoH_IPs ที่ดาวน์โหลดรายการสาธารณะของ address ของ server DNS-over-HTTPS ซึ่งโปรเจกต์ Hagezi ดูแลไว้ (วันนั้นมี 1,434 รายการ);
    • Rule A ซึ่ง reject ทราฟฟิกจาก LAN ที่ไปยัง address เหล่านั้นบน port 443;
    • Rule B ซึ่ง reject ทราฟฟิกจาก LAN ที่ไปยัง address ใดก็ได้บน port 853 ซึ่ง DNS over TLS และ DNS over QUIC ใช้;
    • NAT redirect ที่ส่ง query ทุกตัวบน port 53 ที่ส่งไปยัง server อื่นโดยไม่ผ่าน router กลับมาที่ router

    บน router ของผม alias และ rule redirect มีอยู่แล้ว และ redirect ถูกปิดไว้ script จะทำความสะอาด alias สร้าง rule สองตัวถ้ายังไม่มี และเปิด redirect มันไม่สร้าง rule redirect rule เหล่านี้ครอบคลุมเฉพาะ IPv4 และ interface LAN ข้อจำกัดต่าง ๆ อยู่ในแผงขั้นตอนใกล้ท้ายหน้า

    ผมคลิกสร้าง object ทั้งสี่นี้เองก็ได้ แต่ผมเขียน script เพราะอยากได้การเปลี่ยนแปลงในรูปที่ตรวจสอบได้โดยไม่เปลี่ยนอะไร รันซ้ำได้ และปิดได้ด้วยคำสั่งเดียว

    กฎที่ script ต้องทำตาม

    1. สามโหมด Check อ่านและรายงาน Apply ทำการเปลี่ยนแปลง Rollback ปิด rule สองตัวและ redirect โดยไม่ลบอะไร คำสั่งที่ไม่ระบุ -Mode จะรัน Check
    2. ตรวจเวอร์ชัน script ถาม router ก่อนว่ารันอะไรอยู่ และหยุดถ้าคำตอบไม่ใช่ซีรีส์ 26.7
    3. backup เป็นลำดับถัดไป ก่อนจะอ่านหรือเปลี่ยน configuration ใด ๆ ทุกการรันจะดาวน์โหลด configuration ทั้งหมดของ router ลงไฟล์ใหม่ และไม่ยอมเขียนทับไฟล์ที่มีอยู่แล้ว
    4. ทดสอบทุกการเปลี่ยนแปลง alias ก่อน แล้วตามด้วย rule ทั้งสอง แล้วจึง redirect ในเวอร์ชัน 2.3 ถ้าการทดสอบล้มเหลว จะ undo ทุกอย่างที่การรันนั้นเปลี่ยนไป ตั้งแต่เวอร์ชัน 2.4 ถ้าล้มเหลวเฉพาะ redirect ก็จะปิดเฉพาะ redirect ส่วน rule ที่ผ่านแล้วยังอยู่
    5. ไม่มีความลับใน script API key เก็บอยู่ในไฟล์แยก

    สามสิบเจ็ดนาที

    เริ่ม เวอร์ชัน โหมด เกิดอะไรขึ้น สิ่งที่เหลืออยู่บน router
    หลัง 14:29 2.0 ไม่ได้บันทึกใน log หยุดก่อน log บรรทัดแรก ไม่มี
    14:43 2.1 Check รายงานแบบอ่านอย่างเดียว ครบถ้วน ไม่มี
    14:51 2.2 Apply หยุดเพราะ guard ของตัวเองก่อนการ save ใด ๆ ไม่มี
    14:56 2.3 Apply rule ใช้ได้; การทดสอบ redirect ล้มเหลว; undo แล้ว rule สองตัว ถูกปิดไว้
    15:04 2.4 Apply เสร็จเมื่อ 15:06 ผ่านทุกการทดสอบ การแก้ไขนี้

    เวอร์ชัน 2.0 ไม่ได้เขียน log เวลาของมันจึงเป็นนาทีที่ผมบันทึกไฟล์ เวลาอื่น ๆ มาจาก log ของ script เอง

    ลำดับการทำงานช่วยจำกัดความเสียหาย script ตรวจเวอร์ชัน ทำ backup และอ่านก่อนเขียน ความล้มเหลวครั้งที่ 1 หยุดก่อนเรียก router ใด ๆ ความล้มเหลวครั้งที่ 2 หยุดก่อนการ save ใด ๆ ด้วย guard ที่เขียนไว้สำหรับปัญหาอื่น ความล้มเหลวครั้งที่ 3 เกิดหลังจากมีการเปลี่ยนแปลงแล้ว และ undo ของเวอร์ชันนั้นปิดการเปลี่ยนแปลงเหล่านั้น

    ความล้มเหลวครั้งที่ 1: สาเหตุที่ผมเข้าใจผิด

    เวอร์ชัน 2.0 เอาโฟลเดอร์ทำงานมาจากค่า default ของ parameter:

    [string]$WorkDir = $PSScriptRoot

    $PSScriptRoot คือโฟลเดอร์ที่ script อยู่ script ใช้มันสร้าง path ของโฟลเดอร์ logs ซึ่ง script สร้างขึ้นก่อนจะอ่าน key หรือเรียก router

    เวอร์ชัน 2.1 เปลี่ยนสามอย่าง มันหาโฟลเดอร์ในตัว script เอง หยุดถ้าโฟลเดอร์นั้นไม่มีอยู่ และครอบการนับสองจุดไว้เพื่อให้คำตอบ DNS ที่ว่างเปล่านับเป็นศูนย์ มีเพียงการเปลี่ยนเรื่องโฟลเดอร์ที่อยู่ก่อน log บรรทัดแรก ในวันนั้น Claude กับผมสรุปว่า Windows PowerShell 5.1 ปล่อยให้ $PSScriptRoot ว่าง และร่างแรก ๆ ของโพสต์นี้ก็เขียนไว้อย่างนั้น

    ชุดทดสอบของโพสต์นี้ตรวจเรื่องนั้น และข้อสรุปนั้นผิด บน PC ของผม Windows PowerShell 5.1 ที่เริ่มด้วย -File แบบที่ผมเริ่ม script ใส่โฟลเดอร์ลงใน $PSScriptRoot ในค่า default ของ parameter เช่นเดียวกับ PowerShell 7.4.6 ผมไม่ได้ทดสอบทุกวิธีที่ใช้เริ่ม script จึงตัดความเป็นไปได้ไม่ได้ว่าบางวิธีทำให้มันว่าง ผมไม่ได้บันทึกว่าบ่ายวันนั้นผมเริ่มเวอร์ชัน 2.0 อย่างไร หรือ error ที่มันแสดง ผมจึงไม่รู้ว่าอะไรทำให้มันหยุด สิ่งที่หลักฐานรองรับแคบกว่านั้น: เวอร์ชัน 2.0 หยุดก่อน log บรรทัดแรก ดังนั้น เท่าที่หลักฐานแสดง จึงหยุดก่อนการเรียก router ใด ๆ คอมเมนต์ใน script ที่เผยแพร่บอกว่าโฟลเดอร์นี้อาจว่างบน Windows PowerShell 5.1 คอมเมนต์นั้นตรงกับข้อสรุปแรกของผม ผมปล่อยไฟล์ที่ผ่านการทดสอบแล้วไว้ตามเดิม

    การเปลี่ยนในเวอร์ชัน 2.1 ยังคงไว้ มันไม่มีต้นทุนอะไร และใช้ได้ไม่ว่าจะเริ่ม script ด้วยวิธีไหน:

    if ([string]::IsNullOrWhiteSpace($WorkDir)) {
        if ($MyInvocation.MyCommand.Path) { $WorkDir = Split-Path -Parent $MyInvocation.MyCommand.Path }
        else { $WorkDir = (Get-Location).Path }
    }

    การรัน Check ของเวอร์ชัน 2.1 เมื่อ 14:43 ทำงานจนจบ

    ความล้มเหลวครั้งที่ 2: mock ที่ไม่มีพฤติกรรมเฉพาะตัวของ router

    เพื่อตรวจชนิดของ alias เวอร์ชัน 2.2 เรียก endpoint alias/get_item ของ router log ของการรันเมื่อ 14:51:

    14:51:46  Problem: Existing alias DoH_IPs is type '', not urltable. Fix or delete it in the GUI, then rerun.
    14:51:46  Nothing to undo.
    ...
    14:51:47  STOP: Apply did not complete; changes from this run were undone.

    ชนิดของ alias ไม่ได้ว่าง คำตอบของ router มีรายการที่ชื่อเป็นสตริงว่าง ("":) JSON อนุญาตให้ทำเช่นนั้นได้ แต่ PowerShell สร้าง property ของ object ที่มีชื่อว่างไม่ได้ เอกสารของ Microsoft สำหรับ ConvertFrom-Json บอกไว้อย่างนั้น (เอกสารอ้างอิง PowerShell 7.4) และเสนอ switch -AsHashtable สำหรับคำตอบแบบนี้ Windows PowerShell 5.1 ไม่มี switch นั้น Invoke-RestMethod ไม่แจ้ง error ใด ๆ มันคืนคำตอบมาเป็นข้อความธรรมดา และ script อ่านชนิดจากข้อความนั้นออกมาเป็นค่าว่าง

    นี่ไม่ใช่ความต่างระหว่างเวอร์ชันของ PowerShell ชุดทดสอบป้อนคำตอบที่มี key ว่างให้ script บน PowerShell 7.4.6 และบน PC ของผมบน Windows PowerShell 5.1 Invoke-RestMethod คืนค่าเป็นข้อความโดยไม่มี error เวอร์ชัน 2.2 ผ่านการทดสอบกับ mock เพราะคำตอบของ mock ไม่มี key ว่าง แต่คำตอบของ router มี

    guard ที่หยุดการรันนี้เขียนไว้สำหรับปัญหาอื่น คือ alias ที่มีอยู่แล้วแต่เป็นชนิดผิด มันหยุดการรันนี้เพราะชนิดที่ว่างไม่ใช่ urltable ถ้าไม่มี guard นี้ การรันจะ save URL ใหม่ แล้วตอน undo ก็จะเขียนสตริงว่างลงใน alias

    การรัน Check เมื่อ 14:43 ไม่ได้จับปัญหานี้ Check อ่าน alias ผ่าน alias/search_item มีแค่ Apply ที่เรียก get_item

    เวอร์ชัน 2.3 เปลี่ยนสองอย่าง endpoint search_item และ search_rule ของ router คืนชนิดและเนื้อหาอยู่แล้ว และคำตอบของมัน parse ได้ script จึงอ่านผ่าน endpoint เหล่านี้เท่านั้น และทุกการเรียก API ตอนนี้ผ่าน helper ตัวเดียวที่ปฏิเสธคำตอบที่มัน parse ไม่ได้:

    $r = Invoke-RestMethod @p
    if ($r -is [string]) {
        $t = $r.TrimStart()
        if ($t.StartsWith('{') -or $t.StartsWith('[')) { throw "Router reply to $Path could not be read as JSON by this PowerShell; stopping." }
    }

    ความล้มเหลวครั้งที่ 3: redirect ที่ทดสอบเร็วเกินไป

    เวอร์ชัน 2.3 ไปได้ไกลกว่า มันทำความสะอาด alias เพิ่ม rule ทั้งสองและทดสอบ จากนั้นเปิด NAT redirect และทดสอบห้าวินาทีต่อมา:

    14:57:16  Rules A and B verified: DoH and DoT refused, normal HTTPS works.
    14:57:17  NAT rule enabled and applied. Verifying...
    14:57:22  Problem: 8.8.8.8 still returns real ad addresses; the redirect is not taking effect.
    14:57:22  Undoing changes made in this run...

    การทดสอบส่ง query สองตัวไปที่ 8.8.8.8: ตัวหนึ่งสำหรับ example.com และอีกตัวสำหรับโดเมนโฆษณา log ของ firewall แสดงว่ามีหนึ่งในสองตัวถูก redirect โดเมนโฆษณาได้ address จริงกลับมา ตัวที่ไม่ถูก redirect จึงเป็นตัวนั้น สิบสามวินาทีก่อนเปิด redirect การตรวจตอนเริ่มของ script ได้ส่งชื่อเดียวกันนั้นไปที่ 8.8.8.8 เพื่อแสดงว่าทางเลี่ยงยังเปิดอยู่

    ผมมีคำอธิบายสองแบบ และไม่ได้ทดสอบเลยสักแบบ firewall เก็บ state entry ไว้สำหรับแต่ละ connection ที่มันเคยเห็น และใช้ redirect กับ connection ใหม่เท่านั้น ถ้า query ครั้งที่สองของโดเมนโฆษณาออกจาก PC ของผมจาก source port เดียวกับครั้งแรก มันจะตรงกับ entry เดิมและออกไปถึง Google หรือมีบางอย่างบน PC ของผมตอบคำถามซ้ำนั้นจากแคช และ query ไม่เคยออกจาก PC เลย

    timeout ของ UDP state บน router นี้ ซึ่งอ่านจาก Firewall → Diagnostics → Statistics คือ 60 วินาทีสำหรับ udp.first และ udp.multiple และ 30 วินาทีสำหรับ udp.single เวอร์ชัน 2.4 รอ 70 วินาทีก่อนทดสอบ และการทดสอบผ่าน:

    15:05:08  NAT rule enabled and applied. Waiting 70 s for older DNS states to expire before testing...
    15:06:18  NAT redirect verified: queries to 8.8.8.8 are answered by your router.

    การรอนี้นานกว่า state entry ของ firewall แต่จะนานกว่าคำตอบที่ PC จำไว้หรือไม่ ขึ้นกับว่าคำตอบนั้นถูกเก็บไว้นานแค่ไหน ซึ่งผมไม่ได้วัด ผลลัพธ์นี้จึงแยกคำอธิบายทั้งสองแบบออกจากกันไม่ได้ การทดสอบด้วยชื่อที่ไม่เคย query มาก่อน โดยเปิด state table ของ firewall ดูไปด้วย จะแยกได้

    undo ในเวอร์ชัน 2.3 ปิด redirect ปิด rule ใหม่ทั้งสองตัว และคืนเนื้อหาของ alias มันไม่ได้ลบ rule และปล่อยให้ช่วงเวลา refresh ของ alias เป็นหนึ่งวัน backup ที่ทำหลัง undo ใหญ่กว่า backup ก่อนการรัน 4,788 ไบต์ เวอร์ชัน 2.4 เริ่มต้นด้วยการพบ rule ทั้งสองตัว:

    15:04:56  Rule A: present, enabled=0, sort_order=400000.0000100
    15:04:56  Rule B: present, enabled=0, sort_order=400000.0000200

    ดังนั้น “undo แล้ว” หมายถึง “ไม่มีอะไรเหลือที่เปิดใช้งานอยู่” ไม่ใช่ “router กลับเป็นเหมือนเดิม” เวอร์ชัน 2.4 เปิด rule สองตัวที่มีอยู่แล้วแทนที่จะเพิ่มสำเนาใหม่ เพราะมันค้นหา rule จากคำอธิบายก่อนจะสร้าง

    สิ่งที่ mock พลาด และการทดสอบรอบที่สอง

    Claude รันแต่ละเวอร์ชันกับ mock ก่อนที่ผมจะรันกับ router ตามบันทึกของ session นั้น แต่ละเวอร์ชันรันครั้งหนึ่งแบบปกติ และอีกครั้งแบบบังคับให้ล้มเหลว เพื่อตรวจ undo เวอร์ชัน 2.0 ถึง 2.3 ผ่านการทดสอบกับ mock แต่เมื่อรันกับ router สามในสี่เวอร์ชันล้มเหลว mock ไม่เคยรันบน Windows PowerShell 5.1 และคำตอบของมันไม่มี key ว่างแบบที่ router มี

    script ท้ายหน้านี้คือเวอร์ชัน 2.5.1 ไม่ใช่ 2.4 ก่อนเผยแพร่ ผมให้ Claude รีวิว script อีกครั้ง และเวอร์ชัน 2.5 แก้สิ่งที่รีวิวนั้นพบ: ข้อความที่อาจบรรยายสถานะของ router ผิด, การหยุดที่ไม่ได้เขียนลง log, undo ที่ไม่ได้คืนค่า enabled ของ alias และการรันที่อาจเริ่มได้บน router ที่ไม่มี rule redirect หรือ rule allow-all ของ LAN มันยังปฏิเสธ address ของ router ที่ไม่ได้ขึ้นต้นด้วย https:// ยกเว้น address บน PC เครื่องที่รัน script เอง ซึ่งชุดทดสอบใช้ เวอร์ชัน 2.4 คือตัวที่รันบน router ของผม เวอร์ชัน 2.5.1 ซึ่งต่างจาก 2.5 เฉพาะคอมเมนต์ส่วนหัว รันกับ mock เท่านั้น

    การทดสอบรอบที่สองใช้ mock ตัวใหม่ ที่สร้างให้ทำตัวผิดปกติแบบที่ router อาจทำได้ รวมถึงคำตอบที่มี key ว่าง harness รันสำเนาของ script กับ mock นี้ครั้งละหนึ่งกรณี รวม 30 กรณี บน PowerShell 7.4.6 ผ่านทั้ง 30 กรณี

    การรันครั้งแรกบน Windows PowerShell 5.1 บน PC ของผมล้มเหลวสองกรณี log ของ script แสดงว่า script ทำถูกแล้ว แต่ harness ทำไม่ถูก เมื่อ function ของ PowerShell คืน list ที่มีสมาชิกตัวเดียว ผู้เรียกจะได้ตัวสมาชิกนั้นเอง PowerShell 7 ให้นับและ index สมาชิกนั้นได้เหมือนเป็น list แต่ Windows PowerShell 5.1 ไม่ให้ สำหรับ object ชนิดนี้ harness เคยรันบน PowerShell 7 เท่านั้น เมื่อแก้ตรงนั้นแล้ว ทั้ง 30 กรณีผ่านบน Windows PowerShell 5.1 ด้วย กับ script เวอร์ชันที่เผยแพร่

    เพื่อตรวจ harness เอง Claude ทำให้ script พังสิบแบบ เช่น เอา undo, การตรวจ JSON หรือการตรวจ HTTPS ออก การทำพังแต่ละแบบทำให้อย่างน้อยหนึ่งกรณีล้มเหลว การตรวจนั้นรันบน PowerShell 7.4.6 กับเวอร์ชัน 2.5 โดยใช้ harness รุ่นก่อนหน้า

    สิ่งที่ผมจะนำไปใช้กับ script ตัวต่อไป

    1. ทดสอบบน PowerShell ที่จะใช้รัน script และรันการทดสอบบนตัวนั้นด้วย (harness ผ่านบน PowerShell 7 และล้มเหลวในการรันครั้งแรกบน 5.1)
    2. สร้างคำตอบของ mock จากคำตอบจริง คำตอบที่ save มาจาก get_item ของ router จะจับความล้มเหลวครั้งที่ 2 ได้ก่อนที่ router จะเห็น script
    3. ทำให้โหมดอ่านอย่างเดียวอ่านทุกอย่างที่โหมดเขียนจะอ่าน ในกรณีนี้ Check และ Apply อ่าน alias ผ่าน endpoint ต่างกัน
    4. ถือว่าสตริงจาก Invoke-RestMethod คือความล้มเหลว เมื่อคุณคาดว่าจะได้ object มันไม่ได้แจ้ง error เสมอไป
    5. หลังเปิด redirect ให้รอนานกว่า state timeout ของ firewall และทดสอบด้วยชื่อที่ยังไม่เคย query มาก่อน
    6. ถ้า undo ใช้วิธีปิดแทนการลบ ให้การรันครั้งถัดไปมองหาสิ่งที่ครั้งก่อนทิ้งไว้
    7. ทำให้ script พังโดยตั้งใจ เพื่อตรวจว่าการทดสอบล้มเหลวได้
    8. เก็บ API key ไว้นอก script และลบมันเมื่องานเสร็จ ผมใช้ key ของ user root การใช้ user ที่มีเฉพาะสิทธิ์ที่ script ต้องใช้จะดีกว่า ผมไม่ได้ลอง
    วิธีรันกับ router ของคุณเอง ทีละขั้น

    ก่อนเริ่ม คุณต้องมี:

    • PC Windows ที่อยู่ในเครือข่ายเดียวกับ router คุณพิมพ์ในสองที่ คือ PowerShell บน PC และหน้าเว็บของ router ในเบราว์เซอร์;
    • OPNsense 26.7 script จะหยุดถ้าเป็นซีรีส์อื่น เพราะ path ของ API อ่านมาจากหน้าเว็บของซีรีส์นั้นเอง;
    • DNS blocklist ที่เปิดอยู่ ใน Services → Unbound DNS → Blocklist (เอกสารของ OPNsense ระบุหน้านั้น) และอุปกรณ์ของคุณถาม router เรื่อง DNS;
    • rule Destination NAT ที่ส่ง query DNS (port 53) ซึ่งเล็งไปที่ใดก็ได้ที่ไม่ใช่ router กลับมาที่ router สร้างไว้แล้ว โดยมีคำอธิบาย “Redirect non-local DNS to Local” script เปิดมัน แต่ไม่ได้สร้าง script ไม่สร้าง rule นี้ แผงนี้ไม่ครอบคลุมการสร้าง rule นี้ และถ้าไม่มี Apply จะหยุด วิธีทำจากชุมชนในฟอรัม OPNsense แสดงวิธีหนึ่ง;
    • rule LAN ชื่อ “Default allow LAN to any rule” ซึ่ง OPNsense สร้างให้โดย default script ตรวจว่า rule ใหม่สองตัวของมันอยู่เหนือ rule นี้

    เวอร์ชัน 2.5.1 ซึ่งเป็น script ในแผงนี้ รันกับ mock router ในชุดทดสอบเท่านั้น เวอร์ชัน 2.4 คือตัวที่รันบน router ของผม

    ใช้เวลาราว 20 นาที ตัวการเปลี่ยนเองใช้ราวสองนาที การเปลี่ยนแปลงแรกบน router คือ API key ในขั้น 3 การรัน Check ในขั้น 5 ไม่เปลี่ยนอะไรบน router Apply ในขั้น 6 เปลี่ยนค่าบน router ขั้น 8 ปิดการแก้ไขและแสดงวิธีกู้คืน configuration ทั้งหมด ทุกการรันจะบันทึก backup ของ configuration ของ router ลงบน PC ก่อนอ่าน configuration

    อ่านข้อจำกัดต่อไป ถ้าข้อใดตรงกับเครือข่ายของคุณ script ไม่เหมาะกับเครือข่ายนั้น อย่าทำต่อ

    ข้อจำกัด

    • IPv4 เท่านั้น Rule A และ B สร้างสำหรับ IPv4 และทุกการทดสอบใช้ address IPv4 ถ้า LAN ของคุณมี IPv6 DoH และ DoT ผ่าน IPv6 จะไม่ถูกบล็อกและไม่ถูกทดสอบ (Interfaces → LAN แสดง IPv6 Configuration Type; None หมายถึงไม่มี IPv6)
    • interface LAN เท่านั้น interface อื่นและ VLAN ไม่ครอบคลุม
    • ทุก host ใน LAN Pi-hole หรือ AdGuard Home ใน LAN ที่ใช้ DoH หรือ DoT เป็น upstream จะเสีย upstream ไป ถ้ามันส่ง DNS ธรรมดาไปที่ server สาธารณะ rule redirect ของคุณอาจจับสิ่งนั้นด้วย ขึ้นกับว่า rule สร้างไว้อย่างไร
    • อุปกรณ์ที่บังคับใช้ DNS แบบเข้ารหัสเท่านั้น อุปกรณ์ที่ตั้งให้ใช้เฉพาะผู้ให้บริการ DNS แบบเข้ารหัส เช่น โทรศัพท์ที่ตั้ง Private DNS เป็น hostname อาจค้นหาชื่อบนเครือข่ายนี้ไม่ได้ เมื่อ rule ปฏิเสธเส้นทางของมัน ให้เปลี่ยนค่านั้นบนอุปกรณ์
    • rule redirect ต้องมีอยู่แล้ว ใน Firewall → NAT → Destination NAT โดยมีคำอธิบาย “Redirect non-local DNS to Local” หรือค่าที่คุณตั้งใน $NatDesc script ไม่ได้สร้างมัน และไม่ได้ตรวจว่ามันสร้างไว้อย่างไร
    • alias จะถูกเขียนทับ ด้วย URL ของ Hagezi เนื้อหาเดิมจะถูกเขียนลง log
    • โดเมนทดสอบ ใน $AdTestDomain ต้องถูก blocklist ของ router บล็อก โดยตอบเป็น 0.0.0.0 หรือไม่มี address ไม่เช่นนั้นการทดสอบ redirect จะล้มเหลว
    • LAN ที่คุณเชื่อถือ การตรวจ certificate ของ script ยอมรับ certificate ใดก็ได้ที่แสดงสำหรับ address ของ router ดังนั้นอุปกรณ์ใน LAN ที่ปลอมตัวเป็น router จะได้ key ไป รันเฉพาะบนเครือข่ายที่คุณควบคุม
    • เวลารอ ใน $NatWaitSeconds ควรนานกว่า UDP state timeout ของ router คุณ
    • Rollback ปิด rule สองตัวและ rule redirect แม้ว่า redirect จะเปิดอยู่ก่อนที่คุณจะรัน Apply ครั้งแรก มันไม่คืนค่า alias
    1. เปิด PowerShell และสร้างโฟลเดอร์ เปิดเมนู Start พิมพ์ powershell แล้วกด Enter หน้าต่างชื่อ Windows PowerShell จะเปิดขึ้น และ prompt ของมันขึ้นต้นด้วย PS ถ้า prompt ไม่มี PS แสดงว่าคุณอยู่ใน Command Prompt ให้ปิดแล้วเปิด PowerShell แทน เพราะคำสั่งด้านล่างใช้ได้เฉพาะใน PowerShell คลิกในหน้าต่าง ใช้สองบรรทัดด้านล่างทีละบรรทัด: คลิก PS> เพื่อคัดลอกบรรทัดนั้น วางมัน (Ctrl + V หรือคลิกขวา) แล้วกด Enter

      New-Item -ItemType Directory -Path "$env:USERPROFILE\opnsense-dns"
      Set-Location "$env:USERPROFILE\opnsense-dns"

      บรรทัดแรกสร้างโฟลเดอร์ชื่อ opnsense-dns ในโฟลเดอร์ผู้ใช้ของคุณและแสดงรายการสั้น ๆ; บรรทัดที่สองย้าย PowerShell เข้าไปในโฟลเดอร์นั้น และ prompt จะลงท้ายด้วย opnsense-dns> แต่ละบรรทัดใช้เวลาไม่ถึงหนึ่งวินาที ถ้าบรรทัดแรกบอกว่ามีโฟลเดอร์อยู่แล้ว ให้ทำต่อ เปิดหน้าต่างนี้ไว้ และเก็บโฟลเดอร์ให้อยู่นอก OneDrive, Dropbox และที่เก็บที่แชร์ร่วม: backup ที่บันทึกที่นี่มี configuration ทั้งหมดของ router

    2. บันทึก script เลื่อนไปที่ The script, the mock router and the test harness ท้ายหน้านี้ เปิด opnsense-dns-bypass.ps1 (version 2.5.1) อ่านมัน แล้วคลิก Copy มันยาว 491 บรรทัด มันจะใช้ key ของ router คุณ จึงอ่านก่อนรัน Windows ทำเครื่องหมายไฟล์ที่เบราว์เซอร์ดาวน์โหลดว่ามาจากอินเทอร์เน็ต ไฟล์ที่เขียนด้วยคำสั่งด้านล่างไม่มีเครื่องหมายนั้น จึงไม่ต้องใช้ Unblock-File คำสั่งนี้เขียนทับไฟล์ชื่อเดียวกันในโฟลเดอร์นี้ ในหน้าต่าง PowerShell:

      Get-Clipboard -Raw | Set-Content -Encoding Ascii .\opnsense-dns-bypass.ps1

      Get-Clipboard อ่านสิ่งที่คุณคัดลอก และ Set-Content เขียนลงไฟล์ ตัว script เป็น ASCII ล้วน encoding นี้จึงปลอดภัย ใช้เวลาไม่ถึงหนึ่งวินาทีและไม่พิมพ์อะไร ตรวจว่าทั้งหมดมาครบ:

      (Get-Content .\opnsense-dns-bypass.ps1).Count
      491

      ตัวเลขที่ต่างออกไปบ่งว่าการคัดลอกถูกตัดหรือถูกเปลี่ยน กลับไปที่หน้านั้น คลิก Copy อีกครั้ง แล้วทำคำสั่งแรกซ้ำ

    3. สร้าง API key บน router ในเว็บเบราว์เซอร์ พิมพ์ https:// ตามด้วย address ที่คุณใช้เปิดหน้า settings ของ router (เช่น https://192.168.1.1) แล้วกด Enter เบราว์เซอร์อาจเตือนว่าการเชื่อมต่อไม่เป็นส่วนตัว เพราะ router เซ็น certificate เอง เลือกตัวเลือกที่ไปต่อยัง address นั้น (ใน Chrome: Advanced แล้ว Proceed) ล็อกอินด้วย login ของคุณเองบน router จากนั้น:

      1. ในเมนูทางซ้าย คลิก System แล้ว Access แล้ว Users
      2. คลิกไอคอนดินสอ (edit) ที่ท้ายแถวของผู้ดูแลที่คุณล็อกอินเป็น
      3. หาส่วน API keys ในการตั้งค่าของ user (เอกสารของ OPNsense เรียกว่าแท็บ ApiKeys) และใช้ปุ่มในตารางของมันที่สร้าง key
      4. เบราว์เซอร์จะดาวน์โหลดไฟล์ข้อความขนาดเล็กภายในไม่กี่วินาที ไฟล์มีบรรทัด key= และบรรทัด secret= เอกสารบอกว่า secret ถูกสร้างเพียงครั้งเดียว ถ้าไฟล์หาย ให้สร้าง key ใหม่

      key ทำงานในฐานะ user ที่เป็นเจ้าของมัน ผมใช้ key ของ user root และลบทิ้งหลังจากนั้น key ของ root ให้สิทธิ์ควบคุม router เต็มที่ user ที่จำกัดเฉพาะหน้า firewall, NAT และ backup จะมีสิทธิ์น้อยกว่า แต่ script ดาวน์โหลด configuration ทั้งหมดของ router user นั้นจึงยังอ่าน hash ของรหัสผ่านและ private key ใน configuration ได้ ผมไม่ได้ลอง user ที่จำกัดสิทธิ์ ถ้าเมนูของคุณหน้าตาต่างออกไป เอกสารของ OPNsense เรื่อง local user อธิบายขั้นเดียวกัน อย่านำเนื้อหาในไฟล์ key ไปวางที่ใด: secret ในไฟล์ให้สิทธิ์ควบคุม router

    4. ใส่ไฟล์ key ในโฟลเดอร์ กลับมาที่ PowerShell แสดงรายการไฟล์ข้อความใหม่ล่าสุดในโฟลเดอร์ Downloads ของคุณ:

      Get-ChildItem "$env:USERPROFILE\Downloads" -Filter *.txt | Sort-Object LastWriteTime -Descending | Select-Object -First 3 Name, LastWriteTime
      Name                  LastWriteTime
      ----                  -------------
      example_apikey.txt    <date and time>

      ถ้ารายการว่าง เบราว์เซอร์บันทึกไฟล์ไว้ที่อื่น: กด Ctrl + J ในเบราว์เซอร์เพื่อดูว่าอยู่ที่ไหน ตอนนี้ย้ายไฟล์เข้าโฟลเดอร์ภายใต้ชื่อที่ script คาดไว้ แทน <file-name> รวมวงเล็บมุม ด้วยชื่อจากรายการ:

      Move-Item -LiteralPath "$env:USERPROFILE\Downloads\<file-name>" -Destination .\apikey.txt

      ใช้เวลาไม่ถึงหนึ่งวินาทีและไม่พิมพ์อะไร มันจะไม่เขียนทับ apikey.txt ที่มีอยู่แล้วในโฟลเดอร์ ถ้ามันปฏิเสธด้วยเหตุนั้น แสดงว่ามีไฟล์ key เก่าอยู่ที่นั่น ลบ key นั้นบน router (ขั้น 8 บอกว่าอยู่ที่ไหน) รัน Remove-Item .\apikey.txt และทำขั้นนี้ซ้ำ ถ้ามันรายงาน error เรื่อง path แสดงว่า path อาจยังมี <file-name> อยู่ หรือชื่ออาจไม่ตรงกับชื่อในรายการ ตอนนี้ตรวจว่าไฟล์ key มีสองบรรทัด คำสั่งนี้พิมพ์เฉพาะคำก่อนเครื่องหมาย = แต่ละตัว ไม่พิมพ์ค่า:

      Get-Content .\apikey.txt | ForEach-Object { ($_ -split '=')[0] }
      key
      secret

      ถ้าคุณเห็นคำอื่น ไฟล์นี้น่าจะไม่ใช่ไฟล์ key ดาวน์โหลด key ใหม่ (ขั้น 3)

    5. รัน Check — คำสั่งนี้อ่านอย่างเดียว ก่อนอื่นบอก PowerShell ว่า address ของ router คืออะไร คลิก PS> เพื่อคัดลอกบรรทัด วางมัน และอย่าเพิ่งกด Enter แทน <router-ip-address> รวมวงเล็บมุม ด้วยตัวเลขของ address จากขั้น 3 (เช่น 192.168.1.1) และปล่อย https:// ไว้ตามเดิม ขยับ cursor ด้วยปุ่มลูกศร เพราะการคลิกเมาส์ไม่ย้าย cursor ใน PowerShell; Backspace ลบตัวอักษร จากนั้นกด Enter ถ้ายังมีวงเล็บมุมอยู่ script จะหยุด

      $RouterUrl = 'https://<router-ip-address>'

      ค่านี้จำ address ไว้เฉพาะหน้าต่างนี้ ถ้าปิดหน้าต่าง ให้ทำซ้ำ

      ตอนนี้รัน script powershell -ExecutionPolicy Bypass -File เริ่ม Windows PowerShell 5.1 ตัวใหม่ที่รันไฟล์นั้น -ExecutionPolicy Bypass บน command line มีผลเฉพาะการรันครั้งนั้น และ เอกสารของ Microsoft เรื่อง execution policy บอกว่าค่านี้ไม่ถูกเก็บไว้ มันไม่ override Group Policy ที่นายจ้างตั้งไว้ ถ้าไม่มี -Mode script จะรัน Check

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl

      ใช้เวลา 10 ถึง 60 วินาทีและไม่เปลี่ยนอะไรบน router มันบันทึก backup ของ configuration ของ router ไว้ในโฟลเดอร์ router-backups ภายใน opnsense-dns บันทึก log ใน logs และรันการทดสอบจริงห้าตัว บรรทัดที่สำคัญ:

      HH:MM:SS  Router reports: OPNsense series 26.7, amd64
      HH:MM:SS  Backup (before) saved: C:\Users\<you>\opnsense-dns\router-backups\config-Check-before-<timestamp>.xml (NNN,NNN bytes)
      ...
      HH:MM:SS  Router resolves example.com            : True   (want True)
      HH:MM:SS  Router blocks the ad domain (blocklist) : True   (want True)
      HH:MM:SS  Bypass DoH  1.1.1.1:443 reachable       : True   (want False after Apply)
      HH:MM:SS  Bypass DoT  9.9.9.9:853 reachable       : True   (want False after Apply)
      HH:MM:SS  Bypass 8.8.8.8 gives real ad IPs        : True   (want False after Apply)
      HH:MM:SS  Check mode: nothing was changed on the router.
      HH:MM:SS  Log file: C:\Users\<you>\opnsense-dns\logs\run-Check-<timestamp>.log

      บรรทัด “want True” ทั้งสองต้องเป็น True ถ้า “Router blocks the ad domain” เป็น False แสดงว่า blocklist ของคุณไม่บล็อกโดเมนทดสอบ และการทดสอบ redirect ในขั้น 6 จะล้มเหลว ตั้ง $AdTestDomain ใกล้ต้น script เป็นโดเมนที่ blocklist ของคุณบล็อก หรือเปิด blocklist ถ้าบรรทัดสีเหลืองขึ้นต้นด้วย Apply would stop: มันระบุ rule ที่ขาด: rule redirect หรือ rule allow-all ของ LAN แก้บน router ก่อนขั้น 6

      ถ้าเกิดปัญหา script พิมพ์บรรทัดสีแดง (ส่วนใหญ่มีคำว่า STOP) และไม่เปลี่ยนอะไรบน router บรรทัดนั้นบอกอะไร และหมายความว่าอย่างไร:

      • Set -Router to your router’s address: วงเล็บมุมยังอยู่ใน address จากขั้นนี้
      • Missing an argument for parameter ‘Router’: น่าจะไม่ได้รันบรรทัด address ข้างบนในหน้าต่างนี้ รันอีกครั้ง
      • -Router must start with https://: address ขึ้นต้นด้วย http:// ใช้ https://
      • STOP: Key file not found: apikey.txt ไม่อยู่ในโฟลเดอร์ opnsense-dns ทำขั้น 4 ใหม่
      • STOP: Cannot reach the router API with this key: address ผิด key ถูกลบแล้ว หรือ PC ไม่ได้อยู่ในเครือข่ายของ router เปิด address ในเบราว์เซอร์เพื่อทดสอบ
      • STOP: Script was built for OPNsense 26.7: router ของคุณรันซีรีส์อื่น และ path API ของ script อ่านมาจาก 26.7 หยุดที่นี่
      • PowerShell บอกว่าการรัน script ถูกปิด: นโยบายบน PC ของคุณบล็อก script และตัวเลือกบน command line override ไม่ได้ หยุดที่นี่
    6. รัน Apply — คำสั่งนี้เปลี่ยนค่าบน router มันเขียนทับ alias DoH_IPs ด้วย address ของรายการ Hagezi (เนื้อหาเดิมไปอยู่ใน log) เพิ่ม rule reject สองตัวถ้ายังไม่มี และเปิด rule redirect อุปกรณ์ในเครือข่ายของคุณที่คุยกับ server DNS-over-HTTPS หรือ DNS-over-TLS โดยตรงจะเสียเส้นทางนั้น นั่นคือจุดประสงค์ รันคำสั่งเดิมโดยเพิ่ม -Mode Apply:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl -Mode Apply

      ใช้เวลาราวสองนาที และนานสุดสี่นาทีถ้า alias ต้องดาวน์โหลดรายการก่อน มีหนึ่งบรรทัดที่เขียนว่า Waiting 70 s for older DNS states to expire before testing...; รอมันและอย่าปิดหน้าต่าง บรรทัดสุดท้ายควรเป็น:

      HH:MM:SS  Bypass DoH  1.1.1.1:443 reachable       : False   (want False after Apply)
      HH:MM:SS  Bypass DoT  9.9.9.9:853 reachable       : False   (want False after Apply)
      HH:MM:SS  Bypass 8.8.8.8 gives real ad IPs        : False   (want False after Apply)
      HH:MM:SS  Backup (after) saved: C:\Users\<you>\opnsense-dns\router-backups\config-Apply-after-<timestamp>.xml (NNN,NNN bytes)
      HH:MM:SS  Apply finished. Expected: router tests True, all three bypass tests False.
      HH:MM:SS  Log file: C:\Users\<you>\opnsense-dns\logs\run-Apply-<timestamp>.log

      ถ้าเกิดปัญหา Apply did not complete; changes from this run were undone: การทดสอบล้มเหลว และ script ปิดสิ่งที่มันเปลี่ยน rule ที่มันเพิ่มยังอยู่ แต่ถูกปิดไว้ มันบันทึก backup ของผลลัพธ์ อ่านบรรทัดที่ขึ้นต้นด้วย Problem: เพื่อดูเหตุผล ถ้าบรรทัดใดมี UNDO STEP FAILED ให้กู้คืน backup “before” ตามที่ขั้น 8 อธิบาย Apply PARTLY finished (สีเหลือง): alias และ rule สองตัวอยู่ครบและผ่านการทดสอบ และ redirect ไม่ผ่าน บรรทัดนั้นบอกว่า redirect ถูกทิ้งไว้เปิดหรือปิด ถ้าต้องการปิดการแก้ไข ใช้ขั้น 8

    7. ตรวจว่าได้ผล รันคำสั่ง Check จากขั้น 5 อีกครั้ง:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl

      ตอนนี้สามบรรทัด Bypass เป็น False และสองบรรทัด Router เป็น True ในหน้าเว็บของ router คุณยังดู Firewall → Rules ได้ (เลือก LAN ในตัวเลือก interface) ซึ่ง rule สองตัว Reject DoH to known resolvers (A) และ Reject DoT/DoQ 853 from LAN (B) ปรากฏอยู่ และดู Firewall → NAT → Destination NAT ซึ่ง Redirect non-local DNS to Local เปิดใช้งานอยู่

    8. ปิดการแก้ไข กู้คืนถ้าจำเป็น และลบ key ถ้าต้องการปิดการแก้ไข รันคำสั่งโดยใช้ -Mode Rollback:

      powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router $RouterUrl -Mode Rollback

      ใช้เวลาไม่ถึงหนึ่งนาที มันปิด rule สองตัวและ redirect และไม่ลบอะไร alias ยังอยู่ตามที่ Apply ทิ้งไว้ ถ้า redirect เปิดอยู่ก่อนที่คุณเริ่ม ตอนนี้มันปิดอยู่: เปิดกลับใน Firewall → NAT → Destination NAT

      ถ้าต้องการคืน configuration ทั้งหมดให้เป็นเหมือนก่อน Apply ให้กู้คืน backup บน router: ไปที่ System → Configuration → Backups เลือกไฟล์ชื่อ config-Apply-before-<timestamp>.xml จากโฟลเดอร์ router-backups แล้วกู้คืน การรัน Apply แต่ละครั้งบันทึกไฟล์แบบนี้หนึ่งไฟล์ ไฟล์แรกสุดเก็บ configuration จากก่อน Apply ครั้งแรกของคุณ การกู้คืนนี้จะย้อนการเปลี่ยนแปลงอื่นทุกอย่างที่ทำบน router หลังจากนั้นด้วย

      เมื่อใช้ script เสร็จ ไม่ว่าจะเก็บการแก้ไขไว้หรือไม่ ให้ลบ key บน router ไปที่ System → Access → Users คลิกดินสอที่ user เดิม และลบ key ในส่วน API keys (แท็บ ApiKeys) จากนั้นลบไฟล์ key จาก PC:

      Remove-Item .\apikey.txt

      คำสั่งนี้ลบไฟล์ทันที ไม่ผ่านถังรีไซเคิล เมื่อไม่ต้องใช้ backup อีกแล้ว ให้ลบโฟลเดอร์ router-backups ด้วย: มี hash ของรหัสผ่านและ private key อยู่

    หมายเหตุด้านความปลอดภัย script ส่ง key ไปกับทุก request มันไม่พิมพ์หรือเขียน secret ลง log และชุดทดสอบตรวจเรื่องนั้นในทั้ง 30 กรณี การตรวจ certificate ของมันยอมรับ certificate ใดก็ได้ที่แสดงสำหรับ address ของ router ดังนั้นอุปกรณ์ใน LAN ที่ปลอมตัวเป็น router จะได้ key ไป ผมลบ key ของผมเมื่อ 13 ตุลาคม 2026 สองวันหลังการรัน และประวัติ configuration ของ router บันทึกการลบนั้นไว้

    backup คือ configuration ทั้งหมดของ router: hash ของรหัสผ่าน และ private key ของ certificate และ VPN tunnel ต่าง ๆ เก็บโฟลเดอร์นั้นไว้เป็นส่วนตัว และอย่าแนบ backup ไปกับโพสต์ในฟอรัม

    เจาะลึก: การตรวจอื่น ๆ ของ script
    • backup ต้องดูเหมือน backup หลังดาวน์โหลด script ตรวจว่าไฟล์มีขนาดอย่างน้อย 50,000 ไบต์ และมี <opnsense> ในสามบรรทัดแรก
    • การ save ที่ล้มเหลวจะถูกจับได้ คำตอบที่มี validations นับเป็นการ save ที่ล้มเหลว เหมือนที่หน้าเว็บของ router เองทำ result ที่เป็น failed ก็เช่นกัน การเปลี่ยน alias และ redirect จะถูกอ่านกลับมาตรวจ การเปลี่ยน rule ตรวจจากการมีอยู่และลำดับของ rule และจากการทดสอบ connection จริง
    • ลำดับ rule หลังเพิ่ม Rule A และ B script จะหยุดถ้า rule ตัวใดเรียงอยู่หลัง “Default allow LAN to any rule” เพราะ rule ที่อยู่ใต้ rule allow-all จะไม่มีวัน match
    • alias ต้องมีข้อมูลเข้ามา script ตรวจ alias ทุก 5 วินาที นานสูงสุด 90 วินาที และหยุดถ้า alias มี address ไม่ถึง 500 รายการ
    • การท่องเว็บปกติต้องยังใช้ได้ ก่อนจะสรุปว่า rule ใช้ได้ script เปิด connection ไปที่ www.google.com:443
    • ผลที่สำเร็จบางส่วนจะบอกว่าเป็นเช่นนั้น ถ้าล้มเหลวเฉพาะขั้น redirect การรันจะจบด้วย Apply PARTLY finished บอกว่าทิ้ง redirect ไว้ในสถานะใด และออกด้วย exit code 2
    เจาะลึก: ยอมรับ certificate ที่ไม่ผ่านการตรวจ เฉพาะ address ของ router

    หน้าเว็บของ router ใช้ certificate แบบ self-signed PowerShell 7 มี -SkipCertificateCheck ซึ่ง script ใช้ในกรณีนั้น Windows PowerShell 5.1 ไม่มี switch นี้ วิธีแก้ที่ใช้กันทั่วไปคือ callback ที่ยอมรับทุก certificate ตลอดทั้ง session callback ของ script ยอมรับการตรวจ certificate ที่ล้มเหลวเฉพาะเมื่อ host ของ request เป็น address ของ router:

    public static bool Check(object sender, X509Certificate c, X509Chain ch, SslPolicyErrors e) {
        if (e == SslPolicyErrors.None) return true;
        HttpWebRequest r = sender as HttpWebRequest;
        return r != null && r.RequestUri.Host == Host;
    }

    วิธีนี้ทำให้ข้อยกเว้นแคบลง แต่ไม่ได้ pin certificate: certificate ใดก็ตามที่แสดงสำหรับ address นั้นจะผ่าน การตรวจ thumbprint ของ certificate จะปิดช่องว่างนั้นได้ script ยังตั้ง TLS 1.2 สำหรับ 5.1 ด้วย

    เจาะลึก: มาตรการป้องกันไว้ก่อน ไม่ใช่ความล้มเหลว: Expect: 100-continue

    โหมด Check ส่งเฉพาะ request แบบ GET ส่วน Apply ส่ง POST Windows PowerShell 5.1 รันบน .NET Framework ซึ่ง ServicePointManager.Expect100Continue เป็น true โดย default และเพิ่ม header Expect: 100-continue ให้ request แบบ POST ที่มี body (เอกสารของ Microsoft) เวอร์ชัน 2.2 ปิด header นี้ก่อน request แรก:

    [Net.ServicePointManager]::Expect100Continue = $false

    ผมไม่ได้ทดสอบว่า web server ของ router จะมีปัญหากับ header นี้หรือไม่

    เจาะลึก: การรันที่สำเร็จ ทีละบรรทัด

    log ของการรันเมื่อ 15:04 address ของ router และชื่อของ interface หนึ่งของมันถูกแทนด้วย placeholder ในวงเล็บมุม โฟลเดอร์ในเครื่องและหมายเลข build ของ PowerShell ถูกตัดออก และตัวเลขในจำนวนไบต์ถูกจัดกลุ่มทีละสามหลัก การทดสอบตอนเริ่มแสดงว่าทางเลี่ยง blocklist ทั้งสามทางเปิดอยู่ การทดสอบตอนจบแสดงว่าทั้งสามทางปิดแล้ว สำหรับ address IPv4 สามตัวที่ทดสอบ

    15:04:49  Mode: Apply   Router: https://<router-ip-address>   PowerShell 5.1
    15:04:55  Router reports: OPNsense series 26.7, amd64
    15:04:55  Backup (before) saved: ...\config-Apply-before-20261011-150449.xml (404,269 bytes)
    15:04:56  Alias DoH_IPs: present, enabled=1, entries loaded=1434, content=[__<interface>_network | https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt]
    15:04:56  Rule A: present, enabled=0, sort_order=400000.0000100
    15:04:56  Rule B: present, enabled=0, sort_order=400000.0000200
    15:04:56  'Default allow LAN to any rule': sort_order=400000.1000023
    15:04:56  NAT 'Redirect non-local DNS to Local': disabled=1
    15:04:56  Router resolves example.com            : True   (want True)
    15:04:56  Router blocks the ad domain (blocklist) : True   (want True)
    15:04:56  Bypass DoH  1.1.1.1:443 reachable       : True   (want False after Apply)
    15:04:56  Bypass DoT  9.9.9.9:853 reachable       : True   (want False after Apply)
    15:04:56  Bypass 8.8.8.8 gives real ad IPs        : True   (want False after Apply)
    15:04:56  Alias DoH_IPs set to the URL only (was: __<interface>_network | https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt).
    15:04:58  Alias DoH_IPs holds 1434 addresses.
    15:04:58  Rule 'Reject DoH to known resolvers (A)' enabled.
    15:04:58  Rule 'Reject DoT/DoQ 853 from LAN (B)' enabled.
    15:04:58  Firewall rules applied. Verifying...
    15:05:08  Rules A and B verified: DoH and DoT refused, normal HTTPS works.
    15:05:08  NAT rule enabled and applied. Waiting 70 s for older DNS states to expire before testing...
    15:06:18  NAT redirect verified: queries to 8.8.8.8 are answered by your router.
    15:06:19  Alias DoH_IPs: present, enabled=1, entries loaded=1434, content=[https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt]
    15:06:19  Rule A: present, enabled=1, sort_order=400000.0000100
    15:06:19  Rule B: present, enabled=1, sort_order=400000.0000200
    15:06:19  'Default allow LAN to any rule': sort_order=400000.1000023
    15:06:19  NAT 'Redirect non-local DNS to Local': disabled=0
    15:06:23  Router resolves example.com            : True   (want True)
    15:06:23  Router blocks the ad domain (blocklist) : True   (want True)
    15:06:23  Bypass DoH  1.1.1.1:443 reachable       : False   (want False after Apply)
    15:06:23  Bypass DoT  9.9.9.9:853 reachable       : False   (want False after Apply)
    15:06:23  Bypass 8.8.8.8 gives real ad IPs        : False   (want False after Apply)
    15:06:23  Backup (after) saved: ...\config-Apply-after-20261011-150449.xml (404,254 bytes)
    15:06:23  Apply finished. Expected: router tests True, all three bypass tests False.

    alias มีรายการหนึ่งที่ผมไม่ได้ตั้งใจใส่ไว้: network ของ interface หนึ่งของ router อยู่ก่อน URL การรันพิมพ์เนื้อหาเดิมออกมาก่อนแทนที่ จึงคืนค่าได้จาก log

    เจาะลึก: ชุดทดสอบตรวจอะไร และตรวจอะไรไม่ได้

    mock ตอบ path API ที่ script ใช้ เก็บสถานะของ router ไว้ในหน่วยความจำ บันทึกทุกการเรียก และตั้งให้ทำตัวผิดปกติได้: เวอร์ชันผิด, API key ไม่ถูกต้อง, backup ขนาดเล็ก, backup ที่ล้มเหลวหลังมีการเปลี่ยนแปลง, alias ชนิดผิด, คำตอบที่มี key ว่าง, การ save ที่ router ปฏิเสธ, alias ที่ไม่มีข้อมูลเข้ามา, rule ที่เรียงอยู่ใต้ rule allow-all, DoH ที่ยังเข้าถึงได้, HTTPS ปกติใช้ไม่ได้, rule redirect หรือ rule allow-all ที่ไม่มีอยู่, redirect ที่ไม่มีผล และ redirect ที่เปิดอยู่แล้ว มันยังจำลองสถานะที่ router ของผมผ่านมา: alias ที่มีรายการแปลกปลอม, rule สองตัวที่เวอร์ชัน 2.3 ปิดทิ้งไว้ และสถานะที่ apply ทุกอย่างแล้ว คำตอบที่มี key ว่างของมันเขียนด้วยมือ ตามแบบคำตอบ get_item ของ router และตอบบน endpoint ที่ script อ่าน

    harness รัน script ครั้งละหนึ่งกรณี เป็น process แยก และตรวจ exit code, log, ไฟล์ backup, ทุกการเรียกที่ mock ได้รับ และสถานะของ mock router ตอนจบ ในทุกกรณี มันตรวจว่าทั้ง secret และ key ที่ encode แล้วไม่ปรากฏใน output หรือ log ว่าไม่มีอะไรถูกลบ และว่าการหยุดหลังเปิด log แล้วถูกเขียนลง log

    harness ทดสอบสำเนาของ script ไม่ใช่ตัว script เอง ในสำเนานั้น การทดสอบเครือข่ายสองตัวจะถาม mock แทนอินเทอร์เน็ต และทุกการรอถูกตัดเหลือหนึ่งมิลลิวินาที ก่อนรันกรณีใด ๆ harness ตรวจว่าแต่ละ pattern เหล่านั้น match ตามจำนวนครั้งที่คาดไว้ สำเนานั้นคุยกับ mock ผ่าน HTTP ธรรมดาบน PC ส่วน script ยอมรับ HTTP ธรรมดาเฉพาะ address บน PC เครื่องนั้นเองเท่านั้น

    ดังนั้นชุดทดสอบไม่ได้ทดสอบ: การตรวจ certificate และ TLS; การทดสอบเครือข่ายจริง; ความล้มเหลวครั้งที่ 3 เพราะ mock ไม่มี state table และการรอถูกตัดสั้น; คำตอบจาก router จริง ยกเว้นคำตอบ key ว่างที่เขียนด้วยมือหนึ่งตัว; การที่ script ไม่ยอมเขียนทับ backup; ทางสำรองสำหรับโฟลเดอร์ทำงาน เพราะทุกกรณีระบุโฟลเดอร์ไว้; หรือขั้น undo ที่ตัวมันเองล้มเหลว

    การทำพังโดยตั้งใจสิบแบบ และกรณีที่แต่ละแบบทำให้ล้มเหลว อยู่ในรายการพร้อมชุดทดสอบท้ายหน้า

    เจาะลึก: บันทึกเกี่ยวกับ API ของ OPNsense 26.7
    • header ของ script บันทึกว่า path ของ configuration แต่ละตัวนำมาจากหน้าเว็บของ router เองในวันนั้น: alias/search_item, alias/add_item, alias/set_item, alias/reconfigure, filter/search_rule, filter/add_rule, filter/set_rule, filter/apply, d_nat/search_rule, d_nat/set_rule, d_nat/apply, alias_util/list และ core/backup/download/this มันยังเรียก core/firmware/info เพื่อดูเวอร์ชัน และ core/firmware/status เพื่อตรวจว่าเข้าถึง router ได้
    • endpoint สำหรับค้นหาตอบ GET ที่มี ?rowCount=-1&current=1 และคืนทุกแถว พร้อม field ที่ script ต้องใช้
    • alias/get_item คืนรายการตัวเลือกที่มี key ชื่อว่าง ซึ่ง PowerShell แปลงเป็น property ของ object ไม่ได้
    • GET /api/core/backup/download/this คืน configuration ทั้งหมดเป็น XML
    • body ของ POST เป็น JSON พร้อม Content-Type: application/json การเปลี่ยน rule มีผลหลัง apply ที่คู่กัน การเปลี่ยน alias มีผลหลัง reconfigure
    อภิธานศัพท์
    • Windows PowerShell 5.1: PowerShell ที่มากับ Windows สร้างบน .NET Framework เรียกใช้ด้วย powershell
    • PowerShell 7: PowerShell รุ่นใหม่ ติดตั้งแยก สร้างบน .NET รุ่นใหม่ เรียกใช้ด้วย pwsh
    • REST API: ชุดของ web address ที่โปรแกรมเรียกเพื่ออ่านหรือเปลี่ยนค่าตั้ง คำตอบของ OPNsense เป็น JSON
    • JSON: รูปแบบข้อความสำหรับข้อมูลที่มีโครงสร้าง
    • Mock: ตัวแทนของระบบจริงที่ใช้ทดสอบ ในที่นี้คือ web server ขนาดเล็กที่ตอบเหมือน router
    • Test harness: script ที่รัน script อีกตัวในสถานการณ์ที่กำหนดไว้หลายแบบ และตรวจผลลัพธ์
    • API key: key และ secret ที่ให้ script ทำงานในฐานะ user ของ router โดยไม่ต้องใช้รหัสผ่าน
    • Alias (URL table): รายการ address ของ OPNsense ที่ router ดาวน์โหลดจาก web address และ refresh
    • NAT redirect: rule ที่เปลี่ยนปลายทางของทราฟฟิกที่ match ในที่นี้ใช้ส่ง query DNS ที่ส่งไปยัง server อื่นกลับมาที่ router
    • State table: รายการ connection ที่ firewall เคยเห็นแล้ว packet ถัดไปของ connection ที่รู้จักจะทำตามการตัดสินใจที่ทำไว้กับ packet แรก
    • DoH, DoT: DNS over HTTPS (port 443) และ DNS over TLS (port 853) สองวิธีที่อุปกรณ์ใช้ค้นหาชื่อโดยไม่ต้องถาม router
    • Expect: 100-continue: header ของ HTTP ที่ขอให้ server อนุมัติ request ก่อนส่ง body

    The script, the mock router and the test harness

    Code is the same in every language. MIT licence. कोड हर भाषा में एक ही है। కోడ్ అన్ని భాషలలో ఒకేలా ఉంటుంది. โค้ดเหมือนกันทุกภาษา

    opnsense-dns-bypass.ps1 (version 2.5.1)
    <#
      opnsense-dns-bypass.ps1   (version 2.5.1, 28/10/2026)
      Prepared by Vivek Sanghi with Claude (Anthropic).
      Copyright (c) 2026 Vivek Sanghi. MIT licence: see the end of this header.
      Built for: OPNsense 26.7 series (amd64). Version 2.4 of this script ran against the author's router
      on 11/10/2026. Version 2.5.1 has been tested only against the mock router published with it.
      Changes from 2.4:
        - the router address is a placeholder you must replace; https is required (plain http is
          accepted only for an address on this PC, as the test kit uses)
        - Apply stops before changing anything if the NAT rule or the LAN allow rule is not found
        - an undo of the alias restores its enabled flag as well as its contents
        - messages corrected: the NAT stage says what state it left the redirect in, a failed backup
          says whether changes had been made, and every stop after the log file is opened is
          written to the log (the checks on -Router and the work folder stop earlier, on screen only)
        - the test domain and the NAT wait are settings near the top
        - this header: usage, scope and limits, firmware paths, licence
      Every API path used here was taken from the router's own web pages on that date:
        Aliases page       : alias/search_item, alias/add_item, alias/set_item, alias/reconfigure
        Rules page         : filter/search_rule, filter/add_rule, filter/set_rule, filter/apply
      get_item/get_rule are NOT used: their replies contain empty JSON keys ("":), which PowerShell
      cannot turn into object properties, so Invoke-RestMethod returns raw text. Checked 11/10/2026.
        Destination NAT    : d_nat/search_rule, d_nat/set_rule, d_nat/apply
        Diagnostics        : alias_util/list ; Backups: core/backup/download/this
      Also used, not listed in 2.4's header: core/firmware/info (version check), core/firmware/status (reachability).
      The script stops before changing anything if the router reports a different OPNsense series.
    
      What it does (Apply):
        1. Alias  DoH_IPs : URL table, Hagezi DoH IP list, refresh daily (created, or cleaned to the URL only)
        2. Rule A : LAN in, reject TCP/UDP to DoH_IPs port 443
        3. Rule B : LAN in, reject TCP/UDP to any port 853
        4. NAT    : "Redirect non-local DNS to Local" (port 53) switched ON (the rule must already exist)
    
      Scope and limits (read before running):
        - IPv4 only. Rules A and B are created for IPv4 (ipprotocol inet) and every test uses an IPv4
          address. If your LAN has IPv6, DoH and DoT over IPv6 are neither blocked nor tested.
        - LAN interface only (interface 'lan'). Other interfaces and VLANs are not covered.
        - Rules A and B apply to every host on the LAN. A Pi-hole or AdGuard Home on the LAN that uses
          DoH or DoT upstream loses its upstream.
        - The NAT rule must already exist (Firewall > NAT > Destination NAT) with the description in
          $NatDesc. The script only switches it on or off; it does not create it or check how it is built.
        - The alias named in $AliasName is overwritten with the Hagezi URL; its old contents are logged.
        - $AdTestDomain must be blocked by your router's DNS blocklist and answered as 0.0.0.0.
        - Rollback switches the NAT rule off even if it was on before you first ran Apply.
        - The API key acts as an OPNsense user. A root user's key gives full control of the router, to
          the script and to anyone who obtains the key. The certificate check accepts any certificate
          presented for the router's address, so a LAN device posing as the router would receive the key.
    
      Modes:
        -Mode Check     (default) Backup, then READ-ONLY report and live tests.
        -Mode Apply     Backup, check that the NAT rule and the LAN allow rule exist, make the changes and
                        verify them; on a failure it undoes what this run changed. If only the NAT stage
                        fails, only the NAT change is undone and it exits with code 2.
        -Mode Rollback  Backup, then DISABLE rules A and B and the NAT rule. Nothing is deleted.
    
      Files written on this PC (never overwritten):
        <WorkDir>\router-backups\config-<mode>-<before|after>-<timestamp>.xml
        <WorkDir>\logs\run-<mode>-<timestamp>.log
      The API secret is read from -KeyFile and is never printed or logged.
    
      Usage (Windows PowerShell 5.1):
        powershell -ExecutionPolicy Bypass -File .\opnsense-dns-bypass.ps1 -KeyFile .\apikey.txt -Router https://<router-ip-address>
        Add -Mode Apply or -Mode Rollback to change the router; without -Mode it only checks.
    
      MIT licence
      Permission is hereby granted, free of charge, to any person obtaining a copy of this software
      and associated documentation files (the "Software"), to deal in the Software without restriction,
      including without limitation the rights to use, copy, modify, merge, publish, distribute,
      sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
      furnished to do so, subject to the following conditions:
      The above copyright notice and this permission notice shall be included in all copies or
      substantial portions of the Software.
      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
      NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
      NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
      OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
      CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    #>
    [CmdletBinding()]
    param(
        [ValidateSet('Check','Apply','Rollback')]
        [string]$Mode = 'Check',
        [Parameter(Mandatory = $true)]
        [string]$KeyFile,
        [string]$Router = 'https://<router-ip-address>',
        [string]$WorkDir = $PSScriptRoot
    )
    
    $ErrorActionPreference = 'Stop'
    Set-StrictMode -Version 1
    $LogFile = $null
    
    # $PSScriptRoot in a param() default can be empty under Windows PowerShell 5.1, so resolve the folder here.
    if ([string]::IsNullOrWhiteSpace($WorkDir)) {
        if ($MyInvocation.MyCommand.Path) { $WorkDir = Split-Path -Parent $MyInvocation.MyCommand.Path }
        else { $WorkDir = (Get-Location).Path }
    }
    if (-not (Test-Path -LiteralPath $WorkDir -PathType Container)) { Write-Host "Work folder not found: $WorkDir" -ForegroundColor Red; exit 1 }
    if ($Router -match '[<>]') { Write-Host "Set -Router to your router's address, for example -Router https://192.168.1.1 . Nothing was done." -ForegroundColor Red; exit 1 }
    try { $RouterUri = [Uri]$Router } catch { Write-Host "-Router is not a valid address: $Router . Nothing was done." -ForegroundColor Red; exit 1 }
    if ($RouterUri.Scheme -ne 'https' -and -not $RouterUri.IsLoopback) { Write-Host "-Router must start with https:// because the API key goes with every request. Nothing was done." -ForegroundColor Red; exit 1 }
    
    # ---------- fixed settings ----------
    $ExpectedSeries = '26.7'
    $AliasName   = 'DoH_IPs'
    $AliasUrl    = 'https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt'
    $AliasDesc   = 'Hagezi DoH resolver IPs'
    $DescA       = 'Reject DoH to known resolvers (A)'
    $DescB       = 'Reject DoT/DoQ 853 from LAN (B)'
    $NatDesc     = 'Redirect non-local DNS to Local'
    $AllowLan    = 'Default allow LAN to any rule'
    $AdTestDomain   = 'googleads.g.doubleclick.net'   # must be blocked by your router's blocklist (answered as 0.0.0.0)
    $NatWaitSeconds = 70   # longer than the router's udp.first / udp.multiple timeouts (Firewall > Diagnostics > Statistics)
    $MinAliasIPs = 500
    $RuleDefs = @(
        @{ description = $DescA; destination_net = $AliasName; destination_port = '443' },
        @{ description = $DescB; destination_net = 'any';      destination_port = '853' }
    )
    
    # ---------- logging ----------
    $stamp  = Get-Date -Format 'yyyyMMdd-HHmmss'
    $logDir = Join-Path $WorkDir 'logs'
    New-Item -ItemType Directory -Force -Path $logDir | Out-Null
    $LogFile = Join-Path $logDir ("run-{0}-{1}.log" -f $Mode, $stamp)
    function Log([string]$msg, [string]$color = 'Gray') {
        $line = '{0}  {1}' -f (Get-Date -Format 'HH:mm:ss'), $msg
        Write-Host $line -ForegroundColor $color
        if ($LogFile) { Add-Content -Path $LogFile -Value $line }
    }
    function Fail([string]$msg) { Log "STOP: $msg" 'Red'; Log "Log file: $LogFile" 'Red'; exit 1 }
    # Any error that no try/catch below handles is written to the log before the script stops.
    trap { Log "STOP: $($_.Exception.Message)" 'Red'; Log "Log file: $LogFile" 'Red'; exit 1 }
    
    # ---------- API key ----------
    if (-not (Test-Path -LiteralPath $KeyFile)) { Fail "Key file not found: $KeyFile" }
    $kv = @{}
    foreach ($l in Get-Content -LiteralPath $KeyFile) {
        if ($l -match '^\s*(key|secret)\s*=\s*(\S+)\s*$') { $kv[$Matches[1]] = $Matches[2] }
    }
    if (-not $kv.ContainsKey('key') -or -not $kv.ContainsKey('secret')) { Fail "Key file must contain lines key=... and secret=..." }
    $Auth = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($kv['key'] + ':' + $kv['secret']))
    $kv = $null
    
    # ---------- TLS: accept the router's self-signed certificate, for the router's address only ----------
    $IsPS7 = $PSVersionTable.PSVersion.Major -ge 6
    if (-not $IsPS7) {
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
        # Windows PowerShell 5.1 adds 'Expect: 100-continue' to POSTs; switch it off so the router's web server gets a plain request.
        [Net.ServicePointManager]::Expect100Continue = $false
        if (-not ('RouterCertTrust' -as [type])) {
            Add-Type -TypeDefinition @"
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public static class RouterCertTrust {
        public static string Host;
        public static bool Check(object sender, X509Certificate c, X509Chain ch, SslPolicyErrors e) {
            if (e == SslPolicyErrors.None) return true;
            HttpWebRequest r = sender as HttpWebRequest;
            return r != null && r.RequestUri.Host == Host;
        }
        public static void Enable(string host) {
            Host = host;
            ServicePointManager.ServerCertificateValidationCallback = Check;
        }
    }
    "@
        }
        [RouterCertTrust]::Enable(([Uri]$Router).Host)
    }
    
    # ---------- API helper ----------
    function Api([string]$Method, [string]$Path, $Body = $null) {
        $p = @{ Uri = $Router + $Path; Method = $Method; Headers = @{ Authorization = $Auth }; TimeoutSec = 60 }
        if ($Method -eq 'POST') {
            if ($null -eq $Body) { $p.Body = '{}' } else { $p.Body = ($Body | ConvertTo-Json -Depth 10 -Compress) }
            $p.ContentType = 'application/json'
        }
        if ($IsPS7) { $p.SkipCertificateCheck = $true }
        $r = Invoke-RestMethod @p
        if ($r -is [string]) {
            $t = $r.TrimStart()
            if ($t.StartsWith('{') -or $t.StartsWith('[')) { throw "Router reply to $Path could not be read as JSON by this PowerShell; stopping." }
        }
        return $r
    }
    function Assert-Saved($resp, [string]$what) {
        # The router's own GUI (opnsense_ui.js) treats a reply carrying 'validations' as a failure.
        # A reply with result 'failed' is also a failure. Every save is additionally verified by reading state back.
        $names = @()
        if ($resp) { $names = @($resp.PSObject.Properties.Name) }
        $bad = (-not $resp) -or ($names -contains 'validations') -or (($names -contains 'result') -and "$($resp.result)" -eq 'failed')
        if ($bad) { throw "$what was not saved. Router replied: $($resp | ConvertTo-Json -Compress -Depth 6)" }
    }
    
    # ---------- live tests from this PC ----------
    function Test-Tcp([string]$TargetHost, [int]$Port, [int]$Ms = 4000) {
        $c = New-Object Net.Sockets.TcpClient
        try {
            $t = $c.ConnectAsync($TargetHost, $Port)
            if ($t.Wait($Ms)) { return $c.Connected } else { return $false }
        } catch { return $false } finally { $c.Dispose() }
    }
    function Get-ARecords([string]$Name, [string]$Server) {
        try {
            $a = Resolve-DnsName -Name $Name -Server $Server -Type A -DnsOnly -QuickTimeout -ErrorAction Stop
            return @($a | Where-Object { $_.Type -eq 'A' } | ForEach-Object { $_.IPAddress })
        } catch { return @() }
    }
    function Test-Leaks([string]$Server) {
        # $true if $Server hands out a real address for $AdTestDomain, which your blocklist blocks
        $ips = Get-ARecords $AdTestDomain $Server
        return (@($ips | Where-Object { $_ -ne '0.0.0.0' }).Count -gt 0)
    }
    function Show-Tests {
        $routerHost = ([Uri]$Router).Host
        $r = [ordered]@{
            RouterResolves = (@(Get-ARecords 'example.com' $routerHost).Count -gt 0)
            RouterBlocks   = (-not (Test-Leaks $routerHost))
            DoH443Open     = (Test-Tcp '1.1.1.1' 443)
            DoT853Open     = (Test-Tcp '9.9.9.9' 853)
            Google53Leaks  = (Test-Leaks '8.8.8.8')
        }
        Log ("Router resolves example.com            : {0}   (want True)" -f $r.RouterResolves)
        Log ("Router blocks the ad domain (blocklist) : {0}   (want True)" -f $r.RouterBlocks)
        Log ("Bypass DoH  1.1.1.1:443 reachable       : {0}   (want False after Apply)" -f $r.DoH443Open)
        Log ("Bypass DoT  9.9.9.9:853 reachable       : {0}   (want False after Apply)" -f $r.DoT853Open)
        Log ("Bypass 8.8.8.8 gives real ad IPs        : {0}   (want False after Apply)" -f $r.Google53Leaks)
        return $r
    }
    
    # ---------- router state ----------
    function Get-State {
        $aliases = Api GET '/api/firewall/alias/search_item?rowCount=-1&current=1'
        $alias   = @($aliases.rows | Where-Object { $_.name -eq $AliasName }) | Select-Object -First 1
        $rules   = Api GET '/api/firewall/filter/search_rule?rowCount=-1&current=1'
        $mvc     = @($rules.rows | Where-Object { -not (($_.PSObject.Properties.Name -contains 'legacy') -and $_.legacy) })
        $ruleA   = @($mvc | Where-Object { $_.description -eq $DescA }) | Select-Object -First 1
        $ruleB   = @($mvc | Where-Object { $_.description -eq $DescB }) | Select-Object -First 1
        $allow   = @($rules.rows | Where-Object { $_.description -eq $AllowLan }) | Select-Object -First 1
        $nats    = Api GET '/api/firewall/d_nat/search_rule?rowCount=-1&current=1'
        $nat     = @($nats.rows | Where-Object { $_.descr -eq $NatDesc }) | Select-Object -First 1
        $count   = 0
        if ($alias) { try { $count = [int](Api GET "/api/firewall/alias_util/list/$AliasName").total } catch { $count = 0 } }
        return [pscustomobject]@{ Alias = $alias; AliasCount = $count; RuleA = $ruleA; RuleB = $ruleB; Allow = $allow; Nat = $nat }
    }
    function Show-State($s) {
        if ($s.Alias) {
            $c = ("$($s.Alias.content)" -replace "`r?`n", ' | ')
            Log ("Alias {0}: present, enabled={1}, entries loaded={2}, content=[{3}]" -f $AliasName, $s.Alias.enabled, $s.AliasCount, $c)
        } else { Log ("Alias {0}: not present" -f $AliasName) }
        foreach ($pair in @(@('Rule A', $s.RuleA), @('Rule B', $s.RuleB))) {
            $r = $pair[1]
            if ($r) { Log ("{0}: present, enabled={1}, sort_order={2}" -f $pair[0], $r.enabled, $r.sort_order) }
            else    { Log ("{0}: not present" -f $pair[0]) }
        }
        if ($s.Allow) { Log ("'{0}': sort_order={1}" -f $AllowLan, $s.Allow.sort_order) }
        if ($s.Nat)   { Log ("NAT '{0}': disabled={1}" -f $NatDesc, $s.Nat.disabled) }
        else          { Log ("NAT '{0}': NOT FOUND" -f $NatDesc) 'Yellow' }
    }
    
    # ---------- backup ----------
    function Save-Backup([string]$when) {
        $dir = Join-Path $WorkDir 'router-backups'
        New-Item -ItemType Directory -Force -Path $dir | Out-Null
        $file = Join-Path $dir ("config-{0}-{1}-{2}.xml" -f $Mode, $when, $stamp)
        if (Test-Path -LiteralPath $file) { Fail "Backup file already exists, refusing to overwrite: $file" }
        $p = @{ Uri = "$Router/api/core/backup/download/this"; Method = 'GET'; Headers = @{ Authorization = $Auth }; OutFile = $file; UseBasicParsing = $true; TimeoutSec = 60 }
        if ($IsPS7) { $p.SkipCertificateCheck = $true }
        Invoke-WebRequest @p | Out-Null
        $size = (Get-Item -LiteralPath $file).Length
        $head = (Get-Content -LiteralPath $file -TotalCount 3) -join ' '
        if ($size -lt 50000 -or $head -notmatch '<opnsense>') {
            if ($when -eq 'before') { Fail "Backup looks wrong ($size bytes): $file. Nothing changed on the router." }
            Fail "Backup ($when) looks wrong ($size bytes): $file. The changes logged above were made; check the router."
        }
        Log ("Backup ({0}) saved: {1} ({2:N0} bytes)" -f $when, $file, $size) 'Green'
    }
    
    # ================= START =================
    Log "Mode: $Mode   Router: $Router   PowerShell $($PSVersionTable.PSVersion)"
    try { $info = Api GET '/api/core/firmware/info' } catch { Fail "Cannot reach the router API with this key: $($_.Exception.Message)" }
    $series = "$($info.product.product_series)"
    Log ("Router reports: {0} series {1}, {2}" -f $info.product.product_name, $series, $info.product.product_arch)
    if ($series -ne $ExpectedSeries) { Fail "Script was built for OPNsense $ExpectedSeries; router reports $series. Nothing changed. Check the API paths against your router's own web pages before changing ExpectedSeries." }
    
    # Backup next (after the version check), in every mode, before any configuration is read or changed.
    Save-Backup 'before'
    
    $state = Get-State
    Show-State $state
    $tests = Show-Tests
    
    # Apply needs both of these before it changes anything; Check reports them.
    $problems = @()
    if (-not $state.Nat)   { $problems += "NAT rule '$NatDesc' not found. Create it in Firewall > NAT > Destination NAT, or set `$NatDesc to its description." }
    if (-not $state.Allow) { $problems += "Rule '$AllowLan' not found, so rule order cannot be checked. Set `$AllowLan to the description of your LAN allow-all rule." }
    if ($Mode -eq 'Check') {
        foreach ($p in $problems) { Log "Apply would stop: $p" 'Yellow' }
        Log 'Check mode: nothing was changed on the router.' 'Green'; Log "Log file: $LogFile"; exit 0
    }
    if ($Mode -eq 'Apply' -and $problems.Count -gt 0) { Fail (($problems -join ' ') + ' Nothing changed.') }
    
    # ---------- undo bookkeeping ----------
    $Undo = New-Object System.Collections.ArrayList
    function Invoke-Undo {
        if ($Undo.Count -eq 0) { Log 'Nothing to undo.'; return }
        Log 'Undoing changes made in this run...' 'Yellow'
        for ($i = $Undo.Count - 1; $i -ge 0; $i--) {
            $u = $Undo[$i]
            try {
                switch ($u.kind) {
                    'rule'         { $null = Api POST "/api/firewall/filter/set_rule/$($u.uuid)" @{ rule = @{ enabled = '0' } }; $null = Api POST '/api/firewall/filter/apply'; Log "  rule $($u.uuid) disabled" 'Yellow' }
                    'nat'          { $null = Api POST "/api/firewall/d_nat/set_rule/$($u.uuid)" @{ rule = @{ disabled = '1' } }; $null = Api POST '/api/firewall/d_nat/apply'; Log '  NAT rule switched back off' 'Yellow' }
                    'aliascontent' { $null = Api POST "/api/firewall/alias/set_item/$($u.uuid)" @{ alias = @{ content = $u.old; enabled = $u.oldEnabled } }; $null = Api POST '/api/firewall/alias/reconfigure'; Log '  alias content and enabled flag restored (refresh interval left at 1 day)' 'Yellow' }
                    'aliasnew'     { $null = Api POST "/api/firewall/alias/set_item/$($u.uuid)" @{ alias = @{ enabled = '0' } }; $null = Api POST '/api/firewall/alias/reconfigure'; Log '  new alias disabled' 'Yellow' }
                }
            } catch { Log "  UNDO STEP FAILED ($($u.kind)): $($_.Exception.Message). Restore the 'before' backup from System > Configuration > Backups." 'Red' }
        }
    }
    
    # ================= ROLLBACK =================
    if ($Mode -eq 'Rollback') {
        try {
            $changed = $false
            foreach ($r in @($state.RuleA, $state.RuleB)) {
                if ($r -and "$($r.enabled)" -eq '1') {
                    Assert-Saved (Api POST "/api/firewall/filter/set_rule/$($r.uuid)" @{ rule = @{ enabled = '0' } }) "Disable rule '$($r.description)'"
                    Log "Disabled rule '$($r.description)'" 'Yellow'; $changed = $true
                }
            }
            if ($changed) { $null = Api POST '/api/firewall/filter/apply'; Log 'Firewall rules applied.' }
            if ($state.Nat -and "$($state.Nat.disabled)" -ne '1') {
                Assert-Saved (Api POST "/api/firewall/d_nat/set_rule/$($state.Nat.uuid)" @{ rule = @{ disabled = '1' } }) 'Disable NAT rule'
                $null = Api POST '/api/firewall/d_nat/apply'
                Log "Disabled NAT rule '$NatDesc' and applied." 'Yellow'
            }
        } catch { Fail "Rollback error: $($_.Exception.Message)" }
        Start-Sleep -Seconds 3
        Show-State (Get-State); $null = Show-Tests
        Save-Backup 'after'
        Log 'Rollback finished.' 'Green'; Log "Log file: $LogFile"; exit 0
    }
    
    # ================= APPLY =================
    if (-not $tests.RouterResolves) { Fail 'The router itself is not resolving example.com. Fix that first; nothing changed.' }
    
    try {
        # ---- 1. Alias ----
        if (-not $state.Alias) {
            $body = @{ alias = @{ enabled = '1'; name = $AliasName; type = 'urltable'; updatefreq = '1'; content = $AliasUrl; description = $AliasDesc } }
            $r = Api POST '/api/firewall/alias/add_item' $body
            Assert-Saved $r "Alias $AliasName"
            $newId = "$($r.uuid)"
            if (-not $newId) { $newId = "$((@((Api GET '/api/firewall/alias/search_item?rowCount=-1&current=1').rows | Where-Object { $_.name -eq $AliasName }) | Select-Object -First 1).uuid)" }
            [void]$Undo.Add(@{ kind = 'aliasnew'; uuid = $newId })
            Log "Alias $AliasName created." 'Green'
        } else {
            $uuid = "$($state.Alias.uuid)"
            $oldContent = ("$($state.Alias.content)" -replace "`r`n", "`n").Trim()
            if ("$($state.Alias.type)" -ne 'urltable') { throw "Existing alias $AliasName is type '$($state.Alias.type)', not urltable. Fix or delete it in the GUI, then rerun." }
            if ($oldContent -ne $AliasUrl -or "$($state.Alias.enabled)" -ne '1') {
                Assert-Saved (Api POST "/api/firewall/alias/set_item/$uuid" @{ alias = @{ enabled = '1'; content = $AliasUrl; updatefreq = '1' } }) "Clean alias $AliasName"
                [void]$Undo.Add(@{ kind = 'aliascontent'; uuid = $uuid; old = $oldContent; oldEnabled = "$($state.Alias.enabled)" })
                Log ("Alias {0} set to the URL only (was: {1})." -f $AliasName, ($oldContent -replace "`r?`n", ' | ')) 'Green'
            } else { Log "Alias $AliasName already correct." }
        }
        $null = Api POST '/api/firewall/alias/reconfigure'
        $nowRow = @((Api GET '/api/firewall/alias/search_item?rowCount=-1&current=1').rows | Where-Object { $_.name -eq $AliasName }) | Select-Object -First 1
        if (-not $nowRow) { throw "Alias $AliasName not found after saving." }
        $nowContent = ("$($nowRow.content)" -replace "`r`n", "`n").Trim()
        if ($nowContent -ne $AliasUrl) { throw "Alias $AliasName content reads back as [$($nowContent -replace "`r?`n", ' | ')], not the URL alone." }
        $count = 0
        for ($i = 0; $i -lt 18; $i++) {
            try { $count = [int](Api GET "/api/firewall/alias_util/list/$AliasName").total } catch { $count = 0 }
            if ($count -ge $MinAliasIPs) { break }
            Start-Sleep -Seconds 5
        }
        if ($count -lt $MinAliasIPs) { throw "Alias $AliasName loaded only $count entries after 90 s." }
        Log "Alias $AliasName holds $count addresses." 'Green'
    
        # ---- 2. Rules A and B ----
        $current = @{ $DescA = $state.RuleA; $DescB = $state.RuleB }
        foreach ($d in $RuleDefs) {
            $existing = $current[$d.description]
            if (-not $existing) {
                $body = @{ rule = @{
                    enabled = '1'; action = 'reject'; quick = '1'; interface = 'lan'; direction = 'in'
                    ipprotocol = 'inet'; protocol = 'TCP/UDP'; source_net = 'any'
                    destination_net = $d.destination_net; destination_port = $d.destination_port
                    log = '1'; description = $d.description } }
                $r = Api POST '/api/firewall/filter/add_rule' $body
                Assert-Saved $r "Rule '$($d.description)'"
                $newId = "$($r.uuid)"
                if (-not $newId) { $newId = "$((@((Api GET '/api/firewall/filter/search_rule?rowCount=-1&current=1').rows | Where-Object { $_.description -eq $d.description }) | Select-Object -First 1).uuid)" }
                if (-not $newId) { throw "Rule '$($d.description)' saved but its id could not be found; stopping before apply." }
                [void]$Undo.Add(@{ kind = 'rule'; uuid = $newId })
                Log "Rule '$($d.description)' added." 'Green'
            } elseif ("$($existing.enabled)" -ne '1') {
                Assert-Saved (Api POST "/api/firewall/filter/set_rule/$($existing.uuid)" @{ rule = @{ enabled = '1' } }) "Enable rule '$($d.description)'"
                [void]$Undo.Add(@{ kind = 'rule'; uuid = $existing.uuid })
                Log "Rule '$($d.description)' enabled." 'Green'
            } else { Log "Rule '$($d.description)' already present and enabled." }
        }
        $null = Api POST '/api/firewall/filter/apply'
        Log 'Firewall rules applied. Verifying...' 'Cyan'
        Start-Sleep -Seconds 5
    
        $after = Get-State
        foreach ($r in @($after.RuleA, $after.RuleB)) {
            if (-not $r) { throw 'A rule is missing after apply.' }
            if (-not $after.Allow) { throw "Rule '$AllowLan' not found after apply." }
            if ([double]"$($r.sort_order)" -ge [double]"$($after.Allow.sort_order)") {
                throw ("'{0}' sorts after '{1}' ({2} vs {3}) and would never match." -f $r.description, $AllowLan, $r.sort_order, $after.Allow.sort_order)
            }
        }
        try { $null = Api GET '/api/core/firmware/status' } catch { throw 'Router API not reachable after apply.' }
        if (-not (Test-Tcp 'www.google.com' 443)) { throw 'Ordinary HTTPS to www.google.com failed after apply.' }
        if (Test-Tcp '1.1.1.1' 443) { throw 'DoH to 1.1.1.1:443 is still reachable.' }
        if (Test-Tcp '9.9.9.9' 853) { throw 'DoT to 9.9.9.9:853 is still reachable.' }
        Log 'Rules A and B verified: DoH and DoT refused, normal HTTPS works.' 'Green'
    
    }
    catch {
        Log "Problem: $($_.Exception.Message)" 'Red'
        Invoke-Undo
        Show-State (Get-State)
        Save-Backup 'after-undo'
        Fail 'Apply did not complete; changes from this run were undone.'
    }
    
    # ---- 3. NAT rule (separate stage: if it fails, only the NAT change is undone; alias and rules A/B stay) ----
    $natUndoFrom = $Undo.Count
    $natOk = $true
    $nat = $null
    $natWaited = $false
    $natEnd = ''
    try {
        $nat = (Get-State).Nat
        if (-not $nat) { throw "NAT rule '$NatDesc' not found." }
        if ("$($nat.disabled)" -eq '1') {
            Assert-Saved (Api POST "/api/firewall/d_nat/set_rule/$($nat.uuid)" @{ rule = @{ disabled = '0' } }) 'Enable NAT rule'
            [void]$Undo.Add(@{ kind = 'nat'; uuid = $nat.uuid })
            $null = Api POST '/api/firewall/d_nat/apply'
            $chk = @($((Api GET '/api/firewall/d_nat/search_rule?rowCount=-1&current=1').rows) | Where-Object { $_.uuid -eq $nat.uuid }) | Select-Object -First 1
            if ("$($chk.disabled)" -ne '0') { throw "Router still shows the NAT rule disabled (disabled=$($chk.disabled))." }
            # A redirect applies only to NEW connections. A DNS query that matches a state opened before the
            # redirect (this script's own test query, or a device that keeps reusing one source port) still goes
            # to 8.8.8.8 until that state expires. The author's router reported udp.first/udp.multiple = 60s, udp.single = 30s
            # (Firewall > Diagnostics > Statistics, read 11/10/2026). Wait them out with no queries to 8.8.8.8.
            Log ("NAT rule enabled and applied. Waiting {0} s for older DNS states to expire before testing..." -f $NatWaitSeconds) 'Cyan'
            Start-Sleep -Seconds $NatWaitSeconds
            $natWaited = $true
        } else { Log 'NAT rule already enabled. Testing it...' }
        if (@(Get-ARecords 'example.com' '8.8.8.8').Count -eq 0) { throw 'example.com no longer resolves through 8.8.8.8 after the redirect.' }
        $waitNote = ''
        if ($natWaited) { $waitNote = " after $NatWaitSeconds s" }
        if (Test-Leaks '8.8.8.8') { throw "8.8.8.8 still returns real ad addresses$waitNote; the redirect is not taking effect." }
        Log 'NAT redirect verified: queries to 8.8.8.8 are answered by your router.' 'Green'
    }
    catch {
        $natOk = $false
        Log "Problem (NAT stage): $($_.Exception.Message)" 'Red'
        if ($Undo.Count -gt $natUndoFrom) {
            $u = $Undo[$Undo.Count - 1]
            try {
                $null = Api POST "/api/firewall/d_nat/set_rule/$($u.uuid)" @{ rule = @{ disabled = '1' } }
                $null = Api POST '/api/firewall/d_nat/apply'
                Log '  NAT rule switched back off. Alias and rules A/B are kept: they passed their checks.' 'Yellow'
                $natEnd = 'This run switched it on and has switched it off again.'
            } catch {
                Log "  UNDO OF NAT FAILED: $($_.Exception.Message). Switch it off in Firewall > NAT > Destination NAT." 'Red'
                $natEnd = 'This run switched it on and could not switch it off again: switch it off in Firewall > NAT > Destination NAT.'
            }
        } elseif ($nat -and "$($nat.disabled)" -ne '1') {
            $natEnd = 'It was already on before this run and is left on: check it in Firewall > NAT > Destination NAT.'
        } else {
            $natEnd = 'It is still off.'
        }
    }
    
    Show-State (Get-State)
    $null = Show-Tests
    Save-Backup 'after'
    if ($natOk) {
        Log 'Apply finished. Expected: router tests True, all three bypass tests False.' 'Green'
        Log "Log file: $LogFile"
    } else {
        Log ('Apply PARTLY finished: alias and rules A/B are in place and verified; the NAT redirect did not pass. ' + $natEnd) 'Yellow'
        Log "Log file: $LogFile"
        exit 2
    }
    
    mock-opnsense.ps1
    <#
      mock-opnsense.ps1 (v2)  -  a stand-in for the OPNsense 26.7 API, for testing opnsense-dns-bypass.ps1
      Prepared by Vivek Sanghi with Claude (Anthropic). Copyright (c) 2026 Vivek Sanghi. MIT licence (see opnsense-dns-bypass.ps1).
      Runs on Windows PowerShell 5.1 and PowerShell 7. Listens on 127.0.0.1 only. Writes no files.
    
      It answers the API paths the script uses, keeps the router's state in memory, and records every call.
      Test-only paths (not part of OPNsense):
        POST /__test/reset   {"scenario":"name"}  start a scenario with fresh state
        GET  /__test/state                         the current state
        GET  /__test/calls                         every call received since the last reset
        GET  /__test/tcp?h=host&p=port             mocked "can this PC reach host:port?"
        GET  /__test/dns?n=name&s=server           mocked DNS answer from that server
        GET  /__test/ping                          liveness
        POST /__test/stop                          stop the mock
    #>
    param([int]$Port = 18443)
    
    $ErrorActionPreference = 'Stop'
    $Url        = 'https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt'
    $DescA      = 'Reject DoH to known resolvers (A)'
    $DescB      = 'Reject DoT/DoQ 853 from LAN (B)'
    $GoodAuth   = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('testkey:testsecret'))
    $AdReal     = '142.250.183.2'
    $ExampleIp  = '93.184.215.14'
    
    function New-State([string]$scenario) {
        $s = @{
            scenario = $scenario; series = '26.7'; nextId = 1
            alias = @{ uuid = 'alias-1'; name = 'DoH_IPs'; type = 'urltable'; content = "__lan_network`n$Url"; enabled = '1'; loaded = 1434 }
            rules = New-Object System.Collections.ArrayList
            allow = @{ uuid = 'allow-1'; description = 'Default allow LAN to any rule'; sort_order = '400000.1000023'; enabled = '1' }
            nat = @{ uuid = 'nat-1'; descr = 'Redirect non-local DNS to Local'; disabled = '1' }
            natLive = $false
            backups = 0
            calls = New-Object System.Collections.ArrayList
        }
        switch ($scenario) {
            'version-mismatch' { $s.series = '26.1' }
            'alias-wrong-type' { $s.alias.type = 'host' }
            'fresh-alias'      { $s.alias = $null }
            'fresh-alias-doh-open' { $s.alias = $null }
            'nat-missing'      { $s.nat = $null }
            'allow-missing'    { $s.allow = $null }
            'nat-already-on-ineffective' { $s.nat.disabled = '0'; $s.natLive = $true }
            'alias-disabled-doh-open' { $s.alias.enabled = '0' }
            'already-applied'  {
                $s.alias.content = $Url
                [void]$s.rules.Add(@{ uuid = 'rule-a'; description = $DescA; enabled = '1'; live = '1'; sort_order = '400000.0000100' })
                [void]$s.rules.Add(@{ uuid = 'rule-b'; description = $DescB; enabled = '1'; live = '1'; sort_order = '400000.0000200' })
                $s.nat.disabled = '0'; $s.natLive = $true
            }
            'left-disabled' {
                # what version 2.3's undo left on the real router: both rules present, disabled
                [void]$s.rules.Add(@{ uuid = 'rule-a'; description = $DescA; enabled = '0'; live = '0'; sort_order = '400000.0000100' })
                [void]$s.rules.Add(@{ uuid = 'rule-b'; description = $DescB; enabled = '0'; live = '0'; sort_order = '400000.0000200' })
            }
        }
        return $s
    }
    $S = New-State 'default'
    
    function Find-Rule([string]$desc) { foreach ($r in $S.rules) { if ($r.description -eq $desc) { return $r } }; return $null }
    function Find-RuleById([string]$id) { foreach ($r in $S.rules) { if ($r.uuid -eq $id) { return $r } }; return $null }
    function Json($o) { return (ConvertTo-Json -InputObject $o -Depth 10 -Compress) }
    function Saved($extra) { $o = @{ result = 'saved' }; if ($extra) { foreach ($k in $extra.Keys) { $o[$k] = $extra[$k] } }; return (Json $o) }
    function Invalid([string]$field) { return (Json @{ result = 'failed'; validations = @{ $field = 'Mock validation error.' } }) }
    
    function Get-Query([string]$q) {
        $h = @{}
        foreach ($pair in ($q -split '&')) {
            if ($pair -match '^([^=]+)=(.*)$') { $h[$Matches[1]] = [Uri]::UnescapeDataString($Matches[2]) }
        }
        return $h
    }
    
    function Alias-Row {
        $a = $S.alias
        return @{ uuid = $a.uuid; name = $a.name; type = $a.type; content = $a.content; enabled = $a.enabled; description = 'mock' }
    }
    
    function Handle([string]$method, [string]$path, [string]$query, [string]$body, [string]$auth) {
        # returns @(status, contentType, body)
        if ($path -like '/__test/*') {
            switch ("$method $path") {
                'GET /__test/ping'  { return @(200, 'application/json', '{"ok":true}') }
                'POST /__test/reset' {
                    $sc = 'default'
                    if ($body) { $j = ConvertFrom-Json $body; if ($j.scenario) { $sc = "$($j.scenario)" } }
                    $script:S = New-State $sc
                    return @(200, 'application/json', (Json @{ ok = $true; scenario = $sc }))
                }
                'GET /__test/state' {
                    $o = @{ scenario = $S.scenario; alias = $S.alias; rules = @($S.rules); nat = $S.nat; natLive = $S.natLive }
                    return @(200, 'application/json', (Json $o))
                }
                'GET /__test/calls' { return @(200, 'application/json', (Json @{ calls = @($S.calls) })) }
                'GET /__test/tcp' {
                    $q = Get-Query $query; $hostPort = "$($q.h):$($q.p)"
                    $ruleA = Find-Rule $DescA; $ruleB = Find-Rule $DescB
                    $aliasOk = ($S.alias -ne $null) -and ($S.alias.loaded -ge 500) -and ($S.alias.enabled -eq '1')
                    $open = $true
                    switch ($hostPort) {
                        '1.1.1.1:443' { if ($ruleA -and $ruleA.live -eq '1' -and $aliasOk -and $S.scenario -notlike '*doh-open*') { $open = $false } }
                        '9.9.9.9:853' { if ($ruleB -and $ruleB.live -eq '1') { $open = $false } }
                        'www.google.com:443' { if ($S.scenario -eq 'https-broken' -and $ruleA -and $ruleA.live -eq '1') { $open = $false } }
                    }
                    return @(200, 'application/json', (Json @{ open = $open }))
                }
                'GET /__test/dns' {
                    $q = Get-Query $query; $ips = @()
                    $isAd = ($q.n -eq 'googleads.g.doubleclick.net')
                    if ($q.s -eq '8.8.8.8') {
                        $redirected = $S.natLive -and ($S.scenario -notlike '*ineffective*')
                        if ($isAd) { if ($redirected) { $ips = @('0.0.0.0') } else { $ips = @($AdReal) } }
                        elseif ($q.n -eq 'example.com') { $ips = @($ExampleIp) }
                    } else {
                        # the router itself
                        if ($isAd) { $ips = @('0.0.0.0') } elseif ($q.n -eq 'example.com') { $ips = @($ExampleIp) }
                    }
                    return @(200, 'application/json', (Json @{ ips = $ips }))
                }
                'POST /__test/stop' { $script:Running = $false; return @(200, 'application/json', '{"ok":true}') }
            }
            return @(404, 'application/json', '{"error":"unknown test path"}')
        }
    
        [void]$S.calls.Add(@{ method = $method; path = $path; body = $body })
        if ($auth -ne $GoodAuth) { return @(401, 'application/json', '{"status":401,"message":"Authentication Failed"}') }
    
        switch -Regex ("$method $path") {
            '^GET /api/core/firmware/info$' {
                return @(200, 'application/json', (Json @{ product = @{ product_name = 'OPNsense'; product_series = $S.series; product_arch = 'amd64' } }))
            }
            '^GET /api/core/firmware/status$' { return @(200, 'application/json', '{"status":"ok"}') }
            '^GET /api/core/backup/download/this$' {
                $S.backups++
                if ($S.scenario -eq 'small-backup' -or ($S.scenario -eq 'small-backup-after' -and $S.backups -gt 1)) { return @(200, 'application/xml', '<?xml version="1.0"?><error/>') }
                $pad = 'x' * 60000
                return @(200, 'application/xml', "<?xml version=`"1.0`"?>`n<opnsense>`n<!-- mock $pad -->`n</opnsense>`n")
            }
            '^GET /api/firewall/alias/search_item$' {
                if ($S.scenario -eq 'empty-key-reply') {
                    # a reply carrying an empty JSON key, as alias/get_item does on a real router
                    return @(200, 'application/json', '{"rows":[{"uuid":"alias-1","name":"DoH_IPs","type":{"":{"value":"","selected":0},"urltable":{"value":"URL Table","selected":1}},"content":"x","enabled":"1"}],"total":1}')
                }
                $rows = @(); if ($S.alias) { $rows = @(Alias-Row) }
                return @(200, 'application/json', (Json @{ rows = $rows; total = $rows.Count }))
            }
            '^GET /api/firewall/alias_util/list/DoH_IPs$' {
                $n = 0; if ($S.alias) { $n = $S.alias.loaded }
                return @(200, 'application/json', (Json @{ total = $n; rows = @() }))
            }
            '^POST /api/firewall/alias/add_item$' {
                if ($S.scenario -eq 'alias-validation') { return @(200, 'application/json', (Invalid 'alias.name')) }
                $j = (ConvertFrom-Json $body).alias
                $S.alias = @{ uuid = 'alias-new'; name = "$($j.name)"; type = "$($j.type)"; content = "$($j.content)"; enabled = "$($j.enabled)"; loaded = 0 }
                return @(200, 'application/json', (Saved @{ uuid = 'alias-new' }))
            }
            '^POST /api/firewall/alias/set_item/(.+)$' {
                if ($S.scenario -eq 'alias-validation') { return @(200, 'application/json', (Invalid 'alias.content')) }
                $j = (ConvertFrom-Json $body).alias
                foreach ($p in $j.PSObject.Properties) { if ($p.Name -ne 'updatefreq') { $S.alias[$p.Name] = "$($p.Value)" } }
                return @(200, 'application/json', (Saved $null))
            }
            '^POST /api/firewall/alias/reconfigure$' {
                if ($S.alias) {
                    $ok = ($S.alias.enabled -eq '1') -and (("$($S.alias.content)" -replace "`r", '').Trim() -eq $Url)
                    if ($ok) { if ($S.scenario -eq 'alias-not-filling') { $S.alias.loaded = 12 } else { $S.alias.loaded = 1434 } }
                }
                return @(200, 'application/json', '{"status":"ok"}')
            }
            '^GET /api/firewall/filter/search_rule$' {
                $rows = @()
                foreach ($r in $S.rules) { $rows += @{ uuid = $r.uuid; description = $r.description; enabled = $r.enabled; sort_order = $r.sort_order } }
                if ($S.allow) { $rows += @{ uuid = $S.allow.uuid; description = $S.allow.description; enabled = '1'; sort_order = $S.allow.sort_order } }
                return @(200, 'application/json', (Json @{ rows = $rows; total = $rows.Count }))
            }
            '^POST /api/firewall/filter/add_rule$' {
                $j = (ConvertFrom-Json $body).rule
                if ($S.scenario -eq 'rule-validation' -and "$($j.description)" -eq $DescB) { return @(200, 'application/json', (Invalid 'rule.destination_port')) }
                $S.nextId++
                $id = "rule-new-$($S.nextId)"
                $base = '400000.00001'; if ($S.scenario -eq 'rule-order') { $base = '500000.00001' }
                [void]$S.rules.Add(@{ uuid = $id; description = "$($j.description)"; enabled = "$($j.enabled)"; live = '0'; sort_order = ('{0}{1:00}' -f $base, $S.rules.Count) })
                return @(200, 'application/json', (Saved @{ uuid = $id }))
            }
            '^POST /api/firewall/filter/set_rule/(.+)$' {
                $r = Find-RuleById $Matches[1]
                if (-not $r) { return @(200, 'application/json', (Invalid 'rule.uuid')) }
                $j = (ConvertFrom-Json $body).rule
                if ($j.PSObject.Properties.Name -contains 'enabled') { $r.enabled = "$($j.enabled)" }
                return @(200, 'application/json', (Saved $null))
            }
            '^POST /api/firewall/filter/apply$' {
                foreach ($r in $S.rules) { $r.live = $r.enabled }
                return @(200, 'application/json', '{"status":"OK"}')
            }
            '^GET /api/firewall/d_nat/search_rule$' {
                $rows = @(); if ($S.nat) { $rows = @(@{ uuid = $S.nat.uuid; descr = $S.nat.descr; disabled = $S.nat.disabled }) }
                return @(200, 'application/json', (Json @{ rows = $rows; total = $rows.Count }))
            }
            '^POST /api/firewall/d_nat/set_rule/(.+)$' {
                if (-not $S.nat -or $Matches[1] -ne $S.nat.uuid) { return @(200, 'application/json', (Invalid 'rule.uuid')) }
                $j = (ConvertFrom-Json $body).rule
                if ($S.scenario -eq 'nat-validation' -and "$($j.disabled)" -eq '0') { return @(200, 'application/json', (Invalid 'rule.target')) }
                if ($j.PSObject.Properties.Name -contains 'disabled') { $S.nat.disabled = "$($j.disabled)" }
                return @(200, 'application/json', (Saved $null))
            }
            '^POST /api/firewall/d_nat/apply$' {
                $S.natLive = ($S.nat -ne $null) -and ($S.nat.disabled -eq '0')
                return @(200, 'application/json', '{"status":"OK"}')
            }
        }
        return @(404, 'application/json', '{"errorMessage":"Endpoint not found"}')
    }
    
    # ---------- minimal HTTP/1.1 server on 127.0.0.1 ----------
    $listener = New-Object System.Net.Sockets.TcpListener([Net.IPAddress]::Loopback, $Port)
    $listener.Start()
    Write-Host "mock-opnsense listening on http://127.0.0.1:$Port"
    $script:Running = $true
    $enc = New-Object System.Text.UTF8Encoding($false)
    while ($script:Running) {
        $client = $listener.AcceptTcpClient()
        try {
            $stream = $client.GetStream()
            $reader = New-Object System.IO.StreamReader($stream, $enc, $false, 65536, $true)
            $first = $reader.ReadLine()
            if (-not $first) { continue }
            $parts = $first -split ' '
            $method = $parts[0]; $target = $parts[1]
            $headers = @{}
            while ($true) {
                $line = $reader.ReadLine()
                if ([string]::IsNullOrEmpty($line)) { break }
                $i = $line.IndexOf(':')
                if ($i -gt 0) { $headers[$line.Substring(0, $i).Trim().ToLowerInvariant()] = $line.Substring($i + 1).Trim() }
            }
            if ($headers.ContainsKey('expect') -and $headers['expect'] -match '100-continue') {
                $c = $enc.GetBytes("HTTP/1.1 100 Continue`r`n`r`n"); $stream.Write($c, 0, $c.Length); $stream.Flush()
            }
            $body = ''
            if ($headers.ContainsKey('content-length')) {
                $len = [int]$headers['content-length']
                if ($len -gt 0) { $buf = New-Object char[] $len; $got = 0; while ($got -lt $len) { $n = $reader.Read($buf, $got, $len - $got); if ($n -le 0) { break }; $got += $n }; $body = New-Object System.String -ArgumentList $buf, 0, $got }
            }
            $path = $target; $query = ''
            $q = $target.IndexOf('?'); if ($q -ge 0) { $path = $target.Substring(0, $q); $query = $target.Substring($q + 1) }
            $auth = ''; if ($headers.ContainsKey('authorization')) { $auth = $headers['authorization'] }
            try { $res = Handle $method $path $query $body $auth }
            catch { $res = @(500, 'application/json', (ConvertTo-Json -InputObject @{ mockError = "$($_.Exception.Message)" } -Compress)) }
            $status = $res[0]
            $reason = @{ 200 = 'OK'; 401 = 'Unauthorized'; 404 = 'Not Found'; 500 = 'Internal Server Error' }[$status]
            $bytes = $enc.GetBytes([string]$res[2])
            $head = "HTTP/1.1 $status $reason`r`nContent-Type: $($res[1]); charset=utf-8`r`nContent-Length: $($bytes.Length)`r`nConnection: close`r`n`r`n"
            $hb = $enc.GetBytes($head)
            $stream.Write($hb, 0, $hb.Length); $stream.Write($bytes, 0, $bytes.Length); $stream.Flush()
        } catch {
            Write-Host "mock: request failed: $($_.Exception.Message)"
        } finally {
            $client.Close()
        }
    }
    $listener.Stop()
    Write-Host 'mock-opnsense stopped'
    
    Test-OpnsenseScript.ps1
    <#
      Test-OpnsenseScript.ps1 (v4)  -  runs opnsense-dns-bypass.ps1 against mock-opnsense.ps1, one case per failure path
      Prepared by Vivek Sanghi with Claude (Anthropic). Copyright (c) 2026 Vivek Sanghi. MIT licence (see opnsense-dns-bypass.ps1).
      Runs on Windows PowerShell 5.1 and PowerShell 7.
    
      What it touches:
        - reads the script under test; never changes it
        - writes a test copy and one folder per case under .\test-run-<timestamp>\ (next to this file)
        - starts mock-opnsense.ps1 on 127.0.0.1:<Port> and stops it at the end
        - contacts nothing else: the test copy's two network-test functions ask the mock instead of the internet,
          and every run points -Router at the mock. No real router, no real API key.
      The test copy differs from the script in exactly three ways, each checked before any case runs:
        Test-Tcp and Get-ARecords ask the mock; every Start-Sleep is cut to 1 ms.
    #>
    param(
        [string]$ScriptPath = '',
        [string]$MockPath = '',
        [int]$Port = 18443
    )
    $ErrorActionPreference = 'Stop'
    Set-StrictMode -Version 1
    # Work out this file's folder in the body, not in param(): the article's failure 1.
    $Here = ''
    if ($MyInvocation.MyCommand.Path) { $Here = Split-Path -Parent $MyInvocation.MyCommand.Path }
    if (-not $Here) { $Here = (Get-Location).Path }
    if (-not $ScriptPath) { $ScriptPath = Join-Path $Here 'opnsense-dns-bypass.ps1' }
    if (-not $MockPath) { $MockPath = Join-Path $Here 'mock-opnsense.ps1' }
    if (-not (Test-Path -LiteralPath $MockPath)) { Write-Host "Mock not found: $MockPath" -ForegroundColor Red; exit 1 }
    $Exe   = (Get-Process -Id $PID).Path
    $Base  = "http://127.0.0.1:$Port"
    $Url   = 'https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/ips/doh.txt'
    $DescA = 'Reject DoH to known resolvers (A)'
    $DescB = 'Reject DoT/DoQ 853 from LAN (B)'
    foreach ($n in 'NO_PROXY', 'no_proxy') { [Environment]::SetEnvironmentVariable($n, '127.0.0.1,localhost') }
    if ($PSVersionTable.PSVersion.Major -lt 6) { [Net.ServicePointManager]::Expect100Continue = $false }
    
    if (-not (Test-Path -LiteralPath $ScriptPath)) { Write-Host "Script not found: $ScriptPath" -ForegroundColor Red; exit 1 }
    $hash = (Get-FileHash -Algorithm SHA256 -LiteralPath $ScriptPath).Hash.ToLowerInvariant()
    Write-Host "PowerShell $($PSVersionTable.PSVersion) ($($PSVersionTable.PSEdition))"
    Write-Host "Script under test: $ScriptPath"
    Write-Host "SHA-256: $hash"
    
    # ---------- test copy ----------
    $stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
    $Run   = Join-Path $Here "test-run-$stamp"
    New-Item -ItemType Directory -Path $Run | Out-Null
    $text = [IO.File]::ReadAllText($ScriptPath)
    function Swap([string]$t, [string]$pattern, [string]$new, [int]$want, [string]$what) {
        $m = [regex]::Matches($t, $pattern)
        if ($m.Count -ne $want) { throw "Test copy: expected $want match(es) for $what, found $($m.Count). Has the script changed?" }
        foreach ($x in @($m | Sort-Object Index -Descending)) { $t = $t.Remove($x.Index, $x.Length).Insert($x.Index, $new) }
        return $t
    }
    $tcp = @'
    function Test-Tcp([string]$TargetHost, [int]$Port, [int]$Ms = 4000) {
        return [bool](Invoke-RestMethod -Uri ("$Router/__test/tcp?h={0}&p={1}" -f [Uri]::EscapeDataString($TargetHost), $Port) -TimeoutSec 10).open
    }
    
    '@
    $dns = @'
    function Get-ARecords([string]$Name, [string]$Server) {
        return @((Invoke-RestMethod -Uri ("$Router/__test/dns?n={0}&s={1}" -f [Uri]::EscapeDataString($Name), [Uri]::EscapeDataString($Server)) -TimeoutSec 10).ips)
    }
    
    '@
    $text = Swap $text '(?s)function Test-Tcp\(.*?\r?\n\}\r?\n' $tcp 1 'function Test-Tcp'
    $text = Swap $text '(?s)function Get-ARecords\(.*?\r?\n\}\r?\n' $dns 1 'function Get-ARecords'
    $text = Swap $text 'Start-Sleep -Seconds (\d+|\$\w+)' 'Start-Sleep -Milliseconds 1' 4 'Start-Sleep'
    $Copy = Join-Path $Run 'script-under-test.ps1'
    [IO.File]::WriteAllText($Copy, $text, (New-Object Text.UTF8Encoding($false)))
    
    # Evidence, not a pass/fail case: what this PowerShell puts in $PSScriptRoot when it is a parameter default.
    $probe = Join-Path $Run 'probe-psscriptroot.ps1'
    [IO.File]::WriteAllText($probe, 'param([string]$WorkDir = $PSScriptRoot)' + "`n" + '"[" + $WorkDir + "]"' + "`n")
    $probeOut = "$(& $Exe -NoProfile -ExecutionPolicy Bypass -File $probe)"
    $Evidence = "Evidence: `$PSScriptRoot as a parameter default, run with -File, gave $probeOut (empty brackets = empty)"
    Write-Host $Evidence
    
    $GoodKey = Join-Path $Run 'key-good.txt'; [IO.File]::WriteAllText($GoodKey, "key=testkey`nsecret=testsecret`n")
    $BadKey  = Join-Path $Run 'key-bad.txt';  [IO.File]::WriteAllText($BadKey,  "key=testkey`nsecret=wrongsecret`n")
    
    # ---------- mock ----------
    function Q([string]$a) { return '"' + $a + '"' }
    $mockOut = Join-Path $Run 'mock-output.txt'
    $mockArgs = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', (Q $MockPath), '-Port', $Port)
    $mock = Start-Process -FilePath $Exe -ArgumentList $mockArgs -PassThru -NoNewWindow -RedirectStandardOutput $mockOut -RedirectStandardError (Join-Path $Run 'mock-errors.txt')
    $up = $false
    for ($i = 0; $i -lt 60; $i++) { try { $null = Invoke-RestMethod "$Base/__test/ping" -TimeoutSec 2; $up = $true; break } catch { Start-Sleep -Milliseconds 500 } }
    if (-not $up) { Write-Host "The mock did not start. See $mockOut" -ForegroundColor Red; if (-not $mock.HasExited) { Stop-Process -Id $mock.Id -Force }; exit 1 }
    Write-Host "Mock: $MockPath (SHA-256 $((Get-FileHash -Algorithm SHA256 -LiteralPath $MockPath).Hash.ToLowerInvariant()))"
    $Secret64 = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('testkey:testsecret'))
    
    function Reset([string]$scenario) { $null = Invoke-RestMethod -Method POST -Uri "$Base/__test/reset" -Body (ConvertTo-Json @{ scenario = $scenario }) -ContentType 'application/json' }
    function State { return Invoke-RestMethod "$Base/__test/state" }
    function Calls { return @((Invoke-RestMethod "$Base/__test/calls").calls) }
    function Rule($st, [string]$desc) { return @(@($st.rules) | Where-Object { $_.description -eq $desc }) }
    
    # ---------- cases ----------
    $Results = New-Object System.Collections.ArrayList
    function Run-Case {
        param([string]$Name, [string]$Scenario, [string]$Mode = 'Apply', [int[]]$Exit, [scriptblock]$Check, [switch]$NoRouter, [string]$Key = $GoodKey, [string]$ModeRaw = '', [string]$RouterArg = '')
        Reset $Scenario
        $dir = Join-Path $Run $Name; New-Item -ItemType Directory -Path $dir | Out-Null
        $a = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', (Q $Copy), '-KeyFile', (Q $Key), '-WorkDir', (Q $dir))
        if ($RouterArg) { $a += @('-Router', $RouterArg) } elseif (-not $NoRouter) { $a += @('-Router', $Base) }
        if ($ModeRaw) { $a += @('-Mode', $ModeRaw) } else { $a += @('-Mode', $Mode) }
        $out = Join-Path $dir 'console.txt'; $err = Join-Path $dir 'console-errors.txt'
        $p = Start-Process -FilePath $Exe -ArgumentList $a -PassThru -Wait -NoNewWindow -RedirectStandardOutput $out -RedirectStandardError $err
        $code = $p.ExitCode
        $console = ((Get-Content -LiteralPath $out -Raw -ErrorAction SilentlyContinue) + (Get-Content -LiteralPath $err -Raw -ErrorAction SilentlyContinue))
        $logs = @(Get-ChildItem -LiteralPath (Join-Path $dir 'logs') -Filter '*.log' -ErrorAction SilentlyContinue)
        $log = ''; if ($logs.Count -gt 0) { $log = Get-Content -LiteralPath $logs[0].FullName -Raw }
        $backups = @(Get-ChildItem -LiteralPath (Join-Path $dir 'router-backups') -Filter '*.xml' -ErrorAction SilentlyContinue | ForEach-Object { $_.Name })
        $calls = Calls; $posts = @($calls | Where-Object { $_.method -eq 'POST' })
        $st = State
        $script:fails = New-Object System.Collections.ArrayList
        function Want([bool]$ok, [string]$msg) { if (-not $ok) { [void]$script:fails.Add($msg) } }
        Want ($Exit -contains $code) "exit code $code, wanted $($Exit -join ' or ')"
        Want (-not (($console + $log) -match 'testsecret|wrongsecret')) 'the API secret appeared in the output or log'
        Want (-not (($console + $log).Contains($Secret64))) 'the encoded API key appeared in the output or log'
        if ($code -ne 0 -and $log) { Want ($log -match 'STOP: |PARTLY finished') 'the run stopped without saying so in the log' }
        Want (@($posts | Where-Object { $_.path -match 'del' }).Count -eq 0) 'a delete call was made'
        $ctx = @{ code = $code; console = $console; log = $log; all = ($console + "`n" + $log); backups = $backups; calls = $calls; posts = $posts; state = $st; dir = $dir }
        & $Check $ctx
        $status = 'PASS'; if ($script:fails.Count -gt 0) { $status = 'FAIL' }
        [void]$Results.Add([pscustomobject]@{ Case = $Name; Result = $status; Exit = $code; Posts = $posts.Count; Notes = ($script:fails -join '; ') })
        $colour = 'Green'; if ($status -eq 'FAIL') { $colour = 'Red' }
        Write-Host ("{0,-24} {1}  exit={2}  POSTs={3}  {4}" -f $Name, $status, $code, $posts.Count, ($script:fails -join '; ')) -ForegroundColor $colour
    }
    
    try {
    Write-Host ''
    Run-Case 'placeholder-router' 'default' -Mode Check -NoRouter -Exit 1 -Check { param($c)
        Want ($c.calls.Count -eq 0) 'the mock received calls'
        Want (-not (Test-Path -LiteralPath (Join-Path $c.dir 'logs'))) 'a logs folder was created'
        Want ($c.console -match 'Set -Router') 'no "Set -Router" message' }
    Run-Case 'bad-mode' 'default' -ModeRaw 'Aply' -Exit 1 -Check { param($c)
        Want ($c.calls.Count -eq 0) 'the mock received calls' }
    Run-Case 'bad-key' 'default' -Mode Check -Key $BadKey -Exit 1 -Check { param($c)
        Want ($c.posts.Count -eq 0) 'POSTs were sent'
        Want ($c.backups.Count -eq 0) 'a backup was written'
        Want ($c.log -match 'Cannot reach the router API') 'no "Cannot reach the router API" message' }
    Run-Case 'version-mismatch' 'version-mismatch' -Exit 1 -Check { param($c)
        Want ($c.posts.Count -eq 0) 'POSTs were sent'
        Want ($c.backups.Count -eq 0) 'a backup was written'
        Want ($c.log -match 'built for OPNsense 26\.7; router reports 26\.1') 'no version message' }
    Run-Case 'small-backup' 'small-backup' -Exit 1 -Check { param($c)
        Want ($c.posts.Count -eq 0) 'POSTs were sent'
        Want ($c.log -match 'Backup looks wrong') 'no "Backup looks wrong" message' }
    Run-Case 'check' 'default' -Mode Check -Exit 0 -Check { param($c)
        Want ($c.posts.Count -eq 0) 'Check sent POSTs'
        Want (@($c.backups | Where-Object { $_ -like 'config-Check-before-*.xml' }).Count -eq 1) 'no Check backup'
        Want ($c.log -match 'Check mode: nothing was changed') 'no Check message'
        Want (@([regex]::Matches($c.log, 'want False after Apply\)')).Count -eq 3) 'not three bypass tests' }
    Run-Case 'empty-key-reply' 'empty-key-reply' -Exit 1 -Check { param($c)
        Want ($c.posts.Count -eq 0) 'POSTs were sent'
        Want ($c.log -match 'STOP: .*could not be read as JSON') 'the JSON guard stop is not in the log' }
    Run-Case 'http-router' 'default' -Mode Check -RouterArg 'http://192.0.2.1' -Exit 1 -Check { param($c)
        Want ($c.calls.Count -eq 0) 'the mock received calls'
        Want ($c.console -match 'must start with https://') 'no https message' }
    Run-Case 'check-nat-missing' 'nat-missing' -Mode Check -Exit 0 -Check { param($c)
        Want ($c.posts.Count -eq 0) 'Check sent POSTs'
        Want ($c.log -match "Apply would stop: NAT rule 'Redirect non-local DNS to Local' not found") 'no "Apply would stop" warning' }
    Run-Case 'allow-missing' 'allow-missing' -Exit 1 -Check { param($c)
        Want ($c.posts.Count -eq 0) 'POSTs were sent'
        Want ($c.log -match "Rule 'Default allow LAN to any rule' not found, so rule order cannot be checked") 'no allow-rule message'
        Want ($c.log -match 'Nothing changed\.') 'no "Nothing changed"' }
    Run-Case 'small-backup-after' 'small-backup-after' -Exit 1 -Check { param($c)
        Want ($c.log -match 'The changes logged above were made') 'no "changes were made" message'
        Want (-not ($c.log -match 'Nothing changed on the router')) 'claims nothing changed after changes' }
    Run-Case 'alias-undo-enabled' 'alias-disabled-doh-open' -Exit 1 -Check { param($c)
        Want ("$($c.state.alias.enabled)" -eq '0') 'alias enabled flag not restored'
        Want ("$($c.state.alias.content)" -eq "__lan_network`n$Url") 'alias content not restored'
        Want ($c.log -match 'alias content and enabled flag restored') 'no restore message' }
    Run-Case 'alias-wrong-type' 'alias-wrong-type' -Exit 1 -Check { param($c)
        Want ($c.posts.Count -eq 0) 'POSTs were sent'
        Want ($c.log -match "is type 'host', not urltable") 'no type message'
        Want ($c.log -match 'Nothing to undo') 'no "Nothing to undo"'
        Want (@($c.backups | Where-Object { $_ -like '*after-undo*' }).Count -eq 1) 'no after-undo backup' }
    Run-Case 'alias-validation' 'alias-validation' -Exit 1 -Check { param($c)
        Want ($c.log -match 'was not saved') 'no "was not saved" message'
        Want ($c.log -match 'Nothing to undo') 'no "Nothing to undo"'
        Want ("$($c.state.alias.content)" -eq "__lan_network`n$Url") 'alias content changed' }
    Run-Case 'alias-not-filling' 'alias-not-filling' -Exit 1 -Check { param($c)
        Want ($c.log -match 'loaded only 12 entries') 'no "loaded only" message'
        Want ($c.log -match 'alias content and enabled flag restored') 'alias not restored'
        Want ("$($c.state.alias.content)" -eq "__lan_network`n$Url") 'alias content not back to the original' }
    Run-Case 'rule-validation' 'rule-validation' -Exit 1 -Check { param($c)
        Want ($c.log -match "Rule 'Reject DoT/DoQ 853 from LAN \(B\)' was not saved") 'no rule B message'
        $ra = @(Rule $c.state $DescA)
        Want ($ra.Count -eq 1 -and "$($ra[0].enabled)" -eq '0') 'rule A not disabled by the undo'
        Want (@(Rule $c.state $DescB).Count -eq 0) 'rule B exists'
        Want ("$($c.state.alias.content)" -eq "__lan_network`n$Url") 'alias not restored'
        Want ("$($c.state.nat.disabled)" -eq '1') 'NAT touched' }
    Run-Case 'rule-order' 'rule-order' -Exit 1 -Check { param($c)
        Want ($c.log -match 'would never match') 'no rule-order message'
        Want (@(@($c.state.rules) | Where-Object { "$($_.enabled)" -ne '0' }).Count -eq 0) 'a rule left enabled'
        Want ("$($c.state.alias.content)" -eq "__lan_network`n$Url") 'alias not restored' }
    Run-Case 'doh-still-open' 'doh-open' -Exit 1 -Check { param($c)
        Want ($c.log -match 'DoH to 1\.1\.1\.1:443 is still reachable') 'no DoH message'
        Want (@(@($c.state.rules) | Where-Object { "$($_.enabled)" -ne '0' }).Count -eq 0) 'a rule left enabled'
        Want ("$($c.state.nat.disabled)" -eq '1') 'NAT touched' }
    Run-Case 'https-broken' 'https-broken' -Exit 1 -Check { param($c)
        Want ($c.log -match 'Ordinary HTTPS to www\.google\.com failed') 'no HTTPS message'
        Want (@(@($c.state.rules) | Where-Object { "$($_.enabled)" -ne '0' }).Count -eq 0) 'a rule left enabled' }
    Run-Case 'fresh-alias' 'fresh-alias' -Exit 0 -Check { param($c)
        Want (@($c.posts | Where-Object { $_.path -eq '/api/firewall/alias/add_item' }).Count -eq 1) 'alias not created once'
        Want ("$($c.state.alias.content)" -eq $Url) 'alias content wrong'
        Want ($c.log -match 'Apply finished') 'no "Apply finished"' }
    Run-Case 'fresh-alias-fails' 'fresh-alias-doh-open' -Exit 1 -Check { param($c)
        Want ($c.log -match 'new alias disabled') 'new alias not disabled'
        Want ("$($c.state.alias.enabled)" -eq '0') 'alias still enabled' }
    Run-Case 'apply' 'default' -Exit 0 -Check { param($c)
        Want ("$($c.state.alias.content)" -eq $Url) 'alias content not cleaned'
        Want ($c.log -match 'Alias DoH_IPs set to the URL only \(was: __lan_network \|') 'old alias content not logged'
        $ra = @(Rule $c.state $DescA); $rb = @(Rule $c.state $DescB)
        Want ($ra.Count -eq 1 -and "$($ra[0].enabled)" -eq '1') 'rule A not enabled'
        Want ($rb.Count -eq 1 -and "$($rb[0].enabled)" -eq '1') 'rule B not enabled'
        Want ("$($c.state.nat.disabled)" -eq '0') 'NAT not enabled'
        Want ($c.log -match 'Waiting 70 s') 'no 70 s wait message'
        Want ($c.log -match 'Apply finished') 'no "Apply finished"'
        Want (@($c.backups | Where-Object { $_ -like 'config-Apply-before-*' }).Count -eq 1 -and @($c.backups | Where-Object { $_ -like 'config-Apply-after-*' }).Count -eq 1) 'backups not before + after' }
    Run-Case 'leftover-rules' 'left-disabled' -Exit 0 -Check { param($c)
        Want (@($c.posts | Where-Object { $_.path -eq '/api/firewall/filter/add_rule' }).Count -eq 0) 'rules added again'
        Want (@($c.state.rules).Count -eq 2) 'duplicate rules'
        Want ($c.log -match "Rule 'Reject DoH to known resolvers \(A\)' enabled\.") 'rule A not re-enabled' }
    Run-Case 'already-applied' 'already-applied' -Exit 0 -Check { param($c)
        Want (@($c.posts | Where-Object { $_.path -like '/api/firewall/filter/add_rule' -or $_.path -like '/api/firewall/filter/set_rule/*' -or $_.path -like '/api/firewall/d_nat/set_rule/*' -or $_.path -like '/api/firewall/alias/set_item/*' }).Count -eq 0) 'something was re-saved'
        Want ($c.log -match 'already present and enabled') 'no "already present" message'
        Want ($c.log -match 'NAT rule already enabled') 'no "NAT already enabled" message' }
    Run-Case 'nat-missing' 'nat-missing' -Exit 1 -Check { param($c)
        Want ($c.posts.Count -eq 0) 'POSTs were sent before the missing NAT rule was reported'
        Want ($c.log -match "NAT rule 'Redirect non-local DNS to Local' not found\. Create it in Firewall > NAT > Destination NAT") 'no NAT-missing message' }
    Run-Case 'nat-ineffective' 'nat-ineffective' -Exit 2 -Check { param($c)
        Want ($c.log -match 'still returns real ad addresses after 70 s') 'no redirect message'
        Want ("$($c.state.nat.disabled)" -eq '1') 'NAT left on'
        Want ($c.log -match 'NAT rule switched back off') 'no switch-off message'
        Want ($c.log -match 'This run switched it on and has switched it off again') 'PARTLY message does not say what happened to NAT'
        Want (@(@($c.state.rules) | Where-Object { "$($_.enabled)" -eq '1' }).Count -eq 2) 'rules not kept' }
    Run-Case 'nat-validation' 'nat-validation' -Exit 2 -Check { param($c)
        Want ($c.log -match 'Enable NAT rule was not saved') 'no NAT save message'
        Want ("$($c.state.nat.disabled)" -eq '1') 'NAT changed'
        Want ($c.log -match 'did not pass\. It is still off\.') 'PARTLY message wrong for a NAT rule that never switched on'
        Want (@(@($c.state.rules) | Where-Object { "$($_.enabled)" -eq '1' }).Count -eq 2) 'rules not kept' }
    Run-Case 'nat-already-on' 'nat-already-on-ineffective' -Exit 2 -Check { param($c)
        Want ("$($c.state.nat.disabled)" -eq '0') 'NAT rule that was on before was switched off'
        Want (-not ($c.log -match 'after 70 s')) 'claims a 70 s wait that did not happen'
        Want ($c.log -match 'It was already on before this run and is left on') 'PARTLY message does not say NAT was left on' }
    Run-Case 'rollback' 'already-applied' -Mode Rollback -Exit 0 -Check { param($c)
        Want (@($c.state.rules).Count -eq 2) 'rules deleted'
        Want (@(@($c.state.rules) | Where-Object { "$($_.enabled)" -ne '0' }).Count -eq 0) 'a rule left enabled'
        Want ("$($c.state.nat.disabled)" -eq '1') 'NAT left on'
        Want ($c.log -match 'Rollback finished') 'no "Rollback finished"'
        Want (@($c.backups | Where-Object { $_ -like 'config-Rollback-after-*' }).Count -eq 1) 'no after backup' }
    Run-Case 'rollback-nothing-to-do' 'default' -Mode Rollback -Exit 0 -Check { param($c)
        Want (@($c.posts | Where-Object { $_.path -like '*set_rule*' }).Count -eq 0) 'something was changed'
        Want ($c.log -match 'Rollback finished') 'no "Rollback finished"' }
    
    } finally {
        # ---------- always stop the mock ----------
        try { $null = Invoke-RestMethod -Method POST -Uri "$Base/__test/stop" -TimeoutSec 5 } catch { }
        Start-Sleep -Milliseconds 500
        if (-not $mock.HasExited) { Stop-Process -Id $mock.Id -Force -ErrorAction SilentlyContinue }
    }
    
    $failed = @($Results | Where-Object { $_.Result -eq 'FAIL' }).Count
    $summary = "{0} cases, {1} passed, {2} failed. PowerShell {3}. Script SHA-256 {4}" -f $Results.Count, ($Results.Count - $failed), $failed, $PSVersionTable.PSVersion, $hash
    $Results | Format-Table -AutoSize | Out-String -Width 200 | Set-Content -LiteralPath (Join-Path $Run 'results.txt')
    Add-Content -LiteralPath (Join-Path $Run 'results.txt') -Value $summary
    Add-Content -LiteralPath (Join-Path $Run 'results.txt') -Value $Evidence
    Write-Host ''
    if ($failed -eq 0) { Write-Host $summary -ForegroundColor Green } else { Write-Host $summary -ForegroundColor Red }
    Write-Host "Details: $Run"
    if ($failed -gt 0) { exit 1 } else { exit 0 }
    
    Mutation check results
    Mutation check of opnsense-dns-bypass.v2.5.ps1 (SHA-256 df017f33269979e9...; 2.5.1 differs only in header comments) with Test-OpnsenseScript.v3.ps1 and mock-opnsense.v2.ps1
    PowerShell 7.4.6, 28/10/2026. Each line: a deliberately broken copy of the script, and the cases that then failed.
    no-undo                9 failed: alias-undo-enabled alias-wrong-type alias-validation alias-not-filling rule-validation rule-order doh-still-open https-broken fresh-alias-fails
    no-exit2               3 failed: nat-ineffective nat-validation nat-already-on
    no-json-guard          1 failed: empty-key-reply
    no-router-guard        1 failed: placeholder-router
    no-order-check         1 failed: rule-order
    no-https-guard         1 failed: http-router
    no-preflight           2 failed: allow-missing nat-missing
    no-trap                1 failed: empty-key-reply
    old-undo-content-only  1 failed: alias-undo-enabled
    old-backup-message     1 failed: small-backup-after
    Unbroken script: 30 cases, 30 passed.
    
  • The fix that let phishing names through

    The fix that let phishing names through

    In English

    On a Saturday in October I fixed four broken entries in my router’s DNS allowlist. A little over two weeks later I found that the fixed entries let through names on the threat feed built to look like the sites I meant to allow: a payment site’s domain followed by .https. and an unrelated domain, or a shop’s name with a hyphen where the dot should be. My router’s own tester passed them.

    The same evening I had cut my blocklists from eighteen to ten; an LG TV list the next day made it eleven. Seven of them were covered by the rest of the set. One list I kept, Abuse.ch ThreatFox, stopped downloading when abuse.ch began to give out its host file only with a key. It downloads again since I put a free key in its address. And the ads inside YouTube and Instagram on my phone came through throughout, which no blocklist was going to change.

    I then rewrote the allowlist entries. This post is about both clean-ups: what OPNsense does with an allowlist entry, how to check yours, and what eighteen overlapping lists added up to. I did the work with Claude over two sessions, one for each clean-up; the ThreatFox key went in during a third. It read the router through my browser; every change on the router was mine to approve. I approved the bare-name fix, so approval was no safeguard against that mistake.

    New to the command line? How to read the boxes

    PS> means: type this in PowerShell on Windows (Start menu → type powershell → Enter). $ means: type this in a terminal on Linux or a Mac, or on the Pi after you have logged in with ssh. Do not type the $ or PS> itself.

    Each line that starts with $ or PS> is one command. Click that $ to copy just that line, paste it, press Enter, and wait for it to finish before the next. A box with a Copy button at the top holds one command (or one file), so copy it whole. A dashed box shows what you should see back; you do not type it.

    The allowlist

    My blocklist policy’s allowlist had 26 entries. On the day of the first clean-up four of them looked broken. Three had been pasted from the browser’s address bar as full addresses, in the form https://example.org/. The fourth had one space before the first letter of the name. I replaced all four with bare names such as example.in. I did not look at how the other 22 were written, and the router’s configuration history no longer goes back far enough to check. If they were bare names, as the router’s own Allow button writes them, the gap was there before my fix, and the fix extended it to the three entries that had matched nothing.

    The router’s log showed a fifth, an entry written as *.ntp.org, since removed. Each nightly update had logged “skip invalid whitelist exclude pattern” for it. A leading * is not valid in Python’s regular expressions, so the router dropped the entry every night and said so only in the log. The form that does what was meant is (.*\.)?ntp\.org\.?$.

    Later Claude read the code that applies the allowlist, in OPNsense 26.7. The leading space had done no harm: the code strips spaces from each entry. The bare names were the problem.

    OPNsense treats each entry as a regular expression, case-insensitive, and checks it against the start of the name a device asks for. Nothing ties it to the end of the name, and an unescaped dot matches any character. So a bare example.com allows example.com but not www.example.com. It also allows any name that begins with those characters, with any character in place of each dot: example.com.evil.net, example-com.evil.net, example.community.

    The threat feed carries names of exactly that shape: a well-known site’s name followed by .https. and an unrelated domain, or the site’s name with a hyphen for the dot. On the feed as I downloaded it for this check, seven of my 26 entries matched 43 such names; one entry matched 20. On my router’s tester, each of the five such names I tried passed, while the same name with www. in front, blocked by the same list entry, was blocked. A name I made up from an allowed site and a domain the threat feed blocks passed too. By the matching code, every bare entry allows any name that begins with it, whether or not a list blocks that name.

    OPNsense’s own Allow button, in Reporting → Unbound DNS, saves the bare name in the same way. Entries added from there behave the same way.

    The fix is to allow the exact name, anchored at both ends:

    ^www\.example\.com\.?$

    The backslashes make the dots literal, and $ ties the pattern to the end of the name. \.? allows the trailing dot the name carries on one of the two paths the code checks (see the deep dive). ^ repeats what the code already does, so leaving it out would work too; I keep it so the pattern reads the same anywhere. The steps to check and rewrite your own entries are in the deep dives under “How to check yours”.

    To allow a domain with all its subdomains, (.*\.)?example\.com\.?$ works, but it also allows hosts the list blocks under that domain on purpose. On one of my entries, Pro++ blocks five hosts under the domain, with names such as advertising and sponsored-ads, and does not block the domain itself or its www. name. A subdomain-wide allow would let them back.

    I ran OPNsense’s own parsing code and its matching call on a few names:

    Allowlist entry Name asked for Allowed?
    https://example.org/ example.org no
    example.in example.in yes
    example.in www.example.in no
    example.in example.in.example.net yes
    example.in example-info.de yes
    ^www\.example\.in\.?$ www.example.in yes
    ^www\.example\.in\.?$ advertising.example.in no
    ^www\.example\.in\.?$ www.example.in.example.net no

    I rewrote all 26 entries in that exact, anchored form and applied the change. Every name that had passed the tester was blocked afterwards. The one entry whose own name is on a list still passes, as intended. The exact names in the other 25 were not blocked by any list, so those entries did no work for the names they spell; their only effect was the prefix gap. I anchored them instead of deleting them, because a list can add a name later. If you have entries like that, deleting them is a fair choice.

    Deep dive: the code, and what my tests do and do not show

    The blocklist dialog has one “Allowlist Domains” field. Its help text says it takes domains, that regular expressions may be used, and that it applies only to matches in that policy. In 26.7:

    • src/opnsense/service/templates/OPNsense/Unbound/core/blocklists.conf writes the field as excludes.patterns, comma-separated.
    • src/opnsense/scripts/unbound/blocklists/default_bl.py splits that value on commas, calls strip() on each entry, drops any entry that does not compile as a regular expression (with the “skip invalid” log line), and joins the rest, with a built-in .*localhost$ entry, into one pattern with |.
    • src/opnsense/scripts/unbound-dnsbl/lib/__init__.py compiles the pattern case-insensitively.
    • src/opnsense/scripts/unbound-dnsbl/lib/dnsbl.py tests it with r.match(domain) after a blocklist hit. Python’s match is anchored at the start of the name, not at the end. The name is lower-cased and its trailing dot removed first.
    • When a CNAME target is blocked, the same function also tests the original name (r.match(orig)), so an allowlisted name still resolves through a blocked alias. That original name comes from Unbound with its trailing dot, www.example.com., and is not cleaned. A pattern ending in a bare $ fails there; \.?$ passes on both paths.
    • src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php, updateBlocklistAction, is what the Allow button in Reporting calls. It removes a trailing dot (rtrim($domain, '.')) and saves the name as it is, unescaped and unanchored.

    OPNsense’s manual describes an allowlist entry as excluding blocklist items that contain the pattern. The code is narrower at the start, since it matches only from the first character, and just as open at the end. Under either reading, anchoring the end is left to the person writing the entry. I compared the same five files in the newest 26.7 release and in the development branch: the allowlist code is unchanged.

    What the tests show: how the parser and the matching calls in the 26.7 source treat these entries, run outside a router, with the CNAME case simulated by adding the trailing dot; and, on my router, the tester’s verdict for each phishing name I tried, beside a control that differs only in not beginning with an allowlisted name, before and after the rewrite. The tester runs the same matching code on the lists the router has loaded, but only for a direct lookup, so it cannot show the CNAME path. The count of 43 names comes from the published lists, not from the router; all 43 are on TIF.

    How to check yours

    Four checks, all read-only until the last one:

    1. Read the resolver log for lists that failed to download and allowlist entries that were skipped.
    2. In the blocklist tester, try a name that should be blocked and one that should pass, to see that the lists are loaded.
    3. For each allowlist entry, test the entry followed by a domain your lists block, then the same name with www. in front. If the first passes and the second is blocked, the entry is open.
    4. Rewrite each open entry anchored, apply, and test again.

    The click-by-click steps for checks 1 to 3 and for the rewrite are in the two deep dives below. They start from the sign-in page and say what each step changes.

    Deep dive: step by step, checking your allowlist

    Before you start. You need a browser on a computer in your network, and the address and login of your router’s settings page. Steps 1 to 8 only read: they change nothing on the router, so you can stop at any point without undoing anything. Allow about ten minutes, plus about ten seconds for each test, because the tester loads the whole blocklist every time.

    1. Open a browser and enter the address you use to sign in to OPNsense. Sign in. You should see the Lobby page. If the page does not load, check that the computer is on your home network and that you used the same address as for any other change to the router.
    2. In the menu on the left, click Services, then Unbound DNS, then Log File. You should see a table with the columns Date, Severity, Process and Line. Above it are a search box, a severity box (set to Warning) and a time box (set to Last day).
    3. Click the search box, type blocklist and press Enter. Two kinds of line matter. “unable to download blocklist” means a list failed to load and contributes nothing. “skip invalid whitelist exclude pattern” means OPNsense dropped an allowlist entry. If the table is empty, nothing at Warning level was logged in the last day. Open the severity box and tick Informational as well to see the “blocklist loaded” lines; open the time box to look further back.
    4. In the same menu click Blocklists, then the Tester tab at the top of the page. You should see a Domain box, a Source box and a Test button. Leave Source empty; the test then runs as the router itself. Source takes a device’s address, and matters only if you have a policy that applies to certain devices.
    5. Type googleads.g.doubleclick.net in Domain and click Test. Wait about ten seconds. The result should be Block. Then test www.youtube.com; it should be Pass. If the first name passes, no list is loaded, or the name is on your own allowlist: go back to step 3 and read the errors, and if you have allowlisted that name, pick another name your lists block. The tester does not follow CNAMEs. A CNAME is a name that points to another name; the tester checks only the name you type.
    6. Click the Blocklists tab. At the right end of your policy’s row, click the pencil (Edit). A window titled Edit Blocklist opens. Allowlist Domains shows your entries, one tag each. Read them, then click Cancel. Nothing is saved.
    7. For each entry, test the entry followed by a domain your lists block. A name my lists block is googleads.g.doubleclick.net, the one from step 5. If yours do not block it, pick a name they do. So for an entry example.com, type example.com.googleads.g.doubleclick.net and click Test. Then test the same name with www. in front, www.example.com.googleads.g.doubleclick.net. If you load TIF, you can use a name from that list instead. An entry that already starts with ^ and ends with $ is anchored; skip it.
    8. Read the two results together. If the first passes and the second is blocked, the entry is open: it lets through every name that begins with it. Rewrite it anchored. A name that no list blocks passes whatever the allowlist says, so confirm in the tester that the name is blocked before you read a Pass as a fault.
    Deep dive: step by step, rewriting your allowlist

    Before you start. This changes your router’s filtering. Allow fifteen minutes. A mistake here most often shows as one allowed site failing to load. The rest of your internet should keep working. The router applies the change in about a minute (43 seconds on mine) and does not restart Unbound; the log shows the lists loading into the running process. Step 3 saves a copy of your old entries, and step 8 puts them back.

    1. Open the router’s settings page and sign in. Click Services, then Unbound DNS, then Blocklists.
    2. At the right end of your policy’s row, click the pencil (Edit). The Edit Blocklist window opens. Under Allowlist Domains, click Text, the small link under the box. The tags turn into a plain box with one entry per line, and a Back link appears. If you have more than one policy, each has its own allowlist; do this for each.
    3. Make the undo copy. Click inside the box, press Ctrl + A, then Ctrl + C. Open Notepad (Start menu, type notepad, press Enter), press Ctrl + V, and save the file as allowlist-before.txt in a folder you will find again. The file should hold one entry per line.
    4. Rewrite each line in the box. This is for plain names; an entry that is already a pattern, such as one containing (.*\.)?, stays as it is. Write the exact name your devices ask for. Put a \ before every dot, ^ at the start and \.?$ at the end:

      • example.in becomes ^example\.in\.?$
      • www.example.com becomes ^www\.example\.com\.?$

      Keep one entry per line, with no spaces and no commas. A name with www. and the same name without it are two names and need two lines. If you are not sure which one a device asks for, look in Reporting, Unbound DNS, or put both on the list.

    5. Click Back. The lines return as tags. Check that every tag has the new form. Click Save. The window closes.

    6. Click Apply, the orange button under the table. Wait about a minute.
    7. Check the result. Open Services, Unbound DNS, Log File, search for blocklist, and tick Informational in the severity box. You should see “updating blocklist”, then “blocklist loaded. length is” and a number, and no “skip invalid” line. Then repeat the tester steps from above: the lookalike names should now be Block. An entry that allows a name a list blocks (on mine, one for a Google ad host) should still be Pass.
    8. If a site stops loading after the change, undo it. Open allowlist-before.txt in Notepad, press Ctrl + A, then Ctrl + C. In the router, repeat steps 1 and 2, click inside the box, press Ctrl + A, then Ctrl + V to paste the old entries over the new ones, click Back, Save and Apply. A site that needs a name you did not list is blocked until you add that exact name.
    Deep dive: testing an allowlist change from a computer

    Before you start. This is for a Windows PC in the same network as the router. It asks the router’s DNS for one name and clears the PC’s own DNS cache; it changes nothing else. It takes two minutes. On a Mac or Linux the idea is the same (nslookup name router-address), but the cache-clearing command differs.

    1. Click the Start menu, type powershell and press Enter. A window opens with a prompt that starts with PS.
    2. Find the router’s address. Type this and press Enter:

      ipconfig

      Look for Default Gateway under the adapter you are using. That address is your router; the steps below call it <router-ip>. If your router sits behind another router, the default gateway may be that other device; use the address of the box that runs your DNS blocklists. If the line is empty, you are looking at an adapter that is not connected; scroll to the next one.

    3. After you click Apply on the router and wait a minute, clear the PC’s cache. Blocked answers carry a one-hour lifetime, so without this the PC may keep an old answer:

      ipconfig /flushdns
    4. Ask the router for the name, replacing <router-ip> with the address from step 2. The final dot after the name stops Windows trying its search suffixes first:

      nslookup www.example.com. <router-ip>

      A blocked name answers 0.0.0.0, or “Non-existent domain” if Return NXDOMAIN is ticked on the policy. A name that is allowed answers with its real address. The first two lines show your router; the rest is the answer.

    What eighteen lists added up to

    In the router’s resolver log, from its first entry until the first clean-up, every full nightly update was set to load the same eighteen lists (ThreatFox among them, see below):

    • Hagezi Normal, plus the Mini versions of Pro, Pro++ and Ultimate
    • Threat Intelligence Feeds (TIF) in all three sizes: full, Medium and Mini
    • Gambling in all three sizes
    • Fake, Pop-Up Ads, Badware Hoster, DynDNS, Anti Piracy and “Safesearch not supported”
    • OISD NSFW and Abuse.ch ThreatFox

    Hagezi, who maintains most of these, gives these rules for combining his lists in his FAQ:

    1. The five Multi lists — Light, Normal, Pro, Pro++ and Ultimate — build on each other. Each contains the one below it. You pick one.
    2. The size-optimised versions (Mini, and Medium for TIF and Gambling) are alternatives to their full list. They do not go on top of it.
    3. TIF is the exception. It covers malware, cryptojacking, scams, spam and phishing and is meant to run alongside whichever tier you pick.

    The Pro, Pro++, Ultimate and Gambling Minis keep only the names that also appear on lists of the most-visited domains. TIF Mini and Gambling Mini are cut from the Medium list. Hagezi describes the Minis as made for blockers on devices with limited memory.

    Deep dive: which tier for whom, and what Ultimate costs

    Hagezi’s FAQ matches the tiers to the person who will deal with breakage:

    Tier For Risk of breakage (Hagezi’s rating)
    Light a blocker that cannot handle big lists, or a setting where even Normal is too much minimal
    Normal unattended setups with no admin to unblock things low
    Pro someone can unblock things; his default recommendation, with TIF low to moderate
    Pro++ experienced users with an admin moderate
    Ultimate very experienced users with an admin available high

    Each tier also carries a share of the native tracker lists: the telemetry built into TVs, phones and operating systems. Pro++ blocks nearly all of it; Ultimate blocks all of it. The README lists what Ultimate costs: some Facebook and Messenger functions, WhatsApp extras such as avatars and video effects, Windows Spotlight and Xbox achievement history, and location trackers some sites rely on, which can bring wrong regional settings and more CAPTCHAs.

    My set broke the first two rules. I downloaded the lists once for this check and compared them name by name, to see which entries one list already blocks in another. I do not have the copies the router loaded earlier, and I did not measure ThreatFox, so seventeen lists were measured.

    Seven of the seventeen were covered by the rest of the set, apart from each list’s one marker entry: Pro Mini, Pro++ Mini, TIF Medium, TIF Mini, Gambling Medium, Gambling Mini and Fake. Dropping all seven together would have lost 15 names that TIF Medium and Mini carry and the full TIF does not. Pop-Up Ads added 37 names of its 48,277 to the rest of the set (against Pro++ alone it adds three, below). DynDNS and Anti Piracy were different: on those lists they carried about 1,200 and about 55,000 names that no other list in the set did, and I dropped them by choice, not as duplicates.

    The four tier lists together held 233,710 names, all but Hagezi’s four marker entries in Ultimate. Against Pro++ on its own, they missed 31,411 Pro++ entries, the ones not on the most-visited lists. In their place they carried 25,040 entries that only Ultimate blocks (25,041 with the Ultimate Mini marker), all from the most-visited lists. Hagezi rates Ultimate’s risk of breakage high. I kept no record of breakage from them and did not test for it, but by Hagezi’s rating the mix took on Ultimate’s risk and lacked Pro++’s coverage.

    Deep dive: how I measured, and why a plain comparison gets it wrong

    OPNsense uses Hagezi’s wildcard format, where a line such as *.example.com blocks example.com and every name under it. So an entry in list A is already blocked by list B if B holds the entry or any of its parent domains.

    A plain text comparison misses that. comm reports 3,294 Pro++ Mini entries that are “not in” Ultimate Mini. All but one of them are covered, because Ultimate Mini blocks a parent domain instead. It has one line for the whole of omtrdc.net, an Adobe tracking domain, where Pro++ Mini lists 998 of its hosts one by one. The one left over is Hagezi’s marker entry, explained below.

    The four tier lists, measured the same way:

    Normal + Pro Mini + Pro++ Mini + Ultimate Mini
    Unique names 233,710
    Of those, also in Ultimate all but 4 (Hagezi’s marker entries)
    Pro++ entries missing from the mix 31,411 of 223,551
    Names in the mix that only Ultimate blocks 25,040

    The check I used walks up the parent domains. It is a Python 3 script with nothing to install beyond Python itself. The script comes first; the steps after it say how to save and run it.

    #!/usr/bin/env python3
    """hagezi_overlap.py - how much of blocklist A is already blocked by blocklist B.
    
    Reads two Hagezi lists in the wildcard format (the /wildcard/ files, the format
    OPNsense uses). A line "*.example.com" blocks example.com and every name under
    it, so an entry of A counts as covered when the entry itself, or one of its
    parent domains, is in B. A plain text comparison (comm, diff) misses that and
    reports too many differences.
    
    Usage:  python3 hagezi_overlap.py A.txt B.txt
    Author: Vivek Sanghi. Licence: CC BY-NC-SA 4.0, as the blog.
    """
    import re
    import sys
    
    WILDCARD = re.compile(r"^\*\.[a-z0-9_-]+(\.[a-z0-9_-]+)+$")
    
    
    def load(path):
        names = set()
        try:
            f = open(path, encoding="utf-8-sig")
        except OSError as e:
            sys.exit(f"{path}: cannot open ({e.strerror})")
        with f:
            for number, line in enumerate(f, 1):
                line = line.strip().lower()
                if not line or line.startswith("#"):
                    continue
                if not WILDCARD.match(line):
                    sys.exit(f"{path}, line {number}: not a wildcard-format line "
                             "('*.example.com'). Download the /wildcard/ version of the list.")
                names.add(line[2:])
        if not names:
            sys.exit(f"{path}: no entries found; check the download")
        return names
    
    
    def covered(name, blocked):
        while True:
            if name in blocked:
                return True
            if "." not in name:
                return False
            name = name.split(".", 1)[1]
    
    
    def main():
        if len(sys.argv) != 3:
            sys.exit("usage: hagezi_overlap.py A.txt B.txt")
        a, b = load(sys.argv[1]), load(sys.argv[2])
        missing = sorted(n for n in a if not covered(n, b))
        print(f"{sys.argv[1]}: {len(a):,} entries; {len(a) - len(missing):,} already "
              f"blocked by {sys.argv[2]}; {len(missing):,} not")
        for n in missing[:10]:
            print(f"  not covered: {n}")
        if len(missing) > 10:
            print(f"  ... and {len(missing) - 10:,} more")
    
    
    if __name__ == "__main__":
        main()
    

    Before you start. This is for a Windows PC. You need Python 3 (step 3 checks). The steps create one folder in your user folder, download two list files of a few megabytes into it, and read them; they change nothing else. Allow ten minutes. To undo, delete the folder in File Explorer. On a Mac or Linux, use Terminal, python3 instead of py, and curl instead of curl.exe.

    1. Click the Start menu, type powershell and press Enter. A window opens with a prompt that starts with PS.
    2. Make a folder and move into it. Each line takes a moment; run them one at a time:

      mkdir hagezi-check
      cd hagezi-check

      The prompt should now end with hagezi-check. If the first line says the folder already exists, pick another name and use it in both lines.

    3. Check that Python is installed:

      py --version

      You should see a line such as Python 3.12.4. If PowerShell says it does not recognise py, install Python 3 from python.org (tick “Add python.exe to PATH” in the installer), close PowerShell and start again at step 1.

    4. Create the script file. This opens Notepad:

      notepad hagezi_overlap.py

      Notepad asks whether to create a new file; click Yes. Paste the script from the box above (click Copy on the box, then Ctrl + V in Notepad), press Ctrl + S, and close Notepad. If Notepad opens without asking, save with File, Save as, type hagezi_overlap.py in quotation marks as the file name, make sure the folder is hagezi-check, and click Save.

    5. Download two lists into the folder. On Windows, type curl.exe, not curl, in PowerShell. Run the lines one at a time:

      curl.exe -o pro.plus.mini.txt https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/pro.plus.mini.txt
      curl.exe -o ultimate.mini.txt https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/ultimate.mini.txt

      Each takes a few seconds and prints a progress table. If a line ends with an error, check the connection and run that line again.

    6. Run the check:

      py hagezi_overlap.py pro.plus.mini.txt ultimate.mini.txt
    7. On the lists I downloaded for this check it printed:

      pro.plus.mini.txt: 98,704 entries; 98,703 already blocked by ultimate.mini.txt; 1 not
        not covered: h4g3z1-pro-plus-mini.web.app

      Your numbers will differ, because the lists change daily. If you see a message instead of numbers, the script stopped on purpose: read the message, since it names the file and the line.

    The one name left over in each comparison is a marker Hagezi puts in every list (h4g3z1-<list>.web.app), so you can tell which list is loaded. If a download fails, or the file is in another format, the script stops and says so instead of reporting a number.

    What else it gave, on the same lists:

    List A List B Entries of A already blocked by B
    Normal (171,454) Pro++ all but the marker
    Pro++ (223,551) Ultimate all but the marker
    Pro Mini (86,842) Ultimate Mini all but the marker
    TIF Mini (212,777) TIF Medium all but the marker
    Gambling Mini (118,888) Gambling Medium all but the marker
    Fake (17,622) Pro++ all but the marker
    Pop-Up Ads (48,277) Pro++ all but 4 (the marker and 3 others)
    Badware Hoster (1,088) Pro++ 966
    Ultimate Mini (120,458) Pro++ 95,417

    The script was tested on these lists and on a missing file, an empty file, a comments-only file, a failed download, a web page, and lists in the adblock, hosts and plain-domain formats.

    The count of names loaded did not follow my changes. On the day of the first clean-up the router loaded 2,840,117 names before it and 3,188,234 after it, with ten lists instead of eighteen: between two downloads that day, TIF had grown by 426,519 entries. With no change on my side, the count then moved from 2,739,044 to 3,229,041 in four days. On the list sizes I downloaded for this check, about two-thirds of the names were on TIF and about 7 per cent on Pro++.

    Deep dive: the router’s figures, with their caveats

    Names loaded, from the router’s log (“blocklist loaded. length is …”, the number of unique names):

    When Lists Names loaded
    First clean-up day, before the eighteen 2,840,117
    First clean-up day, after the new set 3,188,234
    Five days later same set 2,739,044
    Nine days later same set 3,229,041
    Eighteen days later same set 3,198,953

    Share of queries blocked, from Reporting → Unbound DNS:

    Window Queries Blocked
    First clean-up day, as read that day not recorded 12.9 per cent
    A window of about 38 hours, read later 110,248 8,600 (7.80 per cent)

    The two percentages cover different lists, different days and whatever the network happened to be doing. They are not a before and after.

    What I tick now

    My router’s settings show:

    • Hagezi Pro++ (full)
    • TIF (full)
    • Gambling (full)
    • Fake, Pop-Up Ads, Badware Hoster and “Safesearch not supported”
    • OISD NSFW
    • two Hagezi lists by URL: encrypted-DNS servers and LG TV trackers
    • Abuse.ch ThreatFox, by URL, with a free key (below)

    I chose Pro++ over Hagezi’s recommended Pro for device trackers, since Pro++ is where he blocks nearly all of them.

    Two of these are duplicates. Hagezi’s cheat sheet marks Fake and Pop-Up Ads as inside Pro++. For Fake the measurement agrees, and it can come off with no change to what is blocked. Pop-Up Ads has three names, on the lists I downloaded, that none of Pro++, TIF, Gambling, Hoster or Fake carries; dropping it costs those three. I did not compare ThreatFox or the two URL lists. Fake and Pop-Up Ads are both still ticked.

    ThreatFox stopped downloading and now downloads again. Each update had logged “unable to download blocklist … and no cache available”. The address OPNsense’s built-in entry used for it answers “410 Gone”, and abuse.ch’s export page asks for an Auth-Key before it gives out the host file. A later 26.7 release removed the built-in entry for that reason and points users to “URLs of Blocklists”. abuse.ch issues the key free through its authentication portal. I added the list by URL with the key in the address. abuse.ch’s export page asks for the key in the URL, and OPNsense’s downloader sends no headers. The steps below show the form of the address. The update that added it logged “blocklist download” with 28,889 lines for it, 28,869 of them names, and no error; the other lists loaded from cache in that update. By the router’s own count of loaded names, it rose from 2,765,172 to 2,782,246. So 17,074 of the 28,869 were not already loaded under that exact name, and about 11,800 were. The count compares names literally, so a name whose parent domain another list already blocks counts as new. Hagezi does not name ThreatFox as a source.

    The key works like a password. The router stores it in its configuration, and each update writes the address, key included, to the resolver log. Keep it out of screenshots, shared logs, configuration backups and any remote log server that leave your hands. If it has leaked, get a new key from the same portal and change the address.

    Deep dive: adding ThreatFox with a key

    Before you start. This adds one list to your policy. Allow ten minutes. Nothing is deleted. To undo it, remove the address from the same box and apply again.

    1. In a browser, open https://auth.abuse.ch, create an account if you have none, and get an Auth-Key. The key is free. Copy it into a text file only until step 4, where you paste it once, then delete the file.
    2. Log in to the router. Click Services, then Unbound DNS, then Blocklists.
    3. At the right end of your policy’s row, click the pencil (Edit). A window titled Edit Blocklist opens.
    4. Click inside URLs of Blocklists and type the address below, with your key in place of YOUR_KEY and no spaces. Press Enter so it becomes a tag of its own (a tag is one entry shown as a small box in the field):

      https://threatfox-api.abuse.ch/v2/files/exports/YOUR_KEY/hostfile.txt

      The key sits between exports/ and /hostfile.txt.

    5. Click Save, then Apply. The router downloads the lists again; allow a minute or two.

    6. Click Services, Unbound DNS, Log File, search for download, and tick Informational in the severity box. You should see “blocklist download:” and a number of lines for the ThreatFox address. If the line says “unable to download”, check the key and the address for a stray space.
    7. Do not share that screen: the line shows the address with your key.
    Deep dive: Badware Hoster and the two lists added by URL

    Badware Hoster is a standalone Hagezi list, and 966 of its 1,088 entries are already in Pro++. The rest blocks whole hosting providers that keep turning up in threat feeds. Hagezi warns that legitimate sites on those hosts are blocked with them, and leaves unblocking them to whoever runs the list.

    The two lists added by URL are Hagezi’s, in the wildcard format:

    https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/doh.txt
    https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/native.lgwebos.txt

    The first lists encrypted-DNS servers by name, part of stopping devices from going around the router. The second lists LG webOS ad and tracking servers. Each has its own story, for separate posts.

    The built-in Hagezi tick-boxes in OPNsense 26.7 download from Hagezi’s mirror, hagezi-mirror.dnsbunker.org, as the log shows. Hagezi says that mirror publishes a new build roughly every four to eight hours; the jsDelivr copies update once a day.

    What DNS cannot block

    In-app YouTube and Instagram ads come from the same domains as the videos and posts, so blocking them by name would block the content. Hagezi’s FAQ makes the general point: some ads load from the same domains as the content, and a content blocker in the browser, or an app-level blocker on a phone, is the layer that catches them. I accepted the in-app ads.

    A DNS blocklist also filters only the devices that ask the router; devices with their own encrypted or hard-coded DNS go around it. That is a separate post.

    How this was done

    Claude read the documentation and the lists, compared them, and read my router through my logged-in browser session: settings, the resolver log and the tester. I decided what to change. In the allowlist session the only change on the router was the allowlist rewrite.

    The model got things wrong. The bare-name allowlist fix came out of the first session, and in one of the sessions it also told me the nightly blocklist update flushes Unbound’s cache. The router’s log showed the update loading the lists into the running Unbound, with no restart. The manual says applying blocklist settings does not restart Unbound, and the source loads the new list into the running process. The flush setting applies only when Unbound stops.

    A model with a logged-in session on a router is a risk of its own. The resolver log it reads holds names that any website can make a device look up, and a name can carry text written to steer a model. In the allowlist session I kept it to reading, apart from the allowlist change. That is an instruction to the model, not a control; a read-only OPNsense user would be one. The resolver log also holds the ThreatFox address with its key, so a session that reads the log sees the key. If you let a model read that log, replace the key afterwards.

    In the first session I also changed five Unbound settings and one cron job. The router shows all six as set.

    Deep dive: each setting, and how to undo DNS over TLS
    Setting (page) Before After
    Flush DNS Cache during reload (General) on off
    Prefetch Support (Advanced) off on
    Serve Expired Responses (Advanced) off on; TTL for Expired Responses 86,400 s
    Use System Nameservers (Query Forwarding) on off
    DNS over TLS forwarders none Cloudflare and Quad9
    Blocklist update job (System → Settings → Cron) a slot shared with other jobs a slot of its own

    Prefetch refreshes popular entries before they expire. The manual puts the cost at about 10 per cent more DNS traffic.

    Serve Expired Responses answers from cache with an expired record instead of making the device wait. When it is on, more fields appear. “TTL for Expired Responses” limits how long after expiry a stale answer may be served; I set 86,400 seconds, the low end of the manual’s suggested 86,400 to 259,200.

    One interaction I have not tested: with cache flushing off and stale answers allowed, a name that a list newly blocks may go on being answered from Unbound’s cache for a while. If a block does not take effect at once, that is the first thing I would look at.

    Use System Nameservers. The manual says the system nameservers are preferred over any catch-all entry in Query Forwarding and DNS over TLS. Turning it off lets the DNS over TLS entries carry the queries. The four entries, under Services → Unbound DNS → DNS over TLS:

    Server IP Port Verify CN
    1.1.1.1 853 cloudflare-dns.com
    1.0.0.1 853 cloudflare-dns.com
    9.9.9.9 853 dns.quad9.net
    149.112.112.112 853 dns.quad9.net

    The router’s own queries to these servers leave encrypted. A firewall rule that rejects port 853 from the LAN, to stop devices using their own encrypted DNS, does not touch them, because they leave from the router itself.

    The update time moved to a slot of its own so the update no longer shares a time with other scheduled jobs.

    To undo the DNS over TLS change:

    Before you start. This changes your router’s DNS settings and takes five minutes. DNS keeps working through the settings that remain. Note the four entries first (the table above); you need them to put the change back.

    1. Open the router’s settings page and sign in. You should see the Lobby page.
    2. Click Services, then Unbound DNS, then DNS over TLS. A table lists the entries.
    3. At the right end of the first row, click the pencil (Edit). A window titled Edit server opens. Untick Enabled and click Save. Do the same for each of the other rows.
    4. At the top of the same page, tick Use System Nameservers. The same box appears under Query Forwarding; it is one setting.
    5. Click Apply at the bottom of the page. Unbound reloads in a few seconds.
    6. Check: from a device on the network, open any website you have not visited today. It should load. If System, Settings, General has no nameservers, Unbound resolves from the root servers itself instead of forwarding; add your provider’s servers there if you want them used.
    7. To put the change back, tick Enabled on each entry again, untick Use System Nameservers, and click Apply.

    Sources

    वह fix जिसने phishing नाम निकल जाने दिए

    अंग्रेज़ी मूल से अनुवादित। Commands, code और technical terms अंग्रेज़ी में ही रखे गए हैं।

    अक्टूबर के एक शनिवार को मैंने अपने router की DNS allowlist की चार टूटी हुई एंट्री ठीक कीं। दो हफ़्ते से कुछ ज़्यादा बाद मुझे पता चला कि ठीक की गई उन एंट्री ने threat feed के ऐसे नाम निकल जाने दिए, जो उन्हीं साइटों जैसे दिखने के लिए बनाए गए थे जिन्हें मैं allow करना चाहता था: किसी भुगतान वाली साइट का domain, उसके बाद .https. और कोई असंबंधित domain, या किसी दुकान का नाम जिसमें dot की जगह hyphen हो। मेरे router के अपने tester ने इन्हें पास कर दिया।

    उसी शाम मैंने अपनी blocklist अठारह से घटाकर दस कर दी थीं; अगले दिन LG TV की एक सूची जुड़ने से ग्यारह हो गईं। इनमें से सात बाकी सेट में पहले से शामिल थीं। जो एक सूची मैंने रखी, Abuse.ch ThreatFox, वह तब download होना बंद हो गई जब abuse.ch ने अपनी host file सिर्फ़ key के साथ देना शुरू किया। मैंने उसके address में एक free key डाली, तब से वह फिर download होती है। और मेरे फ़ोन पर YouTube और Instagram के भीतर के ads पूरे समय आते रहे, जिसे कोई blocklist बदल नहीं सकती थी।

    फिर मैंने allowlist की एंट्री दोबारा लिखीं। यह पोस्ट दोनों सफ़ाई के बारे में है: OPNsense allowlist की एंट्री के साथ क्या करता है, अपनी एंट्री कैसे जाँचें, और अठारह आपस में मिलती सूचियों का जोड़ क्या निकला। यह काम मैंने Claude के साथ दो sessions में किया, हर सफ़ाई के लिए एक; ThreatFox की key तीसरे session में डाली गई। उसने मेरे browser के ज़रिए router को पढ़ा; router पर हर बदलाव मेरी मंज़ूरी से हुआ। मैंने bare नाम वाला fix मंज़ूर किया था, इसलिए उस गलती के मामले में मंज़ूरी कोई सुरक्षा नहीं थी।

    Command line में नए हैं? इन boxes को कैसे पढ़ें

    PS> का मतलब है: इसे Windows पर PowerShell में type करें (Start menu → powershell type करें → Enter)। $ का मतलब है: इसे Linux या Mac के terminal में type करें, या Pi पर ssh से log in करने के बाद। $ या PS> को खुद type न करें।

    $ या PS> से शुरू होने वाली हर लाइन एक command है। सिर्फ़ उस लाइन को copy करने के लिए उस $ पर click करें, उसे paste करें, Enter दबाएँ, और अगले से पहले उसके पूरा होने का इंतज़ार करें। जिस box के ऊपरी हिस्से में Copy button है, वह एक command (या एक file) रखता है, इसलिए उसे पूरा copy करें। डैश वाली रेखाओं (- – -) से बना box दिखाता है कि आपको जवाब में क्या दिखना चाहिए; उसे आप type नहीं करते।

    Allowlist

    मेरी blocklist policy की allowlist में 26 एंट्री थीं। पहली सफ़ाई के दिन उनमें से चार टूटी हुई लगीं। तीन browser की address bar से पूरे address के रूप में चिपकाई गई थीं, जैसे https://example.org/। चौथी में नाम के पहले अक्षर से पहले एक space था। मैंने चारों को example.in जैसे bare नामों से बदल दिया। बाकी 22 कैसे लिखी गई थीं, यह मैंने नहीं देखा, और router की configuration history अब इतनी पीछे नहीं जाती कि जाँच हो सके। अगर वे bare नाम थीं, जैसे router का अपना Allow button लिखता है, तो यह कमी मेरे fix से पहले भी थी, और fix ने उसे उन तीन एंट्री तक बढ़ा दिया जो पहले किसी चीज़ से मेल नहीं खाती थीं।

    Router के log में पाँचवीं एंट्री दिखी, *.ntp.org के रूप में लिखी हुई, जो अब हटा दी गई है। हर रात के update ने उसके लिए “skip invalid whitelist exclude pattern” लिखा था। Python की regular expressions में शुरू का * मान्य नहीं है, इसलिए router हर रात वह एंट्री छोड़ देता था और इसकी सूचना सिर्फ़ log में देता था। जो रूप वही करता है जो मैं चाहता था, वह है (.*\.)?ntp\.org\.?$।

    बाद में Claude ने वह code पढ़ा जो allowlist लागू करता है, OPNsense 26.7 में। शुरू के space से कोई नुकसान नहीं हुआ था: code हर एंट्री से space हटा देता है। समस्या bare नामों की थी।

    OPNsense हर एंट्री को regular expression मानता है, case-insensitive, और उसे उस नाम की शुरुआत से मिलाता है जो कोई device पूछता है। कुछ भी उसे नाम के अंत से नहीं बाँधता, और बिना escape किया हुआ dot किसी भी अक्षर से मेल खाता है। इसलिए सिर्फ़ example.com लिखने पर example.com allow होता है, पर www.example.com नहीं। साथ ही वह हर उस नाम को allow करता है जो इन्हीं अक्षरों से शुरू हो, हर dot की जगह कोई भी अक्षर रखकर: example.com.evil.net, example-com.evil.net, example.community।

    Threat feed में ठीक इसी आकार के नाम हैं: किसी जाने-माने साइट का नाम, उसके बाद .https. और कोई असंबंधित domain, या dot की जगह hyphen वाला साइट का नाम। इस जाँच के लिए मैंने जो feed download किया, उस पर मेरी 26 एंट्री में से सात ऐसे 43 नामों से मेल खाती थीं; एक एंट्री 20 से। मेरे router के tester पर, ऐसे जो पाँच नाम मैंने आज़माए, हर एक पास हुआ, जबकि blocklist की उसी एंट्री से block होने वाला वही नाम, आगे www. लगाकर, block हो गया। मैंने खुद एक नाम बनाया, एक allow की गई साइट और एक ऐसे domain से जिसे threat feed block करता है; वह भी पास हुआ। Matching code के अनुसार, हर bare एंट्री उस हर नाम को allow करती है जो उससे शुरू होता है, चाहे कोई सूची उस नाम को block करे या न करे।

    OPNsense का अपना Allow button, Reporting → Unbound DNS में, bare नाम को उसी तरह save करता है। वहाँ से जोड़ी गई एंट्री भी उसी तरह चलती हैं।

    इसका हल है ठीक वही नाम allow करना, दोनों सिरों पर anchor के साथ:

    ^www\.example\.com\.?$

    Backslash dot को सिर्फ़ dot ही रहने देते हैं, किसी भी अक्षर से मेल खाने वाला नहीं, और $ pattern को नाम के अंत से बाँध देता है। \.? वह अंतिम dot allow करता है जो code की जाँच के दो रास्तों में से एक पर नाम में रहता है (गहराई वाला हिस्सा देखें)। ^ वही दोहराता है जो code पहले से करता है, इसलिए उसे छोड़ने पर भी काम चलेगा; मैं उसे रखता हूँ ताकि pattern कहीं भी एक जैसा दिखे। अपनी एंट्री जाँचने और दोबारा लिखने के steps “अपनी एंट्री कैसे जाँचें” के नीचे के ‘गहराई में’ वाले हिस्सों में हैं।

    किसी domain को उसके सभी subdomains के साथ allow करने के लिए (.*\.)?example\.com\.?$ चलता है, पर वह उन hosts को भी allow कर देता है जिन्हें सूची उसी domain के नीचे जान-बूझकर block करती है। मेरी एक एंट्री पर, Pro++ उस domain के नीचे पाँच hosts block करती है, advertising और sponsored-ads जैसे नामों वाले, और domain को या उसके www. नाम को block नहीं करती। पूरे subdomain वाला allow उन्हें वापस आने देगा।

    मैंने OPNsense का अपना parsing code और उसकी matching call कुछ नामों पर चलाई:

    Allowlist एंट्री पूछा गया नाम Allow हुआ?
    https://example.org/ example.org नहीं
    example.in example.in हाँ
    example.in www.example.in नहीं
    example.in example.in.example.net हाँ
    example.in example-info.de हाँ
    ^www\.example\.in\.?$ www.example.in हाँ
    ^www\.example\.in\.?$ advertising.example.in नहीं
    ^www\.example\.in\.?$ www.example.in.example.net नहीं

    मैंने सभी 26 एंट्री उसी सटीक, anchor वाले रूप में दोबारा लिखीं और बदलाव apply किया। जो हर नाम tester से पास हुआ था, वह बाद में block हुआ। जिस एंट्री का अपना नाम किसी सूची में है, वह आज भी पास होती है, जैसा चाहा था। बाकी 25 के सटीक नाम किसी सूची ने block नहीं किए थे, इसलिए उन एंट्री का अपने नामों के लिए कोई काम नहीं था; उनका एकमात्र असर prefix वाली कमी था। मैंने उन्हें हटाने की जगह anchor किया, क्योंकि कोई सूची बाद में कोई नाम जोड़ सकती है। अगर आपके पास ऐसी एंट्री हैं, तो उन्हें हटाना भी ठीक विकल्प है।

    गहराई में: code, और मेरे tests क्या दिखाते हैं और क्या नहीं

    Blocklist dialog में एक ही “Allowlist Domains” field है। उसके help text में लिखा है कि वह domains लेता है, regular expressions इस्तेमाल हो सकती हैं, और वह सिर्फ़ उसी policy के matches पर लागू होता है। 26.7 में:

    • src/opnsense/service/templates/OPNsense/Unbound/core/blocklists.conf इस field को excludes.patterns के रूप में, comma से अलग करके लिखता है।
    • src/opnsense/scripts/unbound/blocklists/default_bl.py उस value को commas पर बाँटता है, हर एंट्री पर strip() बुलाता है, जो एंट्री regular expression के रूप में compile नहीं होती उसे छोड़ देता है (“skip invalid” log लाइन के साथ), और बाकी को, एक built-in .*localhost$ एंट्री के साथ, | से जोड़कर एक pattern बना देता है।
    • src/opnsense/scripts/unbound-dnsbl/lib/__init__.py pattern को case-insensitive रूप में compile करता है।
    • src/opnsense/scripts/unbound-dnsbl/lib/dnsbl.py blocklist hit के बाद उसे r.match(domain) से जाँचता है। Python का match नाम की शुरुआत पर anchored है, अंत पर नहीं। नाम पहले lower-case किया जाता है और उसका अंतिम dot हटाया जाता है।
    • जब किसी CNAME target को block किया जाता है, वही function मूल नाम को भी जाँचता है (r.match(orig)), इसलिए allowlist किया हुआ नाम blocked alias के रास्ते भी resolve हो जाता है। वह मूल नाम Unbound से अंतिम dot के साथ आता है, www.example.com., और साफ़ नहीं किया जाता। सिर्फ़ $ पर ख़त्म होने वाला pattern वहाँ fail होता है; \.?$ दोनों रास्तों पर पास होता है।
    • src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php, updateBlocklistAction, वही है जिसे Reporting का Allow button बुलाता है। वह अंतिम dot हटाता है (rtrim($domain, '.')) और नाम को जैसा है वैसा save कर देता है, बिना escape और बिना anchor के।

    OPNsense की manual allowlist एंट्री को ऐसा बताती है जो उन blocklist items को बाहर करती है जिनमें pattern आता है। Code शुरुआत पर इससे संकरा है, क्योंकि वह सिर्फ़ पहले अक्षर से मिलाता है, और अंत पर उतना ही खुला है। दोनों तरह पढ़ने पर अंत को anchor करना एंट्री लिखने वाले पर छोड़ा गया है। मैंने यही पाँच files 26.7 की सबसे नई release में और development branch में मिलाईं: allowlist code वैसा ही है।

    Tests क्या दिखाते हैं: 26.7 source का parser और matching calls इन एंट्री को कैसे लेते हैं, router के बाहर चलाकर, CNAME वाला मामला अंतिम dot जोड़कर simulate किया हुआ; और, मेरे router पर, मैंने जो हर phishing नाम आज़माया उसके लिए tester का फ़ैसला, एक control के बगल में जो सिर्फ़ इसमें अलग है कि वह allowlist की किसी एंट्री से शुरू नहीं होता, rewrite से पहले और बाद। Tester वही matching code उन सूचियों पर चलाता है जो router ने load की हैं, पर सिर्फ़ सीधे lookup के लिए, इसलिए वह CNAME वाला रास्ता नहीं दिखा सकता। 43 नामों की गिनती प्रकाशित सूचियों से आती है, router से नहीं; सभी 43 TIF पर हैं।

    अपनी एंट्री कैसे जाँचें

    चार जाँचें, आख़िरी को छोड़कर सब सिर्फ़ पढ़ने वाली:

    1. Resolver log में देखें कि कौन-सी सूचियाँ download नहीं हुईं और कौन-सी allowlist एंट्री छोड़ी गईं।
    2. Blocklist tester में एक ऐसा नाम आज़माएँ जो block होना चाहिए और एक जो पास होना चाहिए, ताकि दिखे कि सूचियाँ load हैं।
    3. हर allowlist एंट्री के लिए, एंट्री के बाद ऐसा domain लगाकर test करें जिसे आपकी सूचियाँ block करती हैं, फिर वही नाम आगे www. लगाकर। अगर पहला पास हो और दूसरा block हो, तो एंट्री खुली है।
    4. हर खुली एंट्री को anchor के साथ दोबारा लिखें, apply करें, और फिर test करें।

    जाँच 1 से 3 और rewrite के click-by-click steps नीचे के दो ‘गहराई में’ वाले हिस्सों में हैं। वे sign-in पेज से शुरू होते हैं और बताते हैं कि हर step क्या बदलता है।

    गहराई में: step by step, अपनी allowlist की जाँच

    शुरू करने से पहले। आपको अपने network के किसी computer पर एक browser चाहिए, और अपने router के settings पेज का address और login। Steps 1 से 8 सिर्फ़ पढ़ते हैं: वे router पर कुछ नहीं बदलते, इसलिए आप किसी भी जगह रुक सकते हैं, कुछ वापस करने की ज़रूरत नहीं। लगभग दस मिनट रखें, और हर test के लिए लगभग दस सेकंड अलग से, क्योंकि tester हर बार पूरी blocklist load करता है।

    1. एक browser खोलें और वह address डालें जिससे आप OPNsense में sign in करते हैं। Sign in करें। आपको Lobby पेज दिखना चाहिए। अगर पेज load न हो, तो देखें कि computer आपके home network पर है और आपने वही address डाला है जो आप router में किसी भी दूसरे बदलाव के लिए डालते हैं।
    2. बाईं ओर के menu में Services पर click करें, फिर Unbound DNS, फिर Log File। आपको एक table दिखेगी जिसके columns Date, Severity, Process और Line हैं। उसके ऊपर एक search box, एक severity box (Warning पर set) और एक time box (Last day पर set) हैं।
    3. Search box में click करें, blocklist type करें और Enter दबाएँ। दो तरह की लाइनें मायने रखती हैं। “unable to download blocklist” का मतलब है कि एक सूची load नहीं हुई और उसका कोई योगदान नहीं है। “skip invalid whitelist exclude pattern” का मतलब है कि OPNsense ने एक allowlist एंट्री छोड़ दी। अगर table खाली है, तो पिछले एक दिन में Warning level पर कुछ log नहीं हुआ। “blocklist loaded” वाली लाइनें देखने के लिए severity box खोलें और Informational भी tick करें; और पीछे देखने के लिए time box खोलें।
    4. उसी menu में Blocklists पर click करें, फिर पेज के ऊपर Tester tab पर। आपको एक Domain box, एक Source box और एक Test button दिखेगा। Source खाली छोड़ें; तब test router खुद के रूप में चलता है। Source किसी device का address लेता है, और तभी काम आता है जब आपके पास ऐसी policy हो जो कुछ ही devices पर लागू होती हो।
    5. Domain में googleads.g.doubleclick.net type करें और Test पर click करें। लगभग दस सेकंड रुकें। नतीजा Block होना चाहिए। फिर www.youtube.com test करें; वह Pass होना चाहिए। अगर पहला नाम पास हो जाए, तो या कोई सूची load नहीं है, या वह नाम आपकी अपनी allowlist में है: step 3 पर लौटकर errors पढ़ें, और अगर आपने वह नाम allowlist किया है, तो कोई दूसरा नाम चुनें जिसे आपकी सूचियाँ block करती हैं। Tester CNAME को follow नहीं करता। CNAME ऐसा नाम है जो किसी दूसरे नाम की ओर इशारा करता है; tester सिर्फ़ वही नाम जाँचता है जो आप type करते हैं।
    6. Blocklists tab पर click करें। अपनी policy की row के दाएँ सिरे पर pencil (Edit) पर click करें। Edit Blocklist नाम की एक window खुलती है। Allowlist Domains में आपकी एंट्री दिखती हैं, हर एक अलग tag के रूप में। उन्हें पढ़ें, फिर Cancel पर click करें। कुछ save नहीं होता।
    7. हर एंट्री के लिए, एंट्री के बाद ऐसा domain लगाकर test करें जिसे आपकी सूचियाँ block करती हैं। मेरी सूचियाँ जिस नाम को block करती हैं, वह googleads.g.doubleclick.net है, वही जो step 5 में था। अगर आपकी सूचियाँ उसे block नहीं करतीं, तो कोई ऐसा नाम चुनें जिसे वे करती हैं। इसलिए एंट्री example.com के लिए example.com.googleads.g.doubleclick.net type करें और Test पर click करें। फिर वही नाम आगे www. लगाकर test करें, www.example.com.googleads.g.doubleclick.net। अगर आप TIF load करते हैं, तो उसकी जगह उस सूची का कोई नाम इस्तेमाल कर सकते हैं। जो एंट्री पहले से ^ से शुरू और $ पर ख़त्म होती है, वह anchored है; उसे छोड़ दें।
    8. दोनों नतीजे साथ पढ़ें। अगर पहला पास हो और दूसरा block हो, तो एंट्री खुली है: वह हर उस नाम को निकलने देती है जो उससे शुरू होता है। उसे anchor के साथ दोबारा लिखें। जिस नाम को कोई सूची block नहीं करती, वह allowlist चाहे जो कहे, पास होता है, इसलिए Pass को गलती मानने से पहले tester में पक्का कर लें कि नाम block होता है।
    गहराई में: step by step, अपनी allowlist को दोबारा लिखना

    शुरू करने से पहले। यह आपके router की filtering बदलता है। पंद्रह मिनट रखें। यहाँ की गलती ज़्यादातर इसी रूप में दिखती है कि एक allow की हुई साइट load नहीं होती। आपका बाकी internet चलता रहना चाहिए। Router बदलाव लगभग एक मिनट में लागू करता है (मेरे router पर 43 सेकंड) और Unbound को restart नहीं करता; log दिखाता है कि सूचियाँ चलते हुए process में load हो रही हैं। Step 3 आपकी पुरानी एंट्री की एक copy save करता है, और step 8 उन्हें वापस रख देता है।

    1. Router का settings पेज खोलें और sign in करें। Services पर click करें, फिर Unbound DNS, फिर Blocklists।
    2. अपनी policy की row के दाएँ सिरे पर pencil (Edit) पर click करें। Edit Blocklist window खुलती है। Allowlist Domains के नीचे, box के नीचे के छोटे link Text पर click करें। Tags एक सादे box में बदल जाते हैं जिसमें हर लाइन पर एक एंट्री होती है, और एक Back link दिखता है। अगर आपके पास एक से ज़्यादा policy हैं, तो हर एक की अपनी allowlist है; हर एक के लिए यह करें।
    3. Undo copy बनाएँ। Box के अंदर click करें, Ctrl + A दबाएँ, फिर Ctrl + C। Notepad खोलें (Start menu, notepad type करें, Enter दबाएँ), Ctrl + V दबाएँ, और file को allowlist-before.txt नाम से किसी ऐसे folder में save करें जो आपको फिर मिल जाए। File में हर लाइन पर एक एंट्री होनी चाहिए।
    4. Box की हर लाइन दोबारा लिखें। यह सादे नामों के लिए है; जो एंट्री पहले से pattern है, जैसे जिसमें (.*\.)? हो, वह वैसी ही रहती है। वही सटीक नाम लिखें जो आपके devices पूछते हैं। हर dot से पहले \ लगाएँ, शुरू में ^ और अंत में \.?$:

      • example.in बन जाता है ^example\.in\.?$
      • www.example.com बन जाता है ^www\.example\.com\.?$

      हर लाइन पर एक एंट्री रखें, कोई space नहीं और कोई comma नहीं। www. वाला नाम और वही नाम उसके बिना, दो अलग नाम हैं और उन्हें दो लाइनें चाहिए। अगर आपको पक्का नहीं है कि कोई device कौन-सा पूछता है, तो Reporting, Unbound DNS में देखें, या दोनों सूची में रख दें।

    5. Back पर click करें। लाइनें फिर tags बन जाती हैं। जाँचें कि हर tag नए रूप में है। Save पर click करें। Window बंद हो जाती है।

    6. Apply पर click करें, table के नीचे का नारंगी button। लगभग एक मिनट रुकें।
    7. नतीजा जाँचें। Services, Unbound DNS, Log File खोलें, blocklist खोजें, और severity box में Informational tick करें। आपको “updating blocklist”, फिर “blocklist loaded. length is” और एक संख्या दिखनी चाहिए, और कोई “skip invalid” लाइन नहीं। फिर ऊपर के tester वाले steps दोहराएँ: lookalike नाम अब Block होने चाहिए। जो एंट्री किसी ऐसे नाम को allow करती है जिसे कोई सूची block करती है (मेरे यहाँ, Google के एक ad host वाली), वह अब भी Pass होनी चाहिए।
    8. अगर बदलाव के बाद कोई साइट load होना बंद हो जाए, तो उसे undo करें। Notepad में allowlist-before.txt खोलें, Ctrl + A, फिर Ctrl + C दबाएँ। Router में steps 1 और 2 दोहराएँ, box के अंदर click करें, Ctrl + A, फिर Ctrl + V दबाकर पुरानी एंट्री नई एंट्री के ऊपर paste करें, Back, Save और Apply पर click करें। जिस साइट को ऐसा नाम चाहिए जो आपने सूची में नहीं डाला, वह तब तक block रहती है जब तक आप वही सटीक नाम नहीं जोड़ते।
    गहराई में: computer से allowlist के बदलाव को test करना

    शुरू करने से पहले। यह उस Windows PC के लिए है जो router वाले ही network में है। यह router के DNS से एक नाम पूछता है और PC का अपना DNS cache साफ़ करता है; इसके अलावा कुछ नहीं बदलता। इसमें दो मिनट लगते हैं। Mac या Linux पर विचार वही है (nslookup name router-address), पर cache साफ़ करने का command अलग होता है।

    1. Start menu पर click करें, powershell type करें और Enter दबाएँ। एक window खुलती है जिसके prompt की शुरुआत PS से होती है।
    2. Router का address खोजें। यह type करें और Enter दबाएँ:

      ipconfig

      उस adapter के नीचे Default Gateway देखें जो आप इस्तेमाल कर रहे हैं। वही address आपका router है; नीचे के steps उसे <router-ip> कहते हैं। अगर आपका router किसी दूसरे router के पीछे है, तो default gateway वह दूसरा device हो सकता है; उस box का address इस्तेमाल करें जो आपकी DNS blocklist चलाता है। अगर लाइन खाली है, तो आप ऐसे adapter को देख रहे हैं जो connected नहीं है; अगले adapter तक scroll करें।

    3. Router पर Apply पर click करने और एक मिनट रुकने के बाद, PC का cache साफ़ करें। Blocked जवाब एक घंटे तक cache में रहते हैं, इसलिए इसके बिना PC पुराना जवाब रखे रह सकता है:

      ipconfig /flushdns
    4. Router से नाम पूछें, <router-ip> की जगह step 2 का address डालकर। नाम के बाद का आख़िरी dot Windows को पहले अपने search suffixes आज़माने से रोकता है:

      nslookup www.example.com. <router-ip>

      Blocked नाम 0.0.0.0 का जवाब देता है, या अगर policy पर Return NXDOMAIN tick है तो “Non-existent domain” का। जो नाम allowed है, वह अपने असली address के साथ जवाब देता है। पहली दो लाइनें आपका router दिखाती हैं; बाकी जवाब है।

    अठारह सूचियों का जोड़

    Router के resolver log में, उसकी पहली एंट्री से लेकर पहली सफ़ाई तक, हर पूरा रात का update यही अठारह सूचियाँ load करने के लिए set था (ThreatFox उनमें शामिल है, नीचे देखें):

    • Hagezi Normal, साथ में Pro, Pro++ और Ultimate के Mini versions
    • Threat Intelligence Feeds (TIF) तीनों आकारों में: full, Medium और Mini
    • Gambling तीनों आकारों में
    • Fake, Pop-Up Ads, Badware Hoster, DynDNS, Anti Piracy और “Safesearch not supported”
    • OISD NSFW और Abuse.ch ThreatFox

    Hagezi, जो इनमें से ज़्यादातर सूचियाँ बनाए रखते हैं, अपने FAQ में अपनी सूचियों को मिलाने के ये नियम देते हैं:

    1. पाँच Multi सूचियाँ — Light, Normal, Pro, Pro++ और Ultimate — एक-दूसरे पर बनी हैं। हर एक में उसके नीचे वाली शामिल है। आप एक चुनते हैं।
    2. आकार घटाए हुए versions (Mini, और TIF तथा Gambling के लिए Medium) अपनी पूरी सूची के विकल्प हैं। वे उसके ऊपर नहीं लगते।
    3. TIF अपवाद है। वह malware, cryptojacking, scams, spam और phishing को कवर करती है और जो भी tier आप चुनें, उसके साथ चलने के लिए बनी है।

    Pro, Pro++, Ultimate और Gambling के Mini सिर्फ़ वे नाम रखते हैं जो सबसे ज़्यादा देखे जाने वाले domains की सूचियों में भी आते हैं। TIF Mini और Gambling Mini, Medium सूची से काटे गए हैं। Hagezi Mini को सीमित memory वाले devices पर चलने वाले blockers के लिए बने बताते हैं।

    गहराई में: किसके लिए कौन-सा tier, और Ultimate की क़ीमत क्या है

    Hagezi का FAQ tiers को उस व्यक्ति से मिलाता है जो गड़बड़ी सँभालेगा:

    Tier किसके लिए गड़बड़ी का जोखिम (Hagezi की रेटिंग)
    Light ऐसा blocker जो बड़ी सूचियाँ नहीं सँभाल सकता, या ऐसी setting जहाँ Normal भी ज़्यादा है बहुत कम
    Normal बिना देखरेख वाले setups, जहाँ चीज़ें unblock करने वाला कोई admin नहीं कम
    Pro जहाँ कोई चीज़ें unblock कर सकता है; उनकी default सिफ़ारिश, TIF के साथ कम से मध्यम
    Pro++ admin वाले अनुभवी users मध्यम
    Ultimate बहुत अनुभवी users, जिनके पास admin उपलब्ध है ज़्यादा

    हर tier में native tracker सूचियों का एक हिस्सा भी है: TVs, फ़ोन और operating systems में बनी telemetry। Pro++ लगभग सारी block करता है; Ultimate सारी। README बताती है कि Ultimate की क़ीमत क्या है: Facebook और Messenger के कुछ functions, WhatsApp के extras जैसे avatars और video effects, Windows Spotlight और Xbox achievement history, और वे location trackers जिन पर कुछ साइटें निर्भर हैं, जिससे गलत क्षेत्रीय settings और ज़्यादा CAPTCHAs आ सकते हैं।

    मेरे सेट ने पहले दो नियम तोड़े। मैंने इस जाँच के लिए सूचियाँ एक बार download कीं और नाम-दर-नाम मिलाईं, यह देखने के लिए कि एक सूची की कौन-सी एंट्री दूसरी में पहले से block हैं। Router ने पहले जो copies load की थीं, वे मेरे पास नहीं हैं, और मैंने ThreatFox नहीं नापा, इसलिए सत्रह सूचियाँ नापी गईं।

    सत्रह में से सात बाकी सेट में शामिल थीं, हर सूची की एक marker एंट्री को छोड़कर: Pro Mini, Pro++ Mini, TIF Medium, TIF Mini, Gambling Medium, Gambling Mini और Fake। सातों को साथ हटाने पर वे 15 नाम खो जाते जो TIF Medium और Mini में हैं और पूरे TIF में नहीं हैं। Pop-Up Ads ने अपने 48,277 नामों में से 37 बाकी सेट में जोड़े (अकेले Pro++ के मुक़ाबले वह तीन जोड़ती है, नीचे देखें)। DynDNS और Anti Piracy अलग थीं: उन सूचियों में लगभग 1,200 और लगभग 55,000 ऐसे नाम थे जो सेट की किसी और सूची में नहीं थे, और मैंने उन्हें duplicate मानकर नहीं, अपनी पसंद से हटाया।

    चारों tier सूचियों में मिलाकर 233,710 नाम थे; Hagezi की चार marker एंट्री को छोड़कर सब Ultimate में थे। अकेले Pro++ के मुक़ाबले, वे Pro++ की 31,411 एंट्री से चूक गईं, यानी वे जो सबसे ज़्यादा देखे जाने वाली सूचियों में नहीं हैं। उनकी जगह उनमें 25,040 एंट्री थीं जो सिर्फ़ Ultimate block करता है (Ultimate Mini के marker के साथ 25,041), सब सबसे ज़्यादा देखे जाने वाली सूचियों से। Hagezi Ultimate की गड़बड़ी का जोखिम ज़्यादा रेट करते हैं। मैंने उनसे होने वाली किसी गड़बड़ी का record नहीं रखा और उसके लिए test नहीं किया, पर Hagezi की रेटिंग के अनुसार इस मिश्रण ने Ultimate का जोखिम लिया और उसमें Pro++ की coverage की कमी थी।

    गहराई में: मैंने कैसे नापा, और सादी तुलना गलत क्यों निकलती है

    OPNsense Hagezi का wildcard format इस्तेमाल करता है, जिसमें *.example.com जैसी लाइन example.com को और उसके नीचे के हर नाम को block करती है। इसलिए सूची A की कोई एंट्री सूची B में पहले से blocked है, अगर B में वह एंट्री या उसका कोई parent domain हो।

    सादी text तुलना इसे चूक जाती है। comm बताता है कि Pro++ Mini की 3,294 एंट्री Ultimate Mini में “नहीं हैं”। उनमें से एक को छोड़कर सब covered हैं, क्योंकि Ultimate Mini कोई parent domain block करता है। उसमें पूरे omtrdc.net के लिए, जो Adobe का tracking domain है, एक ही लाइन है, जबकि Pro++ Mini उसके 998 hosts एक-एक करके लिखता है। बचा हुआ एक Hagezi की marker एंट्री है, जो नीचे समझाई गई है।

    चारों tier सूचियाँ, उसी तरह नापी गईं:

    Normal + Pro Mini + Pro++ Mini + Ultimate Mini
    अलग-अलग नाम 233,710
    इनमें से, Ultimate में भी 4 को छोड़कर सब (Hagezi की marker एंट्री)
    मिश्रण में न आने वाली Pro++ की एंट्री 223,551 में से 31,411
    मिश्रण के वे नाम जो सिर्फ़ Ultimate block करता है 25,040

    मैंने जो जाँच इस्तेमाल की, वह parent domains पर ऊपर की ओर चलती है। यह एक Python 3 script है, जिसके लिए Python के अलावा कुछ install नहीं करना पड़ता। पहले script है; उसके बाद के steps बताते हैं कि उसे कैसे save और run करें।

    #!/usr/bin/env python3
    """hagezi_overlap.py - how much of blocklist A is already blocked by blocklist B.
    
    Reads two Hagezi lists in the wildcard format (the /wildcard/ files, the format
    OPNsense uses). A line "*.example.com" blocks example.com and every name under
    it, so an entry of A counts as covered when the entry itself, or one of its
    parent domains, is in B. A plain text comparison (comm, diff) misses that and
    reports too many differences.
    
    Usage:  python3 hagezi_overlap.py A.txt B.txt
    Author: Vivek Sanghi. Licence: CC BY-NC-SA 4.0, as the blog.
    """
    import re
    import sys
    
    WILDCARD = re.compile(r"^\*\.[a-z0-9_-]+(\.[a-z0-9_-]+)+$")
    
    
    def load(path):
        names = set()
        try:
            f = open(path, encoding="utf-8-sig")
        except OSError as e:
            sys.exit(f"{path}: cannot open ({e.strerror})")
        with f:
            for number, line in enumerate(f, 1):
                line = line.strip().lower()
                if not line or line.startswith("#"):
                    continue
                if not WILDCARD.match(line):
                    sys.exit(f"{path}, line {number}: not a wildcard-format line "
                             "('*.example.com'). Download the /wildcard/ version of the list.")
                names.add(line[2:])
        if not names:
            sys.exit(f"{path}: no entries found; check the download")
        return names
    
    
    def covered(name, blocked):
        while True:
            if name in blocked:
                return True
            if "." not in name:
                return False
            name = name.split(".", 1)[1]
    
    
    def main():
        if len(sys.argv) != 3:
            sys.exit("usage: hagezi_overlap.py A.txt B.txt")
        a, b = load(sys.argv[1]), load(sys.argv[2])
        missing = sorted(n for n in a if not covered(n, b))
        print(f"{sys.argv[1]}: {len(a):,} entries; {len(a) - len(missing):,} already "
              f"blocked by {sys.argv[2]}; {len(missing):,} not")
        for n in missing[:10]:
            print(f"  not covered: {n}")
        if len(missing) > 10:
            print(f"  ... and {len(missing) - 10:,} more")
    
    
    if __name__ == "__main__":
        main()
    

    शुरू करने से पहले। यह एक Windows PC के लिए है। आपको Python 3 चाहिए (step 3 जाँचता है)। Steps आपके user folder में एक folder बनाते हैं, उसमें कुछ megabytes की दो सूची files download करते हैं, और उन्हें पढ़ते हैं; इसके अलावा कुछ नहीं बदलते। दस मिनट रखें। undo करने के लिए File Explorer में वह folder delete कर दें। Mac या Linux पर Terminal इस्तेमाल करें, py की जगह python3, और curl.exe की जगह curl।

    1. Start menu पर click करें, powershell type करें और Enter दबाएँ। एक window खुलती है जिसके prompt की शुरुआत PS से होती है।
    2. एक folder बनाएँ और उसमें जाएँ। हर लाइन में थोड़ा समय लगता है; उन्हें एक-एक करके चलाएँ:

      mkdir hagezi-check
      cd hagezi-check

      अब prompt का अंत hagezi-check से होना चाहिए। अगर पहली लाइन कहे कि folder पहले से है, तो कोई दूसरा नाम चुनें और दोनों लाइनों में वही इस्तेमाल करें।

    3. जाँचें कि Python install है:

      py --version

      आपको Python 3.12.4 जैसी एक लाइन दिखनी चाहिए। अगर PowerShell कहे कि वह py को नहीं पहचानता, तो python.org से Python 3 install करें (installer में “Add python.exe to PATH” पर tick करें), PowerShell बंद करें और step 1 से फिर शुरू करें।

    4. Script file बनाएँ। इससे Notepad खुलता है:

      notepad hagezi_overlap.py

      Notepad पूछता है कि नई file बनानी है या नहीं; Yes पर click करें। ऊपर के box से script paste करें (box पर Copy पर click करें, फिर Notepad में Ctrl + V), Ctrl + S दबाएँ, और Notepad बंद करें। अगर Notepad बिना पूछे खुल जाए, तो File, Save as से save करें, file के नाम के रूप में hagezi_overlap.py को quotation marks में type करें, पक्का करें कि folder hagezi-check है, और Save पर click करें।

    5. दो सूचियाँ folder में download करें। Windows पर PowerShell में curl नहीं, curl.exe type करें। लाइनें एक-एक करके चलाएँ:

      curl.exe -o pro.plus.mini.txt https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/pro.plus.mini.txt
      curl.exe -o ultimate.mini.txt https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/ultimate.mini.txt

      हर एक में कुछ सेकंड लगते हैं और एक progress table छपती है। अगर कोई लाइन error पर ख़त्म हो, तो connection जाँचें और वह लाइन फिर चलाएँ।

    6. जाँच चलाएँ:

      py hagezi_overlap.py pro.plus.mini.txt ultimate.mini.txt
    7. जो सूचियाँ मैंने इस जाँच के लिए download कीं, उन पर इसने यह छापा:

      pro.plus.mini.txt: 98,704 entries; 98,703 already blocked by ultimate.mini.txt; 1 not
        not covered: h4g3z1-pro-plus-mini.web.app

      आपके numbers अलग होंगे, क्योंकि सूचियाँ रोज़ बदलती हैं। अगर आपको numbers की जगह कोई संदेश दिखे, तो script जान-बूझकर रुका है: संदेश पढ़ें, वह file और लाइन बताता है।

    हर तुलना में बचा हुआ एक नाम वह marker है जो Hagezi हर सूची में डालते हैं (h4g3z1-<list>.web.app), ताकि पता चले कि कौन-सी सूची load है। अगर download fail हो, या file किसी और format में हो, तो script कोई number बताने की जगह रुक जाता है और यह कह देता है।

    उन्हीं सूचियों पर इसने और क्या दिया:

    सूची A सूची B A की वे एंट्री जो B से पहले ही blocked हैं
    Normal (171,454) Pro++ marker को छोड़कर सब
    Pro++ (223,551) Ultimate marker को छोड़कर सब
    Pro Mini (86,842) Ultimate Mini marker को छोड़कर सब
    TIF Mini (212,777) TIF Medium marker को छोड़कर सब
    Gambling Mini (118,888) Gambling Medium marker को छोड़कर सब
    Fake (17,622) Pro++ marker को छोड़कर सब
    Pop-Up Ads (48,277) Pro++ 4 को छोड़कर सब (marker और 3 दूसरी)
    Badware Hoster (1,088) Pro++ 966
    Ultimate Mini (120,458) Pro++ 95,417

    Script का test इन सूचियों पर किया गया, और इन पर भी: missing file, खाली file, सिर्फ़ comments वाली file, failed download, एक web page, और adblock, hosts और plain-domain formats की सूचियाँ।

    load हुए नामों की गिनती मेरे बदलावों के अनुसार नहीं बदली। पहली सफ़ाई के दिन router ने उससे पहले 2,840,117 नाम load किए और उसके बाद 3,188,234, अठारह की जगह दस सूचियों के साथ: उस दिन दो downloads के बीच TIF में 426,519 एंट्री बढ़ गई थीं। मेरी ओर से बिना किसी बदलाव के, गिनती चार दिन में 2,739,044 से 3,229,041 हो गई। जो सूची sizes मैंने इस जाँच के लिए download कीं, उन पर लगभग दो-तिहाई नाम TIF पर थे और लगभग 7 प्रतिशत Pro++ पर।

    गहराई में: router के आँकड़े, उनकी सीमाओं के साथ

    लोड हुए नाम, router के log से (“blocklist loaded. length is …”, unique नामों की संख्या):

    कब सूचियाँ लोड हुए नाम
    पहली सफ़ाई का दिन, पहले अठारह 2,840,117
    पहली सफ़ाई का दिन, बाद में नया सेट 3,188,234
    पाँच दिन बाद वही सेट 2,739,044
    नौ दिन बाद वही सेट 3,229,041
    अठारह दिन बाद वही सेट 3,198,953

    Block हुई queries का हिस्सा, Reporting → Unbound DNS से:

    अवधि Queries Blocked
    पहली सफ़ाई का दिन, उसी दिन पढ़ा गया दर्ज नहीं 12.9 प्रतिशत
    लगभग 38 घंटे की अवधि, बाद में पढ़ी गई 110,248 8,600 (7.80 प्रतिशत)

    दोनों प्रतिशत अलग सूचियों, अलग दिनों और उस समय network जो भी कर रहा था, उसे कवर करते हैं। वे पहले और बाद की तुलना नहीं हैं।

    अब मैं क्या tick रखता हूँ

    मेरे router की settings में यह है:

    • Hagezi Pro++ (full)
    • TIF (full)
    • Gambling (full)
    • Fake, Pop-Up Ads, Badware Hoster और “Safesearch not supported”
    • OISD NSFW
    • URL से जोड़ी गई दो Hagezi सूचियाँ: encrypted-DNS servers और LG TV trackers
    • Abuse.ch ThreatFox, URL से, एक free key के साथ (नीचे)

    मैंने Hagezi के सुझाए Pro की जगह Pro++ चुना, device trackers के लिए, क्योंकि Pro++ वह जगह है जहाँ वे लगभग सारे trackers block करते हैं।

    इनमें से दो duplicate हैं। Hagezi की cheat sheet Fake और Pop-Up Ads को Pro++ के अंदर बताती है। Fake के लिए नाप भी यही कहती है, और उसे हटाया जा सकता है; इससे जो block होता है वह नहीं बदलता। Pop-Up Ads में, मेरी download की हुई सूचियों पर, तीन नाम हैं जो Pro++, TIF, Gambling, Hoster या Fake में से किसी में नहीं हैं; उसे हटाने पर वे तीन जाते हैं। मैंने ThreatFox या दोनों URL सूचियों की तुलना नहीं की। Fake और Pop-Up Ads दोनों अब भी tick हैं।

    ThreatFox download होना बंद हो गई थी और अब फिर download होती है। हर update ने “unable to download blocklist … and no cache available” लिखा था। OPNsense की built-in एंट्री ने उसके लिए जो address इस्तेमाल किया, वह “410 Gone” का जवाब देता है, और abuse.ch का export पेज host file देने से पहले Auth-Key माँगता है। 26.7 की एक बाद की release ने इसी कारण built-in एंट्री हटा दी और users को “URLs of Blocklists” की ओर भेजा। abuse.ch अपने authentication portal से key free देता है। मैंने सूची URL से जोड़ी, key को address में रखकर। abuse.ch का export पेज key URL में माँगता है, और OPNsense का downloader कोई headers नहीं भेजता। नीचे के steps address का रूप दिखाते हैं। जिस update ने इसे जोड़ा, उसने इसके लिए 28,889 लाइनों के साथ “blocklist download” लिखा, जिनमें 28,869 नाम थे, और कोई error नहीं; उस update में बाकी सूचियाँ cache से load हुईं। Router की अपनी load हुए नामों की गिनती के अनुसार, वह 2,765,172 से बढ़कर 2,782,246 हुई। इसलिए 28,869 में से 17,074 उस सटीक नाम से पहले load नहीं थे, और लगभग 11,800 थे। गिनती नामों की अक्षर-दर-अक्षर तुलना करती है, इसलिए जिस नाम के parent domain को कोई और सूची पहले से block करती है, वह भी नया गिना जाता है। Hagezi ThreatFox को source के रूप में नाम नहीं देते।

    Key password की तरह काम करती है। Router उसे अपनी configuration में रखता है, और हर update key समेत address को resolver log में लिखता है। उसे उन screenshots, shared logs, configuration backups और किसी भी remote log server से बाहर रखें जो आपके हाथ से निकल जाते हैं। अगर वह leak हो गई हो, तो उसी portal से नई key लें और address बदल दें।

    गहराई में: key के साथ ThreatFox जोड़ना

    शुरू करने से पहले। यह आपकी policy में एक सूची जोड़ता है। दस मिनट रखें। कुछ delete नहीं होता। इसे undo करने के लिए, उसी box से address हटाएँ और फिर apply करें।

    1. Browser में https://auth.abuse.ch खोलें, अगर account नहीं है तो बनाएँ, और एक Auth-Key लें। Key free है। उसे सिर्फ़ step 4 तक किसी text file में copy रखें, जहाँ आप उसे एक बार paste करते हैं, फिर वह file delete कर दें।
    2. Router में log in करें। Services पर click करें, फिर Unbound DNS, फिर Blocklists।
    3. अपनी policy की row के दाएँ सिरे पर pencil (Edit) पर click करें। Edit Blocklist नाम की एक window खुलती है।
    4. URLs of Blocklists के अंदर click करें और नीचे का address type करें, YOUR_KEY की जगह अपनी key के साथ और बिना किसी space के। Enter दबाएँ ताकि वह अपना एक अलग tag बन जाए (tag वह एक एंट्री है जो field में छोटे box के रूप में दिखती है):

      https://threatfox-api.abuse.ch/v2/files/exports/YOUR_KEY/hostfile.txt

      Key exports/ और /hostfile.txt के बीच बैठती है।

    5. Save पर click करें, फिर Apply। Router सूचियाँ फिर download करता है; एक-दो मिनट रखें।

    6. Services, Unbound DNS, Log File पर click करें, download खोजें, और severity box में Informational tick करें। आपको “blocklist download:” और ThreatFox address के लिए लाइनों की संख्या दिखनी चाहिए। अगर लाइन “unable to download” कहे, तो key और address में किसी फ़ालतू space की जाँच करें।
    7. वह screen share न करें: लाइन में आपकी key के साथ address दिखता है।
    गहराई में: Badware Hoster और URL से जोड़ी गई दो सूचियाँ

    Badware Hoster Hagezi की एक अलग सूची है, और उसकी 1,088 एंट्री में से 966 पहले से Pro++ में हैं। बाकी वे पूरे hosting providers block करती है जो threat feeds में बार-बार आते हैं। Hagezi चेताते हैं कि उन hosts पर मौजूद वैध साइटें उनके साथ block हो जाती हैं, और उन्हें unblock करना वे सूची चलाने वाले पर छोड़ते हैं।

    URL से जोड़ी गई दो सूचियाँ Hagezi की हैं, wildcard format में:

    https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/doh.txt
    https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/native.lgwebos.txt

    पहली encrypted-DNS servers को नाम से सूचीबद्ध करती है, devices को router को बायपास करने से रोकने का एक हिस्सा। दूसरी LG webOS के ad और tracking servers सूचीबद्ध करती है। हर एक की अपनी कहानी है, अलग पोस्टों के लिए।

    OPNsense 26.7 के built-in Hagezi tick-boxes Hagezi के mirror, hagezi-mirror.dnsbunker.org, से download करते हैं, जैसा log दिखाता है। Hagezi कहते हैं कि वह mirror लगभग हर चार से आठ घंटे में नई build प्रकाशित करता है; jsDelivr की copies दिन में एक बार update होती हैं।

    DNS क्या block नहीं कर सकता

    YouTube और Instagram के in-app ads उन्हीं domains से आते हैं जिनसे videos और posts आते हैं, इसलिए उन्हें नाम से block करने पर content भी block हो जाएगा। Hagezi का FAQ सामान्य बात कहता है: कुछ ads content वाले ही domains से load होते हैं, और browser में content blocker, या फ़ोन पर app-level blocker, वह परत है जो उन्हें पकड़ती है। मैंने in-app ads को स्वीकार कर लिया।

    DNS blocklist सिर्फ़ उन्हीं devices को filter करती है जो router से पूछते हैं; जिन devices का अपना encrypted या hard-coded DNS है, वे उसे बायपास कर जाते हैं। वह एक अलग पोस्ट है।

    यह कैसे किया गया

    Claude ने documentation और सूचियाँ पढ़ीं, उनकी तुलना की, और मेरे logged-in browser session के ज़रिए मेरा router पढ़ा: settings, resolver log और tester। क्या बदलना है, यह मैंने तय किया। Allowlist वाले session में router पर एकमात्र बदलाव allowlist का rewrite था।

    Model ने गलतियाँ कीं। bare नाम वाला allowlist fix पहले session से निकला, और एक session में उसने मुझे यह भी बताया कि रात का blocklist update Unbound का cache flush करता है। Router के log में दिखा कि update सूचियों को चल रहे Unbound में load करता है, restart के बिना। Manual कहती है कि blocklist settings apply करने से Unbound restart नहीं होता, और source नई सूची को चल रहे process में load करता है। Flush वाली setting सिर्फ़ तब लागू होती है जब Unbound रुकता है।

    Router पर logged-in session वाला model अपने आप में एक जोखिम है। जो resolver log वह पढ़ता है, उसमें ऐसे नाम हैं जिन्हें कोई भी website किसी device से lookup करवा सकती है, और कोई नाम model को दिशा देने के लिए लिखा text ले जा सकता है। Allowlist वाले session में मैंने उसे सिर्फ़ पढ़ने तक रखा, allowlist के बदलाव को छोड़कर। यह model को दिया गया निर्देश है, कोई control नहीं; read-only OPNsense user एक control होता। Resolver log में key समेत ThreatFox address भी है, इसलिए जो session log पढ़ता है वह key देख लेता है। अगर आप किसी model को वह log पढ़ने देते हैं, तो बाद में key बदल दें।

    पहले session में मैंने पाँच Unbound settings और एक cron job भी बदले। Router छहों को set दिखाता है।

    गहराई में: हर setting, और DNS over TLS को undo कैसे करें
    Setting (पेज) पहले बाद में
    Flush DNS Cache during reload (General) चालू बंद
    Prefetch Support (Advanced) बंद चालू
    Serve Expired Responses (Advanced) बंद चालू; TTL for Expired Responses 86,400 s
    Use System Nameservers (Query Forwarding) चालू बंद
    DNS over TLS forwarders कोई नहीं Cloudflare और Quad9
    Blocklist update job (System → Settings → Cron) दूसरे jobs के साथ साझा slot अपना अलग slot

    Prefetch लोकप्रिय एंट्री को उनके expire होने से पहले refresh करता है। Manual इसकी क़ीमत लगभग 10 प्रतिशत ज़्यादा DNS traffic बताती है।

    Serve Expired Responses device को इंतज़ार कराने की जगह cache से expired record के साथ जवाब देता है। जब यह चालू होता है, तो और fields दिखते हैं। “TTL for Expired Responses” सीमित करता है कि expiry के कितनी देर बाद तक पुराना जवाब दिया जा सकता है; मैंने 86,400 सेकंड रखे, जो manual के सुझाए 86,400 से 259,200 का निचला सिरा है।

    एक interaction जिसे मैंने test नहीं किया: cache flushing बंद और पुराने जवाब allowed होने पर, जिस नाम को कोई सूची नया block करती है, उसे Unbound के cache से कुछ देर तक जवाब मिलते रह सकते हैं। अगर कोई block तुरंत असर न करे, तो मैं सबसे पहले यही देखूँगा।

    Use System Nameservers. Manual कहती है कि Query Forwarding और DNS over TLS की किसी भी catch-all एंट्री से system nameservers को प्राथमिकता मिलती है। इसे बंद करने पर DNS over TLS की एंट्री queries ले जाती हैं। चारों एंट्री, Services → Unbound DNS → DNS over TLS के नीचे:

    Server IP Port Verify CN
    1.1.1.1 853 cloudflare-dns.com
    1.0.0.1 853 cloudflare-dns.com
    9.9.9.9 853 dns.quad9.net
    149.112.112.112 853 dns.quad9.net

    Router की अपनी queries, जो इन servers को जाती हैं, encrypted निकलती हैं। जो firewall rule LAN से port 853 को reject करता है, devices को अपना encrypted DNS इस्तेमाल करने से रोकने के लिए, वह इन्हें नहीं छूता, क्योंकि ये router से ही निकलती हैं।

    Update का समय एक अलग slot में चला गया ताकि update अब दूसरे scheduled jobs के समय पर न चले।

    DNS over TLS का बदलाव undo करने के लिए:

    शुरू करने से पहले। यह आपके router की DNS settings बदलता है और इसमें पाँच मिनट लगते हैं। बाकी बची settings से DNS चलता रहता है। पहले चारों एंट्री note कर लें (ऊपर की table); बदलाव को दोबारा लागू करने के लिए आपको वे चाहिए।

    1. Router का settings पेज खोलें और sign in करें। आपको Lobby पेज दिखना चाहिए।
    2. Services पर click करें, फिर Unbound DNS, फिर DNS over TLS। एक table में एंट्री सूचीबद्ध हैं।
    3. पहली row के दाएँ सिरे पर pencil (Edit) पर click करें। Edit server नाम की एक window खुलती है। Enabled का tick हटाएँ और Save पर click करें। बाकी हर row के लिए यही करें।
    4. उसी पेज के ऊपर Use System Nameservers पर tick करें। वही box Query Forwarding के नीचे भी दिखता है; यह एक ही setting है।
    5. पेज के नीचे Apply पर click करें। Unbound कुछ सेकंड में reload होता है।
    6. जाँचें: network के किसी device से कोई ऐसी website खोलें जो आपने आज नहीं खोली। वह load होनी चाहिए। अगर System, Settings, General में कोई nameservers नहीं हैं, तो Unbound forward करने की जगह root servers से खुद resolve करता है; अगर आप चाहते हैं कि आपके provider के servers इस्तेमाल हों, तो उन्हें वहाँ जोड़ें।
    7. बदलाव को दोबारा लागू करने के लिए, हर एंट्री पर फिर Enabled tick करें, Use System Nameservers का tick हटाएँ, और Apply पर click करें।

    स्रोत

    ఫిషింగ్ పేర్లను లోపలికి పంపిన సవరణ

    ఆంగ్ల మూలం నుండి అనువదించినది. కమాండ్లు, కోడ్, సాంకేతిక పదాలు ఆంగ్లంలోనే ఉంచాను.

    అక్టోబర్‌లో ఒక శనివారం నా రూటర్ DNS allowlistలో పాడైన నాలుగు ఎంట్రీలను సరిచేశాను. రెండు వారాలకు కొంచెం ఎక్కువ రోజుల తర్వాత, సరిచేసిన ఎంట్రీలు threat feedలోని కొన్ని పేర్లను లోపలికి పంపుతున్నాయని కనుగొన్నాను. ఆ పేర్లు నేను అనుమతించదలచిన సైట్లలా కనిపించేలా తయారుచేసినవి: ఒక చెల్లింపు సైట్ domain తర్వాత .https. మరియు సంబంధం లేని మరో domain, లేదా చుక్క ఉండాల్సిన చోట హైఫన్ ఉన్న ఒక షాప్ పేరు. నా రూటర్ సొంత tester వాటిని Pass చేసింది.

    అదే సాయంత్రం నా blocklistలను పద్దెనిమిది నుండి పదికి తగ్గించాను; మరుసటి రోజు ఒక LG TV list చేరి పదకొండు అయింది. వాటిలో ఏడింటిని మిగతా సెట్ ఇప్పటికే కవర్ చేస్తోంది. నేను ఉంచిన ఒక list, Abuse.ch ThreatFox, abuse.ch తన host fileను key ఉన్నవారికే ఇవ్వడం మొదలుపెట్టినప్పుడు download కావడం ఆగిపోయింది. దాని addressలో ఒక ఉచిత key పెట్టినప్పటి నుండి మళ్లీ download అవుతోంది. నా ఫోన్‌లో YouTube, Instagram లోపలి ప్రకటనలు మొత్తం సమయంలో వస్తూనే ఉన్నాయి; ఏ blocklist కూడా దాన్ని మార్చగలిగేది కాదు.

    ఆ తర్వాత allowlist ఎంట్రీలను తిరిగి రాశాను. ఈ పోస్ట్ రెండు శుభ్రతల గురించి: allowlist ఎంట్రీని OPNsense ఏం చేస్తుంది, మీది ఎలా తనిఖీ చేయాలి, ఒకదానిపై ఒకటి ఉన్న పద్దెనిమిది lists చివరికి ఏమి చేర్చాయి. ఈ పనిని Claudeతో రెండు సెషన్లలో చేశాను, ఒక్కో శుభ్రతకు ఒకటి; ThreatFox key మూడో సెషన్‌లో వేశాను. అది నా browser ద్వారా రూటర్‌ను చదివింది; రూటర్‌పై ప్రతి మార్పునూ నేనే ఆమోదించాలి. bare name (యాంకర్ లేని సాదా పేరు) సవరణను నేనే ఆమోదించాను, కాబట్టి ఆ పొరపాటు విషయంలో ఆమోదం రక్షణ కాలేదు.

    కమాండ్ లైన్ మీకు కొత్తా? boxes ను ఎలా చదవాలి

    PS> అంటే: Windowsలో PowerShell లో దీన్ని type చేయండి (Start menu → powershell అని type చేయండి → Enter). $ అంటే: Linux లేదా Mac లోని terminal లో, లేదా Pi లో ssh తో login అయిన తర్వాత దీన్ని type చేయండి. $ లేదా PS> ను మీరు type చేయవద్దు.

    $ లేదా PS> తో మొదలయ్యే ప్రతి line ఒక కమాండ్. ఆ line ను మాత్రమే copy చేయడానికి ఆ $ ను click చేసి, paste చేసి, Enter నొక్కి, తర్వాతి దానికి ముందు అది పూర్తయ్యే వరకు వేచి ఉండండి. పైన Copy button ఉన్న box ఒక కమాండ్ (లేదా ఒక ఫైల్) కలిగి ఉంటుంది, కాబట్టి దాన్ని మొత్తం copy చేయండి. చుక్కల అంచు ఉన్న box మీకు తిరిగి కనిపించాల్సినదాన్ని చూపుతుంది; దాన్ని మీరు type చేయరు.

    Allowlist

    నా blocklist policy allowlistలో 26 ఎంట్రీలు ఉన్నాయి. మొదటి శుభ్రత రోజున వాటిలో నాలుగు పాడైనట్లు కనిపించాయి. మూడింటిని browser address bar నుండి పూర్తి address రూపంలో, అంటే https://example.org/ రూపంలో, paste చేశారు. నాలుగో దానిలో పేరు మొదటి అక్షరానికి ముందు ఒక space ఉంది. ఆ నాలుగింటినీ example.in వంటి bare namesతో మార్చాను. మిగతా 22 ఎలా రాసి ఉన్నాయో నేను చూడలేదు, రూటర్ configuration history ఇప్పుడు తనిఖీ చేసేంత వెనక్కి వెళ్లదు. అవి రూటర్ సొంత Allow button రాసినట్లు bare names అయి ఉంటే, నా సవరణకు ముందే ఈ లోపం ఉంది, సవరణ దాన్ని ఇంతవరకు దేనికీ సరిపోని మూడు ఎంట్రీలకూ విస్తరించింది.

    రూటర్ log ఐదో ఎంట్రీని చూపింది, *.ntp.org అని రాసినది, దాన్ని తర్వాత తొలగించాను. ప్రతి nightly update దాని గురించి “skip invalid whitelist exclude pattern” అని log చేసింది. Python regular expressionsలో ప్రారంభంలో * చెల్లదు, కాబట్టి రూటర్ ప్రతి రాత్రి ఆ ఎంట్రీని వదిలేసింది, ఆ విషయం log లో మాత్రమే చెప్పింది. ఉద్దేశించినది చేసే రూపం (.*\.)?ntp\.org\.?$.

    తర్వాత Claude, OPNsense 26.7లో allowlistను వర్తింపజేసే codeను చదివింది. ప్రారంభంలోని space ఏ హానీ చేయలేదు: code ప్రతి ఎంట్రీ నుండి spaces తొలగిస్తుంది. సమస్య bare names.

    OPNsense ప్రతి ఎంట్రీని regular expressionగా తీసుకుంటుంది, case-insensitiveగా, మరియు ఒక device అడిగే పేరు ప్రారంభంతో సరిపోల్చుతుంది. ఎంట్రీ పేరు చివరకు కట్టబడి ఉండదు, escape చేయని చుక్క ఏ అక్షరానికైనా సరిపోతుంది. కాబట్టి bare example.com, example.comను అనుమతిస్తుంది కానీ www.example.comను కాదు. అది ఆ అక్షరాలతో మొదలయ్యే ఏ పేరునైనా కూడా అనుమతిస్తుంది, ప్రతి చుక్క స్థానంలో ఏ అక్షరమున్నా: example.com.evil.net, example-com.evil.net, example.community.

    Threat feedలో సరిగ్గా అలాంటి ఆకృతి గల పేర్లు ఉన్నాయి: ప్రసిద్ధ సైట్ పేరు తర్వాత .https. మరియు సంబంధం లేని domain, లేదా చుక్కకు బదులు హైఫన్ ఉన్న సైట్ పేరు. ఈ పరిశీలన కోసం నేను download చేసిన feedలో, నా 26 ఎంట్రీలలో ఏడు అలాంటి 43 పేర్లకు సరిపోయాయి; ఒక ఎంట్రీ 20కి సరిపోయింది. నా రూటర్ testerలో, నేను ప్రయత్నించిన అలాంటి ఐదు పేర్లూ Pass అయ్యాయి, అదే list ఎంట్రీ బ్లాక్ చేసే, ముందు www. ఉన్న అదే పేరు మాత్రం blocked అయింది. అనుమతించిన సైట్ పేరుతో, threat feed బ్లాక్ చేసే domainతో నేను తయారుచేసిన పేరు కూడా Pass అయింది. matching code ప్రకారం, ప్రతి bare ఎంట్రీ, దానితో మొదలయ్యే ఏ పేరునైనా అనుమతిస్తుంది, ఏదైనా list ఆ పేరును బ్లాక్ చేసినా, చేయకపోయినా.

    OPNsense సొంత Allow button, Reporting → Unbound DNSలో, bare nameను అదే విధంగా save చేస్తుంది. అక్కడి నుండి చేర్చిన ఎంట్రీలు కూడా అదే విధంగా పనిచేస్తాయి.

    సవరణ ఏమిటంటే, ఖచ్చితమైన పేరును రెండు చివరలా anchor చేసి అనుమతించడం:

    ^www\.example\.com\.?$

    backslashలు చుక్కలను అక్షరార్థంగా చేస్తాయి, $ pattern ను పేరు చివరికి కట్టేస్తుంది. \.? అనేది code తనిఖీ చేసే రెండు మార్గాలలో ఒక దానిలో పేరుకు ఉండే చివరి చుక్కను అనుమతిస్తుంది (లోతైన పరిశీలన చూడండి). ^ code ఇప్పటికే చేసే పనినే పునరావృతం చేస్తుంది, కాబట్టి దాన్ని వదిలేసినా పనిచేస్తుంది; pattern ఎక్కడైనా ఒకేలా చదవబడేలా నేను దాన్ని ఉంచుతాను. మీ ఎంట్రీలను తనిఖీ చేసి తిరిగి రాసే దశలు “మీది ఎలా తనిఖీ చేయాలి” కింద ఉన్న లోతైన పరిశీలనలలో ఉన్నాయి.

    ఒక domainను దాని అన్ని subdomainలతో అనుమతించాలంటే (.*\.)?example\.com\.?$ పనిచేస్తుంది, కానీ list ఉద్దేశపూర్వకంగా ఆ domain కింద బ్లాక్ చేసే hostలను కూడా అది అనుమతిస్తుంది. నా ఎంట్రీలలో ఒకదానిపై, Pro++ ఆ domain కింద advertising, sponsored-ads వంటి పేర్లున్న ఐదు hostలను బ్లాక్ చేస్తుంది, domainను గానీ దాని www. పేరును గానీ బ్లాక్ చేయదు. subdomain అంతటికీ allow ఇస్తే అవి తిరిగి లోపలికి వస్తాయి.

    OPNsense సొంత parsing code, matching call ను కొన్ని పేర్లపై నడిపాను:

    Allowlist ఎంట్రీ అడిగిన పేరు అనుమతి?
    https://example.org/ example.org కాదు
    example.in example.in అవును
    example.in www.example.in కాదు
    example.in example.in.example.net అవును
    example.in example-info.de అవును
    ^www\.example\.in\.?$ www.example.in అవును
    ^www\.example\.in\.?$ advertising.example.in కాదు
    ^www\.example\.in\.?$ www.example.in.example.net కాదు

    ఆ 26 ఎంట్రీలన్నీ ఆ ఖచ్చితమైన, anchor చేసిన రూపంలో తిరిగి రాసి మార్పును apply చేశాను. tester ద్వారా Pass అయిన ప్రతి పేరు ఆ తర్వాత blocked అయింది. తన పేరే ఒక list లో ఉన్న ఒక్క ఎంట్రీ మాత్రం ఉద్దేశించినట్లే ఇప్పటికీ Pass అవుతోంది. మిగతా 25 లోని ఖచ్చితమైన పేర్లను ఏ list బ్లాక్ చేయలేదు, కాబట్టి అవి తాము రాసిన పేర్లకు ఏ పనీ చేయలేదు; వాటి ఏకైక ప్రభావం prefix లోపమే. వాటిని తొలగించకుండా anchor చేశాను, ఎందుకంటే ఒక list తర్వాత ఒక పేరును చేర్చవచ్చు. మీకూ అలాంటి ఎంట్రీలు ఉంటే, వాటిని తొలగించడం కూడా సముచితమైన ఎంపికే.

    లోతైన పరిశీలన: code, మరియు నా పరీక్షలు ఏమి చూపిస్తాయి, ఏమి చూపవు

    blocklist dialogలో ఒకే “Allowlist Domains” field ఉంది. దాని help text ప్రకారం అది domains తీసుకుంటుంది, regular expressions వాడవచ్చు, మరియు ఆ policyలోని matchesకు మాత్రమే వర్తిస్తుంది. 26.7లో:

    • src/opnsense/service/templates/OPNsense/Unbound/core/blocklists.conf ఆ fieldను excludes.patternsగా, commaలతో వేరు చేసి రాస్తుంది.
    • src/opnsense/scripts/unbound/blocklists/default_bl.py ఆ విలువను commaల వద్ద విభజిస్తుంది, ప్రతి ఎంట్రీపై strip() పిలుస్తుంది, regular expressionగా compile కాని ఎంట్రీని వదిలేస్తుంది (“skip invalid” log line తో), మిగతావాటిని, built-in .*localhost$ ఎంట్రీతో కలిపి, | తో ఒకే patternగా కలుపుతుంది.
    • src/opnsense/scripts/unbound-dnsbl/lib/__init__.py ఆ patternను case-insensitiveగా compile చేస్తుంది.
    • src/opnsense/scripts/unbound-dnsbl/lib/dnsbl.py blocklist hit తర్వాత దాన్ని r.match(domain) తో పరీక్షిస్తుంది. Python match పేరు ప్రారంభం వద్ద anchor అవుతుంది, చివర కాదు. పేరును ముందుగా lower-case చేసి, దాని చివరి చుక్కను తొలగిస్తారు.
    • CNAME target blocked అయినప్పుడు, అదే function అసలు పేరును కూడా (r.match(orig)) పరీక్షిస్తుంది, కాబట్టి allowlist చేసిన పేరు blocked alias ద్వారా కూడా resolve అవుతుంది. ఆ అసలు పేరు Unbound నుండి చివరి చుక్కతో, www.example.com. గా వస్తుంది, శుభ్రం చేయబడదు. చివర కేవలం $ ఉన్న pattern అక్కడ విఫలమవుతుంది; \.?$ రెండు మార్గాల్లోనూ Pass అవుతుంది.
    • src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php, updateBlocklistAction, Reportingలోని Allow button పిలిచేది. అది చివరి చుక్కను తొలగించి (rtrim($domain, '.')), పేరును ఉన్నది ఉన్నట్లు, escape చేయకుండా, anchor చేయకుండా save చేస్తుంది.

    OPNsense manual allowlist ఎంట్రీని, pattern ఉన్న blocklist items ను మినహాయించేదిగా వివరిస్తుంది. code ప్రారంభంలో మరింత ఇరుకుగా ఉంది, ఎందుకంటే మొదటి అక్షరం నుండి మాత్రమే సరిపోల్చుతుంది, చివర మాత్రం అంతే తెరిచి ఉంది. ఏ అర్థం తీసుకున్నా, చివరను anchor చేయడం ఎంట్రీ రాసేవారికే వదిలేశారు. అవే ఐదు ఫైళ్లను 26.7 తాజా release లో, development branch లో పోల్చాను: allowlist code మారలేదు.

    పరీక్షలు చూపేవి: 26.7 source లోని parser, matching calls ఈ ఎంట్రీలను ఎలా చూస్తాయో, రూటర్ బయట నడిపినవి, CNAME కేసును చివరి చుక్క చేర్చి simulate చేసినవి; మరియు నా రూటర్‌లో, నేను ప్రయత్నించిన ప్రతి phishing పేరుకు tester తీర్పు, allowlist చేసిన పేరుతో మొదలుకాకపోవడమే తేడా అయిన control తో పాటు, rewrite కు ముందు, తర్వాత. tester రూటర్ load చేసిన lists పై అదే matching code నడుపుతుంది, కానీ direct lookup కు మాత్రమే, కాబట్టి CNAME మార్గాన్ని అది చూపలేదు. 43 పేర్ల లెక్క రూటర్ నుండి కాదు, ప్రచురించిన lists నుండి వచ్చింది; ఆ 43 అన్నీ TIFలో ఉన్నాయి.

    మీది ఎలా తనిఖీ చేయాలి

    నాలుగు తనిఖీలు, చివరిది తప్ప అన్నీ చదవడానికి మాత్రమే:

    1. resolver logలో download కాని lists కోసం, skip అయిన allowlist ఎంట్రీల కోసం చదవండి.
    2. blocklist testerలో, blocked కావలసిన ఒక పేరును, Pass కావలసిన ఒక పేరును ప్రయత్నించి, lists load అయ్యాయో చూడండి.
    3. ప్రతి allowlist ఎంట్రీకి, ఆ ఎంట్రీ తర్వాత మీ lists బ్లాక్ చేసే domain చేర్చిన పేరును test చేయండి, తర్వాత ముందు www. ఉన్న అదే పేరును. మొదటిది Pass అయి రెండోది blocked అయితే, ఆ ఎంట్రీ తెరిచి ఉంది.
    4. తెరిచి ఉన్న ప్రతి ఎంట్రీని anchor చేసి తిరిగి రాయండి, apply చేసి, మళ్లీ test చేయండి.

    1 నుండి 3 వరకు తనిఖీల click-by-click దశలు, rewrite దశలు కింద ఉన్న రెండు లోతైన పరిశీలనలలో ఉన్నాయి. అవి sign-in పేజీ నుండి మొదలై, ప్రతి దశ ఏమి మారుస్తుందో చెబుతాయి.

    లోతైన పరిశీలన: దశలవారీగా, మీ allowlist తనిఖీ

    మొదలుపెట్టే ముందు. మీ నెట్‌వర్క్‌లోని ఒక కంప్యూటర్‌లో browser, మరియు మీ రూటర్ settings పేజీ address, login కావాలి. 1 నుండి 8 దశలు చదవడం మాత్రమే: రూటర్‌లో ఏదీ మార్చవు, కాబట్టి ఎక్కడ ఆపినా ఏదీ వెనక్కి తీసుకోనక్కర్లేదు. సుమారు పది నిమిషాలు పడుతుంది, దానికి తోడు ప్రతి test కు సుమారు పది సెకన్లు, ఎందుకంటే tester ప్రతిసారీ మొత్తం blocklistను load చేస్తుంది.

    1. browser తెరిచి, OPNsense లోకి sign in అవడానికి మీరు వాడే addressను type చేయండి. Sign in అవండి. Lobby page కనిపించాలి. page load కాకపోతే, కంప్యూటర్ మీ ఇంటి నెట్‌వర్క్‌లో ఉందో లేదో, రూటర్‌కు ఏ ఇతర మార్పు కోసమైనా వాడే అదే addressను వాడారో లేదో చూడండి.
    2. ఎడమవైపు menuలో Services, తర్వాత Unbound DNS, తర్వాత Log File click చేయండి. Date, Severity, Process, Line columns ఉన్న table కనిపించాలి. దానికి పైన search box, severity box (Warning కు set చేసి), time box (Last day కు set చేసి) ఉన్నాయి.
    3. search boxను click చేసి, blocklist అని type చేసి Enter నొక్కండి. రెండు రకాల lines ముఖ్యం. “unable to download blocklist” అంటే ఒక list load కాలేదు, అది ఏమీ చేర్చదు. “skip invalid whitelist exclude pattern” అంటే OPNsense ఒక allowlist ఎంట్రీని వదిలేసింది. table ఖాళీగా ఉంటే, గత ఒక రోజులో Warning స్థాయిలో ఏదీ log కాలేదు. “blocklist loaded” lines చూడటానికి severity boxను తెరిచి Informational ను కూడా tick చేయండి; ఇంకా వెనక్కి చూడటానికి time boxను తెరవండి.
    4. అదే menuలో Blocklists click చేసి, తర్వాత పేజీ పైన ఉన్న Tester tab click చేయండి. Domain box, Source box, Test button కనిపించాలి. Sourceను ఖాళీగా వదిలేయండి; అప్పుడు test రూటర్ స్వయంగా అడిగినట్లు నడుస్తుంది. Source ఒక device address తీసుకుంటుంది, కొన్ని devicesకు మాత్రమే వర్తించే policy మీకు ఉంటేనే అది అవసరం.
    5. Domain లో googleads.g.doubleclick.net type చేసి Test click చేయండి. సుమారు పది సెకన్లు వేచి ఉండండి. ఫలితం Block అయి ఉండాలి. తర్వాత www.youtube.com test చేయండి; అది Pass కావాలి. మొదటి పేరు Pass అయితే, ఏ list కూడా load కాలేదు, లేదా ఆ పేరు మీ సొంత allowlistలో ఉంది: 3వ దశకు వెళ్లి errors చదవండి, ఆ పేరును మీరు allowlist చేసి ఉంటే, మీ lists బ్లాక్ చేసే మరో పేరును ఎంచుకోండి. tester CNAMEలను అనుసరించదు. CNAME అంటే మరో పేరును చూపే పేరు; tester మీరు type చేసిన పేరును మాత్రమే తనిఖీ చేస్తుంది.
    6. Blocklists tab click చేయండి. మీ policy row కుడి చివర, పెన్సిల్ (Edit) click చేయండి. Edit Blocklist అనే window తెరుచుకుంటుంది. Allowlist Domains మీ ఎంట్రీలను, ఒక్కో tag గా చూపుతుంది. వాటిని చదివి, Cancel click చేయండి. ఏదీ save కాదు.
    7. ప్రతి ఎంట్రీకి, ఆ ఎంట్రీ తర్వాత మీ lists బ్లాక్ చేసే domain చేర్చిన పేరును test చేయండి. నా lists బ్లాక్ చేసే పేరు googleads.g.doubleclick.net, 5వ దశలోనిదే. మీ lists దాన్ని బ్లాక్ చేయకపోతే, అవి బ్లాక్ చేసే పేరును ఎంచుకోండి. కాబట్టి example.com ఎంట్రీకి, example.com.googleads.g.doubleclick.net type చేసి Test click చేయండి. తర్వాత ముందు www. ఉన్న అదే పేరును, www.example.com.googleads.g.doubleclick.net, test చేయండి. మీరు TIF load చేస్తే, బదులుగా ఆ list లోని ఒక పేరును వాడవచ్చు. ఇప్పటికే ^ తో మొదలై $ తో ముగిసే ఎంట్రీ anchor చేసినదే; దాన్ని వదిలేయండి.
    8. రెండు ఫలితాలను కలిపి చదవండి. మొదటిది Pass అయి రెండోది blocked అయితే, ఆ ఎంట్రీ తెరిచి ఉంది: దానితో మొదలయ్యే ప్రతి పేరునూ అది లోపలికి పంపుతుంది. దాన్ని anchor చేసి తిరిగి రాయండి. ఏ list బ్లాక్ చేయని పేరు allowlist ఏం చెప్పినా Pass అవుతుంది, కాబట్టి Pass ను లోపంగా చదివే ముందు, ఆ పేరు blocked అవుతుందని testerలో నిర్ధారించుకోండి.
    లోతైన పరిశీలన: దశలవారీగా, మీ allowlist తిరిగి రాయడం

    మొదలుపెట్టే ముందు. ఇది మీ రూటర్ filteringను మారుస్తుంది. పదిహేను నిమిషాలు పడుతుంది. ఇక్కడ పొరపాటు చాలావరకు, అనుమతించిన ఒక సైట్ load కాకపోవడంగా కనిపిస్తుంది. మీ ఇంటర్నెట్ మిగతా భాగం పనిచేస్తూనే ఉండాలి. రూటర్ మార్పును సుమారు ఒక నిమిషంలో apply చేస్తుంది (నా దానిపై 43 సెకన్లు), Unboundను restart చేయదు; నడుస్తున్న process లోకి lists load అవుతున్నట్లు log చూపుతుంది. 3వ దశ మీ పాత ఎంట్రీల కాపీని save చేస్తుంది, 8వ దశ వాటిని తిరిగి పెడుతుంది.

    1. రూటర్ settings పేజీ తెరిచి sign in అవండి. Services, తర్వాత Unbound DNS, తర్వాత Blocklists click చేయండి.
    2. మీ policy row కుడి చివర, పెన్సిల్ (Edit) click చేయండి. Edit Blocklist window తెరుచుకుంటుంది. Allowlist Domains కింద, box కింద ఉన్న చిన్న link Text click చేయండి. tags ఒక్కో line కు ఒక ఎంట్రీ ఉన్న సాదా boxగా మారతాయి, Back link కనిపిస్తుంది. మీకు ఒకటికంటే ఎక్కువ policy ఉంటే, ప్రతిదానికి దాని సొంత allowlist ఉంటుంది; ప్రతిదానికీ ఇలా చేయండి.
    3. undo కోసం ఒక కాపీ తయారుచేయండి. box లోపల click చేసి, Ctrl + A, తర్వాత Ctrl + C నొక్కండి. Notepad తెరిచి (Start menu, notepad అని type చేసి, Enter నొక్కండి), Ctrl + V నొక్కి, ఫైల్‌ను allowlist-before.txt పేరుతో మీకు మళ్లీ దొరికే ఫోల్డర్‌లో save చేయండి. ఫైల్‌లో ఒక్కో line కు ఒక ఎంట్రీ ఉండాలి.
    4. box లోని ప్రతి line ను తిరిగి రాయండి. ఇది సాదా పేర్ల కోసం; ఇప్పటికే pattern అయిన ఎంట్రీ, అంటే (.*\.)? ఉన్నది, అలాగే ఉంటుంది. మీ devices అడిగే ఖచ్చితమైన పేరును రాయండి. ప్రతి చుక్క ముందు \, మొదట ^, చివర \.?$ పెట్టండి:

      • example.in అనేది ^example\.in\.?$ అవుతుంది
      • www.example.com అనేది ^www\.example\.com\.?$ అవుతుంది

      ప్రతి line కు ఒక ఎంట్రీ ఉంచండి, spaces లేకుండా, commas లేకుండా. www. ఉన్న పేరు, అది లేని అదే పేరు రెండు వేర్వేరు పేర్లు, రెండు lines కావాలి. device ఏది అడుగుతుందో మీకు తెలియకపోతే, Reporting, Unbound DNS లో చూడండి, లేదా రెండూ list లో పెట్టండి.

    5. Back click చేయండి. lines tags గా తిరిగి వస్తాయి. ప్రతి tag కొత్త రూపంలో ఉందో చూడండి. Save click చేయండి. window మూసుకుంటుంది.

    6. table కింద ఉన్న నారింజ రంగు button Apply click చేయండి. సుమారు ఒక నిమిషం వేచి ఉండండి.
    7. ఫలితాన్ని తనిఖీ చేయండి. Services, Unbound DNS, Log File తెరిచి, blocklist కోసం search చేసి, severity boxలో Informational tick చేయండి. “updating blocklist”, తర్వాత “blocklist loaded. length is” మరియు ఒక సంఖ్య కనిపించాలి, “skip invalid” line ఉండకూడదు. తర్వాత పైన చెప్పిన tester దశలను మళ్లీ చేయండి: lookalike పేర్లు ఇప్పుడు Block అవ్వాలి. ఒక list బ్లాక్ చేసే పేరును అనుమతించే ఎంట్రీ (నా దానిలో, ఒక Google ad host కోసం ఉన్నది) ఇప్పటికీ Pass అవ్వాలి.
    8. మార్పు తర్వాత ఒక సైట్ load కావడం ఆగితే, దాన్ని undo చేయండి. Notepadలో allowlist-before.txt తెరిచి, Ctrl + A, తర్వాత Ctrl + C నొక్కండి. రూటర్‌లో 1, 2 దశలను మళ్లీ చేసి, box లోపల click చేసి, Ctrl + A, తర్వాత Ctrl + V నొక్కి పాత ఎంట్రీలను కొత్తవాటిపై paste చేసి, Back, Save, Apply click చేయండి. మీరు list చేయని పేరు అవసరమైన సైట్, ఆ ఖచ్చితమైన పేరును మీరు చేర్చే వరకు blocked గా ఉంటుంది.
    లోతైన పరిశీలన: కంప్యూటర్ నుండి allowlist మార్పును పరీక్షించడం

    మొదలుపెట్టే ముందు. ఇది రూటర్ ఉన్న నెట్‌వర్క్‌లోని Windows PC కోసం. ఇది రూటర్ DNSను ఒక పేరు అడుగుతుంది, PC సొంత DNS cacheను clear చేస్తుంది; ఇంకేదీ మార్చదు. రెండు నిమిషాలు పడుతుంది. Mac లేదా Linuxలో ఆలోచన అదే (nslookup name router-address), కానీ cache-clear కమాండ్ వేరుగా ఉంటుంది.

    1. Start menu click చేసి, powershell అని type చేసి Enter నొక్కండి. PS తో మొదలయ్యే prompt ఉన్న window తెరుచుకుంటుంది.
    2. రూటర్ addressను కనుక్కోండి. ఇది type చేసి Enter నొక్కండి:

      ipconfig

      మీరు వాడుతున్న adapter కింద Default Gateway కోసం చూడండి. ఆ address మీ రూటర్; కింది దశలు దాన్ని <router-ip> అంటాయి. మీ రూటర్ మరో రూటర్ వెనుక ఉంటే, default gateway ఆ ఇతర device కావచ్చు; మీ DNS blocklists నడిపే box address వాడండి. line ఖాళీగా ఉంటే, మీరు connect కాని adapter చూస్తున్నారు; తర్వాతి దాని వద్దకు scroll చేయండి.

    3. రూటర్‌లో Apply click చేసి ఒక నిమిషం వేచిన తర్వాత, PC cacheను clear చేయండి. Blocked answers PC cache లో ఒక గంట వరకు ఉంటాయి, కాబట్టి ఇది చేయకపోతే PC పాత answerను ఉంచుకోవచ్చు:

      ipconfig /flushdns
    4. <router-ip> స్థానంలో 2వ దశలోని addressను పెట్టి, రూటర్‌ను ఆ పేరు అడగండి. పేరు తర్వాత ఉన్న చివరి చుక్క Windows తన search suffixes ను ముందుగా ప్రయత్నించకుండా ఆపుతుంది:

      nslookup www.example.com. <router-ip>

      blocked పేరుకు 0.0.0.0 సమాధానం వస్తుంది, లేదా policyలో Return NXDOMAIN tick చేసి ఉంటే “Non-existent domain”. అనుమతించిన పేరుకు దాని నిజమైన address వస్తుంది. మొదటి రెండు lines మీ రూటర్‌ను చూపుతాయి; మిగతాది సమాధానం.

    పద్దెనిమిది lists చివరికి ఏమి చేర్చాయి

    రూటర్ resolver logలో, దాని మొదటి ఎంట్రీ నుండి మొదటి శుభ్రత వరకు, ప్రతి పూర్తి nightly update అదే పద్దెనిమిది lists ను load చేసేలా set చేసి ఉంది (వాటిలో ThreatFox కూడా, కింద చూడండి):

    • Hagezi Normal, దానికి తోడు Pro, Pro++, Ultimate Mini versions
    • Threat Intelligence Feeds (TIF) మూడు పరిమాణాలలోనూ: full, Medium, Mini
    • Gambling మూడు పరిమాణాలలోనూ
    • Fake, Pop-Up Ads, Badware Hoster, DynDNS, Anti Piracy, “Safesearch not supported”
    • OISD NSFW, Abuse.ch ThreatFox

    వీటిలో చాలావాటిని నిర్వహించే Hagezi, తన lists ను కలపడానికి తన FAQలో ఈ నియమాలు ఇస్తాడు:

    1. ఐదు Multi lists — Light, Normal, Pro, Pro++, Ultimate — ఒకదానిపై ఒకటి నిర్మితమై ఉంటాయి. ప్రతిదానిలో దాని కింది list ఉంటుంది. మీరు ఒకదాన్ని ఎంచుకోవాలి.
    2. పరిమాణం తగ్గించిన versions (Mini, మరియు TIF, Gambling కు Medium) వాటి full list కు ప్రత్యామ్నాయాలు. వాటిని full list పైన పెట్టరు.
    3. TIF మినహాయింపు. ఇది malware, cryptojacking, scams, spam, phishing లను కవర్ చేస్తుంది, మీరు ఎంచుకునే tier తో పాటు నడపడానికే ఉద్దేశించినది.

    Pro, Pro++, Ultimate, Gambling Minis ఎక్కువగా సందర్శించే domains lists లో కూడా ఉన్న పేర్లను మాత్రమే ఉంచుతాయి. TIF Mini, Gambling Mini Medium list నుండి కత్తిరించినవి. Minis ను పరిమిత మెమరీ ఉన్న devices లోని blockers కోసం తయారు చేసినవిగా Hagezi వివరిస్తాడు.

    లోతైన పరిశీలన: ఏ tier ఎవరికి, Ultimate ఖరీదు ఏమిటి

    సైట్లు పనిచేయకపోతే దాన్ని ఎవరు చూసుకుంటారో ఆ వ్యక్తికి Hagezi FAQ tiers ను జత చేస్తుంది:

    Tier ఎవరికి పనిచేయకపోయే ప్రమాదం (Hagezi రేటింగ్)
    Light పెద్ద lists ను తట్టుకోలేని blocker, లేదా Normal కూడా ఎక్కువైన సెట్టింగ్ కనిష్టం
    Normal ఎవరూ unblock చేయడానికి లేని, పర్యవేక్షణ లేని setups తక్కువ
    Pro ఎవరైనా unblock చేయగలిగే చోట; TIF తో కలిపి అతని default సిఫార్సు తక్కువ నుండి మధ్యస్థం
    Pro++ admin ఉన్న అనుభవజ్ఞులైన వినియోగదారులు మధ్యస్థం
    Ultimate admin అందుబాటులో ఉన్న, చాలా అనుభవజ్ఞులైన వినియోగదారులు ఎక్కువ

    ప్రతి tier లో native tracker lists వాటా కూడా ఉంటుంది: TVలు, ఫోన్లు, operating systems లో అంతర్నిర్మితంగా ఉన్న telemetry. Pro++ దాదాపు అన్నింటినీ బ్లాక్ చేస్తుంది; Ultimate అన్నింటినీ బ్లాక్ చేస్తుంది. Ultimate వల్ల కలిగే నష్టాలను README జాబితా చేస్తుంది: కొన్ని Facebook, Messenger functions, avatars, video effects వంటి WhatsApp అదనపు సౌకర్యాలు, Windows Spotlight, Xbox achievement history, మరియు కొన్ని సైట్లు ఆధారపడే location trackers, వీటివల్ల తప్పు regional settings, ఎక్కువ CAPTCHAs రావచ్చు.

    నా సెట్ మొదటి రెండు నియమాలను ఉల్లంఘించింది. ఈ పరిశీలన కోసం lists ను ఒకసారి download చేసి, ఒక list లోని ఏ ఎంట్రీలను మరో list ఇప్పటికే బ్లాక్ చేస్తోందో చూడటానికి వాటిని పేరు పేరుగా పోల్చాను. రూటర్ ఇంతకుముందు load చేసిన కాపీలు నా దగ్గర లేవు, ThreatFox ను నేను కొలవలేదు, కాబట్టి పదిహేడు lists ను కొలిచాను.

    ఆ పదిహేడింటిలో ఏడు, ప్రతి list లోని ఒక్క marker ఎంట్రీ మినహా, మిగతా సెట్ ద్వారా కవర్ అయ్యాయి: Pro Mini, Pro++ Mini, TIF Medium, TIF Mini, Gambling Medium, Gambling Mini, Fake. ఆ ఏడింటినీ కలిపి తొలగిస్తే, TIF Medium, Mini లో ఉండి full TIF లో లేని 15 పేర్లు పోయేవి. Pop-Up Ads తన 48,277 పేర్లలో 37 ను మిగతా సెట్‌కు చేర్చింది (Pro++ ఒక్కదానితో పోలిస్తే అది మూడింటిని చేర్చుతుంది, కింద చూడండి). DynDNS, Anti Piracy భిన్నమైనవి: ఆ lists లో సెట్‌లోని మరే list లో లేని సుమారు 1,200, సుమారు 55,000 పేర్లు ఉన్నాయి, వాటిని duplicates గా కాక, నా ఎంపికతో తొలగించాను.

    ఆ నాలుగు tier lists కలిసి 233,710 పేర్లు కలిగి ఉన్నాయి, అవన్నీ Ultimate లో ఉన్నాయి, Hagezi నాలుగు marker ఎంట్రీలు తప్ప. Pro++ ఒక్కదానితో పోలిస్తే, అవి 31,411 Pro++ ఎంట్రీలను కోల్పోయాయి, అవి ఎక్కువగా సందర్శించే lists లో లేనివి. వాటి స్థానంలో Ultimate మాత్రమే బ్లాక్ చేసే 25,040 ఎంట్రీలను (Ultimate Mini marker తో 25,041) అవి కలిగి ఉన్నాయి, అన్నీ ఎక్కువగా సందర్శించే lists నుండి. Hagezi Ultimate పనిచేయకపోయే ప్రమాదాన్ని “ఎక్కువ” అని రేట్ చేస్తాడు. వాటివల్ల కలిగిన అంతరాయాల రికార్డు నా దగ్గర లేదు, దాని కోసం నేను పరీక్షించనూ లేదు, కానీ Hagezi రేటింగ్ ప్రకారం ఆ మిశ్రమం Ultimate ప్రమాదాన్ని తీసుకుంది, Pro++ కవరేజీని కోల్పోయింది.

    లోతైన పరిశీలన: నేను ఎలా కొలిచాను, సాదా పోలిక ఎందుకు తప్పు ఫలితం ఇస్తుంది

    OPNsense Hagezi wildcard formatను వాడుతుంది, అందులో *.example.com వంటి line example.com ను, దాని కింది ప్రతి పేరును బ్లాక్ చేస్తుంది. కాబట్టి list A లోని ఎంట్రీ, list B లో ఆ ఎంట్రీ లేదా దాని parent domains ఏవైనా ఉంటే, B ద్వారా ఇప్పటికే blocked అయినట్లే.

    సాదా text పోలిక దాన్ని గుర్తించదు. comm Ultimate Mini లో “లేవు” అని 3,294 Pro++ Mini ఎంట్రీలను చూపిస్తుంది. వాటిలో ఒకటి తప్ప అన్నీ కవర్ అయ్యాయి, ఎందుకంటే Ultimate Mini బదులుగా parent domain ను బ్లాక్ చేస్తుంది. Adobe tracking domain అయిన omtrdc.net మొత్తానికి దానికి ఒకే line ఉంది, Pro++ Mini దాని 998 hosts ను ఒక్కొక్కటిగా జాబితా చేస్తుంది. మిగిలిన ఒకటి Hagezi marker ఎంట్రీ, కింద వివరించాను.

    అదే విధంగా కొలిచిన నాలుగు tier lists:

    Normal + Pro Mini + Pro++ Mini + Ultimate Mini
    ప్రత్యేక పేర్లు 233,710
    వాటిలో, Ultimate లో కూడా ఉన్నవి 4 తప్ప అన్నీ (Hagezi marker ఎంట్రీలు)
    మిశ్రమంలో లేని Pro++ ఎంట్రీలు 223,551 లో 31,411
    మిశ్రమంలోని, Ultimate మాత్రమే బ్లాక్ చేసే పేర్లు 25,040

    నేను వాడిన తనిఖీ parent domains ను పైకి నడుస్తూ చూస్తుంది. ఇది Python 3 script, Python తప్ప ఇన్‌స్టాల్ చేయాల్సినదేదీ లేదు. script మొదట ఉంది; దాన్ని save చేసి నడపడానికి దశలు ఆ తర్వాత ఉన్నాయి.

    #!/usr/bin/env python3
    """hagezi_overlap.py - how much of blocklist A is already blocked by blocklist B.
    
    Reads two Hagezi lists in the wildcard format (the /wildcard/ files, the format
    OPNsense uses). A line "*.example.com" blocks example.com and every name under
    it, so an entry of A counts as covered when the entry itself, or one of its
    parent domains, is in B. A plain text comparison (comm, diff) misses that and
    reports too many differences.
    
    Usage:  python3 hagezi_overlap.py A.txt B.txt
    Author: Vivek Sanghi. Licence: CC BY-NC-SA 4.0, as the blog.
    """
    import re
    import sys
    
    WILDCARD = re.compile(r"^\*\.[a-z0-9_-]+(\.[a-z0-9_-]+)+$")
    
    
    def load(path):
        names = set()
        try:
            f = open(path, encoding="utf-8-sig")
        except OSError as e:
            sys.exit(f"{path}: cannot open ({e.strerror})")
        with f:
            for number, line in enumerate(f, 1):
                line = line.strip().lower()
                if not line or line.startswith("#"):
                    continue
                if not WILDCARD.match(line):
                    sys.exit(f"{path}, line {number}: not a wildcard-format line "
                             "('*.example.com'). Download the /wildcard/ version of the list.")
                names.add(line[2:])
        if not names:
            sys.exit(f"{path}: no entries found; check the download")
        return names
    
    
    def covered(name, blocked):
        while True:
            if name in blocked:
                return True
            if "." not in name:
                return False
            name = name.split(".", 1)[1]
    
    
    def main():
        if len(sys.argv) != 3:
            sys.exit("usage: hagezi_overlap.py A.txt B.txt")
        a, b = load(sys.argv[1]), load(sys.argv[2])
        missing = sorted(n for n in a if not covered(n, b))
        print(f"{sys.argv[1]}: {len(a):,} entries; {len(a) - len(missing):,} already "
              f"blocked by {sys.argv[2]}; {len(missing):,} not")
        for n in missing[:10]:
            print(f"  not covered: {n}")
        if len(missing) > 10:
            print(f"  ... and {len(missing) - 10:,} more")
    
    
    if __name__ == "__main__":
        main()
    

    మొదలుపెట్టే ముందు. ఇది Windows PC కోసం. మీకు Python 3 కావాలి (3వ దశ తనిఖీ చేస్తుంది). ఈ దశలు మీ user folder లో ఒక ఫోల్డర్ సృష్టిస్తాయి, అందులో కొన్ని megabytes ఉన్న రెండు list ఫైళ్లను download చేసి, వాటిని చదువుతాయి; ఇంకేదీ మార్చవు. పది నిమిషాలు పడుతుంది. Undo చేయడానికి, File Explorer లో ఆ ఫోల్డర్‌ను delete చేయండి. Mac లేదా Linuxలో Terminal వాడండి, python3 వాడండి (py బదులు), curl వాడండి (curl.exe బదులు).

    1. Start menu click చేసి, powershell అని type చేసి Enter నొక్కండి. PS తో మొదలయ్యే prompt ఉన్న window తెరుచుకుంటుంది.
    2. ఒక ఫోల్డర్ చేసి దానిలోకి వెళ్లండి. ప్రతి line కు కొంత సమయం పడుతుంది; వాటిని ఒక్కొక్కటిగా నడపండి:

      mkdir hagezi-check
      cd hagezi-check

      prompt ఇప్పుడు hagezi-check తో ముగియాలి. మొదటి line ఆ ఫోల్డర్ ఇప్పటికే ఉందని చెబితే, మరో పేరు ఎంచుకుని రెండు lines లోనూ వాడండి.

    3. Python ఇన్‌స్టాల్ అయి ఉందో తనిఖీ చేయండి:

      py --version

      Python 3.12.4 వంటి line కనిపించాలి. PowerShell py ను గుర్తించలేదని చెబితే, python.org నుండి Python 3 ను ఇన్‌స్టాల్ చేయండి (installer లో “Add python.exe to PATH” tick చేయండి), PowerShell మూసి 1వ దశ నుండి మళ్లీ మొదలుపెట్టండి.

    4. script ఫైల్ సృష్టించండి. ఇది Notepad ను తెరుస్తుంది:

      notepad hagezi_overlap.py

      Notepad కొత్త ఫైల్ సృష్టించాలా అని అడుగుతుంది; Yes click చేయండి. పై box లోని script ను paste చేయండి (box లో Copy click చేసి, Notepad లో Ctrl + V), Ctrl + S నొక్కి, Notepad మూసివేయండి. Notepad అడగకుండా తెరుచుకుంటే, File, Save as తో save చేయండి, ఫైల్ పేరుగా కొటేషన్ మార్కుల్లో hagezi_overlap.py type చేసి, ఫోల్డర్ hagezi-check అని చూసుకుని, Save click చేయండి.

    5. రెండు lists ను ఫోల్డర్‌లోకి download చేయండి. Windowsలో, PowerShell లో curl.exe type చేయండి, curl కాదు. lines ను ఒక్కొక్కటిగా నడపండి:

      curl.exe -o pro.plus.mini.txt https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/pro.plus.mini.txt
      curl.exe -o ultimate.mini.txt https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/ultimate.mini.txt

      ప్రతిదానికి కొన్ని సెకన్లు పడుతుంది, progress table ను చూపుతుంది. ఒక line error తో ముగిస్తే, connection ను చూసి ఆ line ను మళ్లీ నడపండి.

    6. తనిఖీని నడపండి:

      py hagezi_overlap.py pro.plus.mini.txt ultimate.mini.txt
    7. ఈ పరిశీలన కోసం నేను download చేసిన lists పై ఇది ఇలా print చేసింది:

      pro.plus.mini.txt: 98,704 entries; 98,703 already blocked by ultimate.mini.txt; 1 not
        not covered: h4g3z1-pro-plus-mini.web.app

      lists రోజూ మారుతాయి కాబట్టి మీ సంఖ్యలు వేరుగా ఉంటాయి. సంఖ్యలకు బదులు ఒక సందేశం కనిపిస్తే, script ఉద్దేశపూర్వకంగా ఆగింది: ఆ సందేశాన్ని చదవండి, అది ఫైల్‌ను, line ను పేర్కొంటుంది.

    ప్రతి పోలికలో మిగిలిపోయే ఒక పేరు, Hagezi ప్రతి list లో ఉంచే marker (h4g3z1-<list>.web.app), ఏ list load అయిందో తెలుసుకోవడానికి. download విఫలమైతే, లేదా ఫైల్ మరో format లో ఉంటే, script సంఖ్యను చెప్పకుండా ఆగి ఆ విషయం చెబుతుంది.

    అవే lists పై అది ఇంకా ఇచ్చినవి:

    List A List B B ద్వారా ఇప్పటికే blocked అయిన A ఎంట్రీలు
    Normal (171,454) Pro++ marker తప్ప అన్నీ
    Pro++ (223,551) Ultimate marker తప్ప అన్నీ
    Pro Mini (86,842) Ultimate Mini marker తప్ప అన్నీ
    TIF Mini (212,777) TIF Medium marker తప్ప అన్నీ
    Gambling Mini (118,888) Gambling Medium marker తప్ప అన్నీ
    Fake (17,622) Pro++ marker తప్ప అన్నీ
    Pop-Up Ads (48,277) Pro++ 4 తప్ప అన్నీ (marker, మరో 3)
    Badware Hoster (1,088) Pro++ 966
    Ultimate Mini (120,458) Pro++ 95,417

    script ను ఈ lists పై, అలాగే లేని ఫైల్, ఖాళీ ఫైల్, comments మాత్రమే ఉన్న ఫైల్, విఫలమైన download, ఒక web page, adblock, hosts, plain-domain formats లోని lists పై పరీక్షించాను.

    load అయిన పేర్ల సంఖ్య నా మార్పులను అనుసరించలేదు. మొదటి శుభ్రత రోజున రూటర్ దానికి ముందు 2,840,117 పేర్లను, తర్వాత 3,188,234 పేర్లను load చేసింది, పద్దెనిమిదికి బదులు పది lists తో: ఆ రోజు రెండు downloads మధ్య TIF 426,519 ఎంట్రీలు పెరిగింది. నా వైపు మార్పు లేకుండానే, ఆ సంఖ్య నాలుగు రోజుల్లో 2,739,044 నుండి 3,229,041 కు మారింది. ఈ పరిశీలన కోసం నేను download చేసిన list పరిమాణాల ప్రకారం, పేర్లలో సుమారు మూడింట రెండు వంతులు TIF లో, సుమారు 7 శాతం Pro++ లో ఉన్నాయి.

    లోతైన పరిశీలన: రూటర్ గణాంకాలు, వాటి పరిమితులు

    load అయిన పేర్లు, రూటర్ log నుండి (“blocklist loaded. length is …”, ప్రత్యేక పేర్ల సంఖ్య):

    ఎప్పుడు Lists load అయిన పేర్లు
    మొదటి శుభ్రత రోజు, ముందు ఆ పద్దెనిమిది 2,840,117
    మొదటి శుభ్రత రోజు, తర్వాత కొత్త సెట్ 3,188,234
    ఐదు రోజుల తర్వాత అదే సెట్ 2,739,044
    తొమ్మిది రోజుల తర్వాత అదే సెట్ 3,229,041
    పద్దెనిమిది రోజుల తర్వాత అదే సెట్ 3,198,953

    blocked అయిన queries వాటా, Reporting → Unbound DNS నుండి:

    కాలం Queries Blocked అయినవి
    మొదటి శుభ్రత రోజు, ఆ రోజే చదివినది నమోదు చేయలేదు 12.9 శాతం
    సుమారు 38 గంటల కాలం, తర్వాత చదివినది 110,248 8,600 (7.80 శాతం)

    ఆ రెండు శాతాలు వేర్వేరు lists, వేర్వేరు రోజులు, ఆ సమయంలో నెట్‌వర్క్ ఏం చేస్తూ ఉందో దాని మీద ఆధారపడినవి. అవి ముందు-తర్వాత పోలిక కావు.

    ఇప్పుడు నేను tick చేసినవి

    నా రూటర్ settings ఇవి చూపుతాయి:

    • Hagezi Pro++ (full)
    • TIF (full)
    • Gambling (full)
    • Fake, Pop-Up Ads, Badware Hoster మరియు “Safesearch not supported”
    • OISD NSFW
    • URL ద్వారా రెండు Hagezi lists: encrypted-DNS servers, LG TV trackers
    • Abuse.ch ThreatFox, URL ద్వారా, ఉచిత key తో (కింద)

    device trackers కోసం Hagezi సిఫార్సు చేసిన Pro కంటే Pro++ ను ఎంచుకున్నాను, ఎందుకంటే వాటిలో దాదాపు అన్నింటినీ అతను Pro++ లోనే బ్లాక్ చేస్తాడు.

    వీటిలో రెండు duplicates. Fake, Pop-Up Ads Pro++ లోపలే ఉన్నాయని Hagezi cheat sheet గుర్తిస్తుంది. Fake విషయంలో కొలత ఏకీభవిస్తుంది, ఏది బ్లాక్ అవుతుందో మారకుండా దాన్ని తొలగించవచ్చు. నేను download చేసిన lists లో, Pop-Up Ads లో Pro++, TIF, Gambling, Hoster, Fake లో దేనిలోనూ లేని మూడు పేర్లు ఉన్నాయి; దాన్ని తొలగిస్తే ఆ మూడూ పోతాయి. ThreatFox ను, URL ద్వారా చేర్చిన రెండు lists ను నేను పోల్చలేదు. Fake, Pop-Up Ads రెండూ ఇప్పటికీ tick చేసి ఉన్నాయి.

    ThreatFox download కావడం ఆగిపోయి, ఇప్పుడు మళ్లీ download అవుతోంది. ప్రతి update “unable to download blocklist … and no cache available” అని log చేసింది. దాని కోసం OPNsense built-in ఎంట్రీ వాడిన address “410 Gone” అని సమాధానమిస్తుంది, abuse.ch export పేజీ host file ఇవ్వడానికి ముందు Auth-Key అడుగుతుంది. తర్వాతి 26.7 release అందుకే built-in ఎంట్రీని తొలగించి, వినియోగదారులను “URLs of Blocklists” వైపు చూపుతుంది. abuse.ch key ను తన authentication portal ద్వారా ఉచితంగా ఇస్తుంది. నేను key ను addressలో పెట్టి list ను URL ద్వారా చేర్చాను. abuse.ch export పేజీ key ను URLలో అడుగుతుంది, OPNsense downloader ఎలాంటి headers పంపదు. address రూపాన్ని కింది దశలు చూపుతాయి. దాన్ని చేర్చిన update దాని కోసం 28,889 lines తో “blocklist download” అని log చేసింది, వాటిలో 28,869 పేర్లు, error లేదు; ఆ update లో మిగతా lists cache నుండి load అయ్యాయి. load అయిన పేర్ల రూటర్ సొంత లెక్క ప్రకారం, అది 2,765,172 నుండి 2,782,246 కు పెరిగింది. కాబట్టి ఆ 28,869 లో 17,074, ఆ ఖచ్చితమైన పేరుతో ఇంతకుముందే load అయి లేవు, సుమారు 11,800 అయి ఉన్నాయి. ఈ లెక్క పేర్లను అక్షరాలా పోలుస్తుంది, కాబట్టి దాని parent domain ను మరో list ఇప్పటికే బ్లాక్ చేస్తున్న పేరు కూడా కొత్తగా లెక్కలోకి వస్తుంది. Hagezi ThreatFox ను source గా పేర్కొనడు.

    key పాస్‌వర్డ్ లాగా పనిచేస్తుంది. రూటర్ దాన్ని తన configuration లో నిల్వ చేస్తుంది, ప్రతి update key తో సహా addressను resolver logకు రాస్తుంది. మీ చేతి నుండి బయటకు వెళ్లే screenshots, shared logs, configuration backups, remote log server లలో దాన్ని ఉంచకండి. అది leak అయి ఉంటే, అదే portal నుండి కొత్త key తీసుకుని addressను మార్చండి.

    లోతైన పరిశీలన: key తో ThreatFox ను చేర్చడం

    మొదలుపెట్టే ముందు. ఇది మీ policy కి ఒక list ను చేర్చుతుంది. పది నిమిషాలు పడుతుంది. ఏదీ delete కాదు. Undo చేయడానికి, అదే box నుండి addressను తొలగించి మళ్లీ apply చేయండి.

    1. browser లో https://auth.abuse.ch తెరిచి, account లేకపోతే సృష్టించి, Auth-Key తీసుకోండి. key ఉచితం. దాన్ని ఒక text ఫైల్‌లో 4వ దశ వరకు మాత్రమే ఉంచండి; 4వ దశలో మీరు దాన్ని ఒకసారి paste చేస్తారు, ఆ తర్వాత ఆ text ఫైల్‌ను delete చేయండి.
    2. రూటర్‌లోకి login అవండి. Services, తర్వాత Unbound DNS, తర్వాత Blocklists click చేయండి.
    3. మీ policy row కుడి చివర, పెన్సిల్ (Edit) click చేయండి. Edit Blocklist అనే window తెరుచుకుంటుంది.
    4. URLs of Blocklists లోపల click చేసి, కింది addressను type చేయండి, YOUR_KEY స్థానంలో మీ key పెట్టి, spaces లేకుండా. Enter నొక్కండి, అప్పుడు అది ఒక tag గా మారుతుంది (tag అంటే field లో చిన్న boxగా కనిపించే ఒక ఎంట్రీ):

      https://threatfox-api.abuse.ch/v2/files/exports/YOUR_KEY/hostfile.txt

      key exports/ మరియు /hostfile.txt మధ్య ఉంటుంది.

    5. Save, తర్వాత Apply click చేయండి. రూటర్ lists ను మళ్లీ download చేస్తుంది; ఒకటి రెండు నిమిషాలు వేచి ఉండండి.

    6. Services, Unbound DNS, Log File click చేసి, download కోసం search చేసి, severity boxలో Informational tick చేయండి. ThreatFox address కోసం “blocklist download:” అనే line, దానితో పాటు lines సంఖ్య, కనిపించాలి. line “unable to download” అంటే, key ను, addressలో అదనపు space ఉందేమో చూడండి.
    7. ఆ screen ను share చేయవద్దు: ఆ line మీ key తో పాటు addressను చూపుతుంది.
    లోతైన పరిశీలన: Badware Hoster, URL ద్వారా చేర్చిన రెండు lists

    Badware Hoster Hagezi సొంతంగా నిలిచే list, దాని 1,088 ఎంట్రీలలో 966 ఇప్పటికే Pro++ లో ఉన్నాయి. మిగతావి threat feeds లో పదే పదే కనిపించే మొత్తం hosting providers ను బ్లాక్ చేస్తాయి. ఆ hosts లోని చట్టబద్ధమైన సైట్లు కూడా వాటితో పాటు blocked అవుతాయని Hagezi హెచ్చరిస్తాడు, వాటిని unblock చేయడాన్ని list నడిపే వారికి వదిలేస్తాడు.

    URL ద్వారా చేర్చిన రెండు lists Hagezi వే, wildcard format లో:

    https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/doh.txt
    https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/native.lgwebos.txt

    మొదటిది encrypted-DNS servers ను పేరు ద్వారా జాబితా చేస్తుంది, devices రూటర్‌ను తప్పించుకోకుండా ఆపడంలో భాగం. రెండోది LG webOS ad, tracking servers ను జాబితా చేస్తుంది. ప్రతిదానికి దాని సొంత కథ ఉంది, అవి వేరే పోస్ట్‌లకు.

    OPNsense 26.7 లోని built-in Hagezi tick-boxes, log చూపినట్లు, Hagezi mirror hagezi-mirror.dnsbunker.org నుండి download చేస్తాయి. ఆ mirror సుమారు ప్రతి నాలుగు నుండి ఎనిమిది గంటలకు కొత్త build ప్రచురిస్తుందని Hagezi చెబుతాడు; jsDelivr కాపీలు రోజుకు ఒకసారి update అవుతాయి.

    DNS బ్లాక్ చేయలేనివి

    YouTube, Instagram app లోపలి ప్రకటనలు వీడియోలు, పోస్ట్‌లు వచ్చే domains నుండే వస్తాయి, కాబట్టి పేరుతో బ్లాక్ చేస్తే కంటెంట్ కూడా బ్లాక్ అవుతుంది. Hagezi FAQ సాధారణ విషయాన్ని చెబుతుంది: కొన్ని ప్రకటనలు కంటెంట్ వచ్చే domains నుండే load అవుతాయి, వాటిని పట్టేది browser లోని content blocker, లేదా ఫోన్‌లో app-level blocker. app లోపలి ప్రకటనలను నేను అంగీకరించాను.

    DNS blocklist రూటర్‌ను అడిగే devices ను మాత్రమే filter చేస్తుంది; తమ సొంత encrypted లేదా hard-coded DNS ఉన్న devices దాన్ని తప్పించుకుంటాయి. అది వేరే పోస్ట్.

    ఇది ఎలా చేశాను

    Claude documentation, lists ను చదివి, వాటిని పోల్చి, నా logged-in browser session ద్వారా నా రూటర్‌ను చదివింది: settings, resolver log, tester. ఏం మార్చాలో నేను నిర్ణయించాను. allowlist సెషన్‌లో రూటర్‌పై జరిగిన ఏకైక మార్పు allowlist rewrite.

    model తప్పులు చేసింది. bare-name allowlist సవరణ మొదటి సెషన్ నుండి వచ్చింది, మరియు ఒక సెషన్‌లో nightly blocklist update Unbound cache ను flush చేస్తుందని కూడా అది నాకు చెప్పింది. రూటర్ log, update lists ను నడుస్తున్న Unbound లోకి, restart లేకుండా, load చేస్తున్నట్లు చూపింది. blocklist settings ను apply చేయడం Unbound ను restart చేయదని manual చెబుతుంది, source కొత్త list ను నడుస్తున్న process లోకి load చేస్తుంది. flush setting Unbound ఆగినప్పుడు మాత్రమే వర్తిస్తుంది.

    రూటర్‌పై logged-in session ఉన్న model ఒక ప్రమాదమే. అది చదివే resolver log లో, ఏ వెబ్‌సైట్ అయినా ఒక device చేత look up చేయించగల పేర్లు ఉంటాయి, ఒక పేరులో model ను నడిపించడానికి రాసిన text ఉండవచ్చు. allowlist సెషన్‌లో, allowlist మార్పు తప్ప, దాన్ని చదవడానికే పరిమితం చేశాను. అది model కు ఇచ్చిన సూచన, నియంత్రణ కాదు; read-only OPNsense user నియంత్రణ అవుతుంది. resolver log లో ThreatFox address కూడా key తో ఉంటుంది, కాబట్టి log చదివే సెషన్ key ను చూస్తుంది. మీరు ఒక model ను ఆ log చదవనిస్తే, ఆ తర్వాత key ను మార్చండి.

    మొదటి సెషన్‌లో నేను ఐదు Unbound settings, ఒక cron job ను కూడా మార్చాను. ఆరూ set అయి ఉన్నట్లు రూటర్ చూపుతుంది.

    లోతైన పరిశీలన: ప్రతి setting, DNS over TLS ను ఎలా undo చేయాలి
    Setting (పేజీ) ముందు తర్వాత
    Flush DNS Cache during reload (General) on off
    Prefetch Support (Advanced) off on
    Serve Expired Responses (Advanced) off on; TTL for Expired Responses 86,400 s
    Use System Nameservers (Query Forwarding) on off
    DNS over TLS forwarders ఏవీ లేవు Cloudflare, Quad9
    Blocklist update job (System → Settings → Cron) ఇతర jobs తో పంచుకునే slot దాని సొంత slot

    Prefetch popular entries expire కావడానికి ముందే refresh చేస్తుంది. manual ఖరీదును సుమారు 10 శాతం ఎక్కువ DNS traffic గా చెబుతుంది.

    Serve Expired Responses device ను వేచి ఉంచే బదులు cache నుండి expired record తో సమాధానం ఇస్తుంది. అది on అయినప్పుడు మరిన్ని fields కనిపిస్తాయి. “TTL for Expired Responses” గడువు ముగిసిన తర్వాత ఎంతసేపు stale answer ఇవ్వవచ్చో పరిమితం చేస్తుంది; నేను 86,400 సెకన్లు పెట్టాను, manual సూచించే 86,400 నుండి 259,200 లో కనిష్ట చివర.

    నేను పరీక్షించని ఒక పరస్పర ప్రభావం: cache flushing off గా, stale answers అనుమతించి ఉన్నప్పుడు, ఒక list కొత్తగా బ్లాక్ చేసిన పేరుకు Unbound cache నుండి కొంతకాలం సమాధానం వస్తూనే ఉండవచ్చు. ఒక block వెంటనే అమలు కాకపోతే, నేను మొదట చూసేది అదే.

    Use System Nameservers. Query Forwarding, DNS over TLS లోని ఏ catch-all ఎంట్రీ కంటే system nameservers కే ప్రాధాన్యత ఉంటుందని manual చెబుతుంది. దాన్ని off చేస్తే DNS over TLS ఎంట్రీలు queries ను పంపుతాయి. ఆ నాలుగు ఎంట్రీలు, Services → Unbound DNS → DNS over TLS కింద:

    Server IP Port Verify CN
    1.1.1.1 853 cloudflare-dns.com
    1.0.0.1 853 cloudflare-dns.com
    9.9.9.9 853 dns.quad9.net
    149.112.112.112 853 dns.quad9.net

    ఈ servers కు రూటర్ సొంత queries encrypted గా వెళ్తాయి. devices తమ సొంత encrypted DNS వాడకుండా ఆపడానికి LAN నుండి port 853 ను reject చేసే firewall rule వాటిని ఏమీ చేయదు, ఎందుకంటే అవి రూటర్ నుండే బయలుదేరతాయి.

    update సమయం దాని సొంత slot కు మారింది, కాబట్టి update ఇకపై ఇతర scheduled jobs తో సమయాన్ని పంచుకోదు.

    DNS over TLS మార్పును undo చేయడానికి:

    మొదలుపెట్టే ముందు. ఇది మీ రూటర్ DNS settings ను మారుస్తుంది, ఐదు నిమిషాలు పడుతుంది. మిగిలిన settings ద్వారా DNS పనిచేస్తూనే ఉంటుంది. ముందు ఆ నాలుగు ఎంట్రీలను (పై table) నోట్ చేసుకోండి; మార్పును తిరిగి పెట్టడానికి అవి కావాలి.

    1. రూటర్ settings పేజీ తెరిచి sign in అవండి. Lobby page కనిపించాలి.
    2. Services, తర్వాత Unbound DNS, తర్వాత DNS over TLS click చేయండి. ఒక table ఎంట్రీలను జాబితా చేస్తుంది.
    3. మొదటి row కుడి చివర, పెన్సిల్ (Edit) click చేయండి. Edit server అనే window తెరుచుకుంటుంది. Enabled ను untick చేసి Save click చేయండి. మిగతా ప్రతి row కూ ఇలాగే చేయండి.
    4. అదే పేజీ పైన, Use System Nameservers ను tick చేయండి. అదే box Query Forwarding కింద కూడా కనిపిస్తుంది; అది ఒకే setting.
    5. పేజీ అడుగున Apply click చేయండి. Unbound కొన్ని సెకన్లలో reload అవుతుంది.
    6. తనిఖీ: నెట్‌వర్క్‌లోని ఒక device నుండి, ఈ రోజు మీరు సందర్శించని ఏ వెబ్‌సైట్‌నైనా తెరవండి. అది load కావాలి. System, Settings, General లో nameservers లేకపోతే, Unbound forwarding చేయకుండా root servers నుండి స్వయంగా resolve చేస్తుంది; మీ provider servers వాడాలంటే వాటిని అక్కడ చేర్చండి.
    7. మార్పును తిరిగి పెట్టడానికి, ప్రతి ఎంట్రీపై Enabled ను మళ్లీ tick చేసి, Use System Nameservers ను untick చేసి, Apply click చేయండి.

    మూలాలు

    การแก้ไขที่ปล่อยให้ชื่อ phishing ผ่านเข้ามา

    แปลจากต้นฉบับภาษาอังกฤษ คำสั่ง โค้ด และศัพท์เทคนิคคงเป็นภาษาอังกฤษไว้

    ในวันเสาร์วันหนึ่งของเดือนตุลาคม ผมแก้ 4 รายการที่เสียใน allowlist ของ DNS บน router ของผม หลังจากนั้นสองสัปดาห์เศษ ผมพบว่ารายการที่แก้แล้วปล่อยให้ชื่อใน threat feed ผ่านเข้ามา ซึ่งเป็นชื่อที่ถูกสร้างให้ดูเหมือนเว็บไซต์ที่ผมตั้งใจ allow ไว้ คือโดเมนของเว็บชำระเงินตามด้วย .https. และโดเมนอื่นที่ไม่เกี่ยวกัน หรือชื่อร้านค้าที่ใช้ขีดกลางแทนจุด tester ของ router เองก็ปล่อยชื่อเหล่านี้ผ่าน

    ในเย็นวันเดียวกัน ผมลด blocklist จาก 18 เหลือ 10 วันรุ่งขึ้นผมเพิ่ม list ของ LG TV อีกหนึ่ง ทำให้เป็น 11 7 list ในจำนวนนั้นมีชุดที่เหลือครอบคลุมอยู่แล้ว list หนึ่งที่ผมเก็บไว้คือ Abuse.ch ThreatFox หยุดดาวน์โหลดเมื่อ abuse.ch เริ่มแจก host file ให้เฉพาะผู้ที่มี key ตอนนี้มันดาวน์โหลดได้อีกครั้ง หลังจากผมใส่ key ฟรีไว้ในที่อยู่ของมัน ส่วนโฆษณาภายใน YouTube และ Instagram บนโทรศัพท์ของผมเข้ามาตลอด ซึ่ง blocklist ใดก็เปลี่ยนไม่ได้

    จากนั้นผมเขียนรายการ allowlist ใหม่ โพสต์นี้เล่าถึงการล้างทั้งสองครั้ง ได้แก่ OPNsense ทำอะไรกับรายการ allowlist วิธีตรวจรายการของคุณเอง และ list 18 รายการที่ซ้อนกันรวมกันแล้วได้อะไร ผมทำงานนี้กับ Claude ใน 2 session หนึ่ง session ต่อการล้างหนึ่งครั้ง ส่วน key ของ ThreatFox ใส่ไปใน session ที่สาม Claude อ่าน router ผ่าน browser ของผม ทุกการเปลี่ยนแปลงบน router ผมเป็นผู้อนุมัติ ผมอนุมัติการแก้ด้วยชื่อเปล่า (bare name) การอนุมัติจึงไม่ได้ป้องกันความผิดพลาดนั้น

    ไม่คุ้นกับ command line? วิธีอ่านกล่องต่าง ๆ

    PS> หมายถึง พิมพ์คำสั่งนี้ใน PowerShell บน Windows (เมนู Start → พิมพ์ powershell → Enter) $ หมายถึง พิมพ์ใน terminal บน Linux หรือ Mac หรือบน Pi หลังจากคุณล็อกอินด้วย ssh แล้ว อย่าพิมพ์ $ หรือ PS> เอง

    แต่ละบรรทัดที่ขึ้นต้นด้วย $ หรือ PS> คือคำสั่ง 1 คำสั่ง คลิกที่ $ นั้นเพื่อคัดลอกเฉพาะบรรทัดนั้น วาง กด Enter และรอจนเสร็จก่อนทำบรรทัดถัดไป กล่องที่มีปุ่ม Copy ด้านบนมี 1 คำสั่ง (หรือ 1 ไฟล์) ให้คัดลอกทั้งกล่อง กล่องเส้นประแสดงสิ่งที่คุณควรเห็นตอบกลับมา คุณไม่ต้องพิมพ์มัน

    Allowlist

    allowlist ของ blocklist policy ของผมมี 26 รายการ ในวันที่ล้างครั้งแรก 4 รายการดูเหมือนเสีย สามรายการถูกวางมาจากแถบที่อยู่ของ browser เป็นที่อยู่เต็ม ในรูป https://example.org/ รายการที่สี่มีช่องว่างหนึ่งช่องหน้าตัวอักษรแรกของชื่อ ผมแทนที่ทั้ง 4 รายการด้วยชื่อเปล่า เช่น example.in ผมไม่ได้ดูว่า 22 รายการที่เหลือเขียนไว้อย่างไร และประวัติ configuration ของ router ย้อนกลับไปไม่ไกลพอที่จะตรวจได้อีก ถ้ารายการเหล่านั้นเป็นชื่อเปล่า ตามที่ปุ่ม Allow ของ router เองเขียนไว้ ช่องโหว่ก็มีอยู่ก่อนที่ผมแก้ และการแก้ของผมขยายช่องโหว่ไปถึง 3 รายการที่เดิมไม่จับคู่กับชื่อใดเลย

    log ของ router แสดงรายการที่ห้า เป็นรายการที่เขียนเป็น *.ntp.org ซึ่งลบไปแล้ว การอัปเดตทุกคืนบันทึก “skip invalid whitelist exclude pattern” ไว้สำหรับรายการนี้ เครื่องหมาย * นำหน้าใช้ไม่ได้ใน regular expression ของ Python router จึงทิ้งรายการนั้นทุกคืนและแจ้งไว้ใน log เท่านั้น รูปแบบที่ทำสิ่งที่ตั้งใจไว้คือ (.*\.)?ntp\.org\.?$

    ต่อมา Claude อ่านโค้ดที่ใช้ allowlist ใน OPNsense 26.7 ช่องว่างนำหน้าไม่ได้ก่อความเสียหาย โค้ดตัดช่องว่างออกจากทุกรายการ ปัญหาอยู่ที่ชื่อเปล่า

    OPNsense ถือแต่ละรายการเป็น regular expression ไม่สนใจตัวพิมพ์เล็กใหญ่ และตรวจกับส่วนต้นของชื่อที่อุปกรณ์ถาม ไม่มีสิ่งใดผูกรายการกับท้ายชื่อ และจุดที่ไม่ได้ escape จับคู่กับอักขระใดก็ได้ ดังนั้น example.com เปล่า ๆ อนุญาต example.com แต่ไม่อนุญาต www.example.com และยังอนุญาตชื่อใดก็ตามที่ขึ้นต้นด้วยตัวอักษรเหล่านั้น โดยมีอักขระใดก็ได้แทนแต่ละจุด: example.com.evil.net, example-com.evil.net, example.community

    threat feed มีชื่อที่มีรูปแบบนั้นพอดี คือชื่อของเว็บไซต์ที่รู้จักกันดีตามด้วย .https. และโดเมนที่ไม่เกี่ยวกัน หรือชื่อเว็บไซต์นั้นโดยใช้ขีดกลางแทนจุด บน feed ที่ผมดาวน์โหลดมาสำหรับการตรวจครั้งนี้ 7 จาก 26 รายการของผมจับคู่กับชื่อแบบนี้ 43 ชื่อ รายการหนึ่งจับคู่ 20 ชื่อ บน tester ของ router ผม ชื่อแบบนี้ 5 ชื่อที่ผมลองผ่านทุกชื่อ ขณะที่ชื่อเดียวกันที่มี www. นำหน้า ซึ่งถูกบล็อกโดยรายการเดียวกันใน list ก็ถูกบล็อก ชื่อที่ผมประกอบเองจากเว็บไซต์ที่ allow ไว้กับโดเมนที่ threat feed บล็อกก็ผ่านเช่นกัน ตามโค้ดที่จับคู่ ทุกรายการชื่อเปล่าอนุญาตชื่อใดก็ตามที่ขึ้นต้นด้วยมัน ไม่ว่ามี list ใดบล็อกชื่อนั้นหรือไม่

    ปุ่ม Allow ของ OPNsense เอง ใน Reporting → Unbound DNS บันทึกชื่อเปล่าแบบเดียวกัน รายการที่เพิ่มจากที่นั่นจึงทำงานแบบเดียวกัน

    วิธีแก้คือ allow ชื่อที่ตรงทุกตัว โดยผูกทั้งสองปลาย:

    ^www\.example\.com\.?$

    เครื่องหมาย backslash ทำให้จุดเป็นจุดจริง และ $ ผูก pattern กับท้ายชื่อ \.? อนุญาตจุดท้ายที่ชื่อมีอยู่ใน 1 จาก 2 เส้นทางที่โค้ดตรวจ (ดูส่วนเจาะลึก) ^ ทำซ้ำสิ่งที่โค้ดทำอยู่แล้ว การละไว้จึงใช้ได้เช่นกัน ผมคงไว้เพื่อให้ pattern อ่านเหมือนกันทุกที่ ขั้นตอนตรวจและเขียนรายการของคุณใหม่อยู่ในส่วนเจาะลึกภายใต้ “วิธีตรวจของคุณ”

    การ allow โดเมนพร้อม subdomain ทั้งหมด ใช้ (.*\.)?example\.com\.?$ ได้ แต่ก็อนุญาต host ที่ list จงใจบล็อกไว้ใต้โดเมนนั้นด้วย ในรายการหนึ่งของผม Pro++ บล็อก 5 host ใต้โดเมน ด้วยชื่อเช่น advertising และ sponsored-ads และไม่บล็อกโดเมนเอง หรือชื่อ www. ของมัน การ allow ทั้ง subdomain จะปล่อย host เหล่านั้นกลับเข้ามา

    ผมรันโค้ด parsing ของ OPNsense เองและ call ที่ใช้จับคู่ กับชื่อบางชื่อ:

    รายการ allowlist ชื่อที่ถูกถาม อนุญาตหรือไม่
    https://example.org/ example.org ไม่
    example.in example.in ใช่
    example.in www.example.in ไม่
    example.in example.in.example.net ใช่
    example.in example-info.de ใช่
    ^www\.example\.in\.?$ www.example.in ใช่
    ^www\.example\.in\.?$ advertising.example.in ไม่
    ^www\.example\.in\.?$ www.example.in.example.net ไม่

    ผมเขียนทั้ง 26 รายการใหม่ในรูปแบบที่ตรงและผูกหัวท้ายนั้น แล้ว apply การเปลี่ยนแปลง ทุกชื่อที่เคยผ่าน tester ถูกบล็อกหลังจากนั้น รายการหนึ่งที่ชื่อของมันเองอยู่ใน list ยังผ่านตามที่ตั้งใจ ชื่อที่ตรงใน 25 รายการที่เหลือไม่ถูก list ใดบล็อก รายการเหล่านั้นจึงไม่ได้ทำงานให้กับชื่อที่มันสะกด ผลอย่างเดียวของมันคือช่องโหว่คำนำหน้า ผมผูกหัวท้ายแทนที่จะลบ เพราะ list อาจเพิ่มชื่อนั้นเข้ามาภายหลัง ถ้าคุณมีรายการแบบนั้น การลบก็เป็นทางเลือกที่สมเหตุสมผล

    เจาะลึก: โค้ด และสิ่งที่การทดสอบของผมแสดงและไม่แสดง

    dialog ของ blocklist มีช่อง “Allowlist Domains” ช่องเดียว ข้อความช่วยเหลือของช่องบอกว่ารับโดเมน ใช้ regular expression ได้ และใช้กับรายการที่ตรงใน policy นั้นเท่านั้น ใน 26.7:

    • src/opnsense/service/templates/OPNsense/Unbound/core/blocklists.conf เขียนช่องนี้เป็น excludes.patterns คั่นด้วยจุลภาค
    • src/opnsense/scripts/unbound/blocklists/default_bl.py แยกค่านั้นที่เครื่องหมายจุลภาค เรียก strip() กับแต่ละรายการ ทิ้งรายการที่ compile เป็น regular expression ไม่ได้ (พร้อมบรรทัด log “skip invalid”) และรวมรายการที่เหลือ พร้อมรายการ .*localhost$ ที่มีมาในตัว เป็น pattern เดียวด้วย |
    • src/opnsense/scripts/unbound-dnsbl/lib/__init__.py compile pattern โดยไม่สนใจตัวพิมพ์เล็กใหญ่
    • src/opnsense/scripts/unbound-dnsbl/lib/dnsbl.py ทดสอบด้วย r.match(domain) หลังจากพบชื่อใน blocklist match ของ Python ผูกที่ต้นชื่อ ไม่ผูกที่ท้าย ชื่อถูกแปลงเป็นตัวพิมพ์เล็กและตัดจุดท้ายออกก่อน
    • เมื่อเป้าหมายของ CNAME ถูกบล็อก ฟังก์ชันเดียวกันจะทดสอบชื่อเดิม (r.match(orig)) ด้วย ชื่อที่อยู่ใน allowlist จึงยัง resolve ผ่าน alias ที่ถูกบล็อกได้ ชื่อเดิมนั้นมาจาก Unbound พร้อมจุดท้าย www.example.com. และไม่ถูกตัดจุดท้ายออก pattern ที่ลงท้ายด้วย $ เปล่า ๆ ล้มเหลวที่นั่น \.?$ ผ่านทั้งสองเส้นทาง
    • src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php, updateBlocklistAction คือสิ่งที่ปุ่ม Allow ใน Reporting เรียก มันลบจุดท้าย (rtrim($domain, '.')) และบันทึกชื่อตามที่เป็น ไม่ escape และไม่ผูกหัวท้าย

    คู่มือของ OPNsense อธิบายรายการ allowlist ว่าเป็นการยกเว้นรายการ blocklist ที่มี pattern อยู่ในนั้น โค้ดแคบกว่าที่ต้นชื่อ เพราะจับคู่จากอักขระแรกเท่านั้น และเปิดกว้างเท่ากันที่ปลาย ไม่ว่าจะอ่านแบบใด การผูกปลายเป็นหน้าที่ของผู้เขียนรายการ ผมเทียบไฟล์ 5 ไฟล์เดิมนี้ใน release 26.7 ล่าสุดกับ development branch โค้ด allowlist ไม่เปลี่ยน

    สิ่งที่การทดสอบแสดง คือ parser และ matching call ใน source 26.7 จัดการรายการเหล่านี้อย่างไร รันนอก router โดยจำลองกรณี CNAME ด้วยการเติมจุดท้าย และบน router ของผม ผลของ tester สำหรับแต่ละชื่อ phishing ที่ผมลอง เทียบกับตัวควบคุมที่ต่างกันเพียงไม่ได้ขึ้นต้นด้วยชื่อที่อยู่ใน allowlist ทั้งก่อนและหลังการเขียนใหม่ tester รันโค้ดจับคู่เดียวกันกับ list ที่ router โหลดไว้ แต่ใช้ได้เฉพาะกับการ lookup ตรง จึงแสดงเส้นทาง CNAME ไม่ได้ จำนวน 43 ชื่อมาจาก list ที่เผยแพร่ ไม่ได้มาจาก router ทั้ง 43 ชื่ออยู่บน TIF

    วิธีตรวจของคุณ

    ตรวจ 4 อย่าง ทั้งหมดอ่านอย่างเดียวจนถึงอย่างสุดท้าย:

    1. อ่าน resolver log เพื่อหา list ที่ดาวน์โหลดไม่สำเร็จ และรายการ allowlist ที่ถูกข้าม
    2. ใน tester ของ blocklist ลองชื่อที่ควรถูกบล็อกหนึ่งชื่อ และชื่อที่ควรผ่านหนึ่งชื่อ เพื่อดูว่า list โหลดอยู่
    3. สำหรับแต่ละรายการ allowlist ให้ทดสอบรายการนั้นตามด้วยโดเมนที่ list ของคุณบล็อก แล้วทดสอบชื่อเดียวกันโดยมี www. นำหน้า ถ้าชื่อแรกผ่านและชื่อที่สองถูกบล็อก รายการนั้นเปิดอยู่
    4. เขียนแต่ละรายการที่เปิดอยู่ใหม่แบบผูกหัวท้าย apply แล้วทดสอบอีกครั้ง

    ขั้นตอนคลิกทีละขั้นสำหรับข้อ 1 ถึง 3 และสำหรับการเขียนใหม่อยู่ในส่วนเจาะลึก 2 ส่วนด้านล่าง ขั้นตอนเริ่มจากหน้า sign-in และบอกว่าแต่ละขั้นเปลี่ยนอะไร

    เจาะลึก: ทีละขั้น การตรวจ allowlist ของคุณ

    ก่อนเริ่ม คุณต้องมี browser บนคอมพิวเตอร์ในเครือข่ายของคุณ และที่อยู่กับข้อมูลล็อกอินของหน้าตั้งค่า router ขั้นที่ 1 ถึง 8 อ่านอย่างเดียว ไม่เปลี่ยนอะไรบน router คุณจึงหยุดตรงไหนก็ได้โดยไม่ต้องย้อนอะไร ใช้เวลาประมาณ 10 นาที บวกประมาณ 10 วินาทีต่อการทดสอบหนึ่งครั้ง เพราะ tester โหลด blocklist ทั้งชุดทุกครั้ง

    1. เปิด browser และพิมพ์ที่อยู่ที่คุณใช้ sign in เข้า OPNsense แล้ว sign in คุณควรเห็นหน้า Lobby ถ้าหน้าไม่โหลด ให้ตรวจว่าคอมพิวเตอร์อยู่ในเครือข่ายบ้านของคุณ และคุณใช้ที่อยู่เดียวกับที่ใช้เปลี่ยนค่าอื่นของ router
    2. ในเมนูทางซ้าย คลิก Services แล้ว Unbound DNS แล้ว Log File คุณควรเห็นตารางที่มีคอลัมน์ Date, Severity, Process และ Line ด้านบนมีช่องค้นหา ช่อง severity (ตั้งเป็น Warning) และช่องเวลา (ตั้งเป็น Last day)
    3. คลิกช่องค้นหา พิมพ์ blocklist แล้วกด Enter บรรทัดที่สำคัญมี 2 แบบ “unable to download blocklist” หมายความว่า list โหลดไม่สำเร็จและไม่ได้ช่วยอะไรเลย “skip invalid whitelist exclude pattern” หมายความว่า OPNsense ทิ้งรายการ allowlist ถ้าตารางว่าง แปลว่าในวันที่ผ่านมาไม่มีการบันทึกระดับ Warning เปิดช่อง severity แล้วติ๊ก Informational เพิ่มเพื่อดูบรรทัด “blocklist loaded” เปิดช่องเวลาเพื่อดูย้อนไปไกลกว่านั้น
    4. ในเมนูเดียวกัน คลิก Blocklists แล้วแท็บ Tester ที่ด้านบนของหน้า คุณควรเห็นช่อง Domain ช่อง Source และปุ่ม Test ปล่อยช่อง Source ว่างไว้ การทดสอบจะรันในฐานะตัว router เอง ช่อง Source รับที่อยู่ของอุปกรณ์ และสำคัญเฉพาะเมื่อคุณมี policy ที่ใช้กับอุปกรณ์บางเครื่อง
    5. พิมพ์ googleads.g.doubleclick.net ในช่อง Domain แล้วคลิก Test รอประมาณ 10 วินาที ผลควรเป็น Block จากนั้นทดสอบ www.youtube.com ควรเป็น Pass ถ้าชื่อแรกผ่าน แปลว่าไม่มี list ใดโหลดอยู่ หรือชื่อนั้นอยู่ใน allowlist ของคุณเอง ให้กลับไปขั้นที่ 3 และอ่านข้อผิดพลาด และถ้าคุณ allow ชื่อนั้นไว้ ให้เลือกชื่ออื่นที่ list ของคุณบล็อก tester ไม่ตาม CNAME CNAME คือชื่อที่ชี้ไปยังอีกชื่อหนึ่ง tester ตรวจเฉพาะชื่อที่คุณพิมพ์
    6. คลิกแท็บ Blocklists จากนั้นที่ปลายด้านขวาของแถว policy ของคุณ คลิกไอคอนดินสอ (Edit) หน้าต่างชื่อ Edit Blocklist เปิดขึ้น Allowlist Domains แสดงรายการของคุณ รายการละ 1 tag อ่านแล้วคลิก Cancel ไม่มีอะไรถูกบันทึก
    7. สำหรับแต่ละรายการ ให้ทดสอบรายการนั้นตามด้วยโดเมนที่ list ของคุณบล็อก ชื่อที่ list ของผมบล็อกคือ googleads.g.doubleclick.net ตัวเดียวกับในขั้นที่ 5 ถ้า list ของคุณไม่บล็อกชื่อนี้ ให้เลือกชื่อที่ list ของคุณบล็อก ดังนั้นสำหรับรายการ example.com พิมพ์ example.com.googleads.g.doubleclick.net แล้วคลิก Test จากนั้นทดสอบชื่อเดียวกันโดยมี www. นำหน้า www.example.com.googleads.g.doubleclick.net ถ้าคุณโหลด TIF คุณใช้ชื่อจาก list นั้นแทนได้ รายการที่ขึ้นต้นด้วย ^ และลงท้ายด้วย $ อยู่แล้วคือรายการที่ผูกหัวท้ายแล้ว ให้ข้ามไป
    8. อ่านผลทั้งสองร่วมกัน ถ้าชื่อแรกผ่านและชื่อที่สองถูกบล็อก รายการนั้นเปิดอยู่ มันปล่อยผ่านทุกชื่อที่ขึ้นต้นด้วยมัน ให้เขียนใหม่แบบผูกหัวท้าย ชื่อที่ไม่มี list ใดบล็อกจะผ่านไม่ว่า allowlist จะระบุอย่างไร ดังนั้นให้ยืนยันใน tester ว่าชื่อนั้นถูกบล็อกก่อนจะอ่านผล Pass เป็นข้อบกพร่อง
    เจาะลึก: ทีละขั้น การเขียน allowlist ของคุณใหม่

    ก่อนเริ่ม ขั้นตอนนี้เปลี่ยนการกรองของ router ควรเผื่อเวลา 15 นาที ความผิดพลาดที่นี่ส่วนใหญ่แสดงเป็นเว็บไซต์ที่ allow ไว้ 1 แห่งโหลดไม่ขึ้น อินเทอร์เน็ตส่วนที่เหลือควรยังทำงานอยู่ router ใช้การเปลี่ยนแปลงภายในประมาณ 1 นาที (43 วินาทีบนเครื่องผม) และไม่ restart Unbound log แสดง list โหลดเข้าสู่ process ที่กำลังรันอยู่ ขั้นที่ 3 เก็บสำเนารายการเก่าของคุณ และขั้นที่ 8 ใส่กลับคืน

    1. เปิดหน้าตั้งค่าของ router แล้ว sign in คลิก Services แล้ว Unbound DNS แล้ว Blocklists
    2. ที่ปลายด้านขวาของแถว policy ของคุณ คลิกไอคอนดินสอ (Edit) หน้าต่าง Edit Blocklist เปิดขึ้น ใต้ Allowlist Domains คลิก Text ซึ่งเป็นลิงก์เล็ก ๆ ใต้ช่อง tag จะกลายเป็นช่องธรรมดาที่มี 1 รายการต่อบรรทัด และลิงก์ Back ปรากฏขึ้น ถ้าคุณมี policy มากกว่า 1 อัน แต่ละอันมี allowlist ของตัวเอง ให้ทำกับทุกอัน
    3. ทำสำเนาไว้เผื่อย้อนกลับ คลิกในช่อง กด Ctrl + A แล้ว Ctrl + C เปิด Notepad (เมนู Start พิมพ์ notepad กด Enter) กด Ctrl + V และบันทึกไฟล์เป็น allowlist-before.txt ในโฟลเดอร์ที่คุณจะหาเจออีก ไฟล์ควรมี 1 รายการต่อบรรทัด
    4. เขียนแต่ละบรรทัดในช่องใหม่ ขั้นนี้ใช้กับชื่อธรรมดา รายการที่เป็น pattern อยู่แล้ว เช่นรายการที่มี (.*\.)? คงไว้ตามเดิม เขียนชื่อที่ตรงตามที่อุปกรณ์ของคุณถาม ใส่ \ หน้าทุกจุด ใส่ ^ ที่ต้น และ \.?$ ที่ท้าย:

      • example.in กลายเป็น ^example\.in\.?$
      • www.example.com กลายเป็น ^www\.example\.com\.?$

      ให้มี 1 รายการต่อบรรทัด ไม่มีช่องว่าง และไม่มีจุลภาค ชื่อที่มี www. กับชื่อเดียวกันที่ไม่มีเป็น 2 ชื่อ และต้องใช้ 2 บรรทัด ถ้าคุณไม่แน่ใจว่าอุปกรณ์ถามชื่อไหน ให้ดูใน Reporting → Unbound DNS หรือใส่ทั้งสองชื่อไว้ในรายการ

    5. คลิก Back บรรทัดจะกลับเป็น tag ตรวจว่าทุก tag อยู่ในรูปแบบใหม่ คลิก Save หน้าต่างปิด

    6. คลิก Apply ซึ่งเป็นปุ่มสีส้มใต้ตาราง รอประมาณ 1 นาที
    7. ตรวจผล เปิด Services, Unbound DNS, Log File ค้นหา blocklist และติ๊ก Informational ในช่อง severity คุณควรเห็น “updating blocklist” แล้ว “blocklist loaded. length is” และตัวเลข และไม่มีบรรทัด “skip invalid” จากนั้นทำขั้นตอนของ tester ซ้ำจากข้างต้น ชื่อที่หน้าตาคล้ายกันควรเป็น Block แล้ว รายการที่ allow ชื่อที่ list บล็อก (บนเครื่องผมคือรายการสำหรับ ad host ของ Google) ควรยังเป็น Pass
    8. ถ้าเว็บไซต์หยุดโหลดหลังการเปลี่ยนแปลง ให้ย้อนกลับ เปิด allowlist-before.txt ใน Notepad กด Ctrl + A แล้ว Ctrl + C ใน router ทำขั้นที่ 1 และ 2 ซ้ำ คลิกในช่อง กด Ctrl + A แล้ว Ctrl + V เพื่อวางรายการเก่าทับรายการใหม่ คลิก Back, Save และ Apply เว็บไซต์ที่ต้องการชื่อที่คุณไม่ได้ใส่ไว้จะถูกบล็อกจนกว่าคุณจะเพิ่มชื่อที่ตรงนั้น
    เจาะลึก: ทดสอบการเปลี่ยน allowlist จากคอมพิวเตอร์

    ก่อนเริ่ม ส่วนนี้สำหรับ Windows PC ในเครือข่ายเดียวกับ router มันถาม DNS ของ router หา 1 ชื่อ และล้าง DNS cache ของ PC เอง ไม่เปลี่ยนอย่างอื่น ใช้เวลา 2 นาที บน Mac หรือ Linux แนวคิดเหมือนกัน (nslookup name router-address) แต่คำสั่งล้าง cache ต่างกัน

    1. คลิกเมนู Start พิมพ์ powershell แล้วกด Enter หน้าต่างเปิดขึ้นพร้อม prompt ที่ขึ้นต้นด้วย PS
    2. หาที่อยู่ของ router พิมพ์คำสั่งนี้แล้วกด Enter:

      ipconfig

      มองหา Default Gateway ใต้ adapter ที่คุณใช้ ที่อยู่นั้นคือ router ของคุณ ขั้นตอนด้านล่างเรียกมันว่า <router-ip> ถ้า router ของคุณอยู่หลัง router อีกตัว default gateway อาจเป็นอุปกรณ์อีกตัวนั้น ให้ใช้ที่อยู่ของกล่องที่รัน DNS blocklist ของคุณ ถ้าบรรทัดว่าง คุณกำลังดู adapter ที่ไม่ได้เชื่อมต่อ ให้เลื่อนไปอันถัดไป

    3. หลังคลิก Apply บน router และรอ 1 นาที ให้ล้าง cache ของ PC คำตอบที่ถูกบล็อกมีอายุ 1 ชั่วโมง ถ้าไม่ล้าง PC อาจเก็บคำตอบเก่าไว้:

      ipconfig /flushdns
    4. ถาม router หาชื่อ โดยแทน <router-ip> ด้วยที่อยู่จากขั้นที่ 2 จุดสุดท้ายหลังชื่อกันไม่ให้ Windows ลอง search suffix ก่อน:

      nslookup www.example.com. <router-ip>

      ชื่อที่ถูกบล็อกตอบ 0.0.0.0 หรือ “Non-existent domain” ถ้าติ๊ก Return NXDOMAIN บน policy ชื่อที่ allow ตอบด้วยที่อยู่จริงของมัน 2 บรรทัดแรกแสดง router ของคุณ ที่เหลือคือคำตอบ

    18 list รวมกันได้อะไร

    ใน resolver log ของ router ตั้งแต่บรรทัดแรกจนถึงการล้างครั้งแรก ทุกการอัปเดตเต็มตอนกลางคืนถูกตั้งให้โหลด 18 list ชุดเดียวกัน (รวม ThreatFox ดูด้านล่าง):

    • Hagezi Normal บวกรุ่น Mini ของ Pro, Pro++ และ Ultimate
    • Threat Intelligence Feeds (TIF) ทั้ง 3 ขนาด: full, Medium และ Mini
    • Gambling ทั้ง 3 ขนาด
    • Fake, Pop-Up Ads, Badware Hoster, DynDNS, Anti Piracy และ “Safesearch not supported”
    • OISD NSFW และ Abuse.ch ThreatFox

    Hagezi ผู้ดูแล list เหล่านี้ส่วนใหญ่ ให้กฎการรวม list ของเขาไว้ใน FAQ:

    1. Multi list ทั้ง 5 ได้แก่ Light, Normal, Pro, Pro++ และ Ultimate ต่อยอดกัน แต่ละ list มี list ระดับล่างรวมอยู่ คุณเลือก 1 list
    2. รุ่นที่ปรับขนาด (Mini และ Medium สำหรับ TIF และ Gambling) เป็นทางเลือกแทน list เต็มของมัน ไม่ใช่สิ่งที่วางซ้อนบน list เต็ม
    3. TIF เป็นข้อยกเว้น มันครอบคลุม malware, cryptojacking, scam, spam และ phishing และตั้งใจให้รันควบคู่กับ tier ใดก็ตามที่คุณเลือก

    Mini ของ Pro, Pro++, Ultimate และ Gambling เก็บเฉพาะชื่อที่ปรากฏอยู่ใน list ของโดเมนที่ถูกเข้าชมมากที่สุดด้วย TIF Mini และ Gambling Mini ตัดมาจาก list Medium Hagezi อธิบายว่า Mini ทำมาสำหรับตัวบล็อกบนอุปกรณ์ที่มีหน่วยความจำจำกัด

    เจาะลึก: tier ไหนเหมาะกับใคร และ Ultimate มีต้นทุนอะไร

    FAQ ของ Hagezi จับคู่ tier กับคนที่จะจัดการเมื่อมีสิ่งใช้งานไม่ได้:

    Tier เหมาะกับ ความเสี่ยงที่ใช้งานไม่ได้ (การจัดระดับของ Hagezi)
    Light blocker ที่รับ list ใหญ่ไม่ไหว หรือการตั้งค่าที่แม้ Normal ก็มากเกินไป น้อยที่สุด
    Normal การตั้งค่าที่ไม่มีคนดูแล และไม่มี admin คอยปลดบล็อก ต่ำ
    Pro มีคนปลดบล็อกให้ได้ เป็นคำแนะนำเริ่มต้นของเขา คู่กับ TIF ต่ำถึงปานกลาง
    Pro++ ผู้ใช้ที่มีประสบการณ์และมี admin ปานกลาง
    Ultimate ผู้ใช้ที่มีประสบการณ์มากและมี admin อยู่ สูง

    แต่ละ tier ยังมีส่วนแบ่งของ list tracker ในตัวอุปกรณ์ (native tracker) คือ telemetry ที่ฝังอยู่ใน TV โทรศัพท์ และระบบปฏิบัติการ Pro++ บล็อกเกือบทั้งหมด Ultimate บล็อกทั้งหมด README ระบุสิ่งที่ Ultimate ต้องแลก ได้แก่ บางฟังก์ชันของ Facebook และ Messenger; ส่วนเสริมของ WhatsApp เช่น avatar และเอฟเฟกต์วิดีโอ; Windows Spotlight และประวัติความสำเร็จของ Xbox; และ tracker ตำแหน่งที่บางเว็บไซต์พึ่งพา ซึ่งอาจทำให้ได้การตั้งค่าภูมิภาคผิดและเจอ CAPTCHA มากขึ้น

    ชุดของผมฝ่าฝืนกฎ 2 ข้อแรก ผมดาวน์โหลด list ครั้งเดียวสำหรับการตรวจนี้และเทียบกันทีละชื่อ เพื่อดูว่ารายการใดที่ list หนึ่งบล็อกอยู่แล้วใน list อื่น ผมไม่มีสำเนาที่ router โหลดไว้ก่อนหน้า และผมไม่ได้วัด ThreatFox จึงวัด 17 list

    7 จาก 17 list ถูกชุดที่เหลือครอบคลุม ยกเว้นรายการ marker หนึ่งรายการของแต่ละ list ได้แก่ Pro Mini, Pro++ Mini, TIF Medium, TIF Mini, Gambling Medium, Gambling Mini และ Fake การทิ้งทั้ง 7 พร้อมกันจะเสีย 15 ชื่อที่ TIF Medium และ Mini มี แต่ TIF เต็มไม่มี Pop-Up Ads เพิ่ม 37 ชื่อจาก 48,277 ชื่อของมันให้กับชุดที่เหลือ (เทียบกับ Pro++ อย่างเดียวมันเพิ่ม 3 ชื่อ ดูด้านล่าง) DynDNS และ Anti Piracy ต่างออกไป บน list เหล่านั้นมีประมาณ 1,200 และประมาณ 55,000 ชื่อที่ไม่มี list อื่นในชุดมี และผมทิ้งไปโดยเลือกเอง ไม่ใช่เพราะซ้ำ

    tier list ทั้ง 4 รวมกันมี 233,710 ชื่อ ซึ่งอยู่ใน Ultimate ทั้งหมดยกเว้นรายการ marker 4 รายการของ Hagezi เมื่อเทียบกับ Pro++ อย่างเดียว ชุดนี้ขาด 31,411 รายการของ Pro++ ซึ่งเป็นรายการที่ไม่อยู่ใน list ของโดเมนที่ถูกเข้าชมมากที่สุด แทนที่นั้นมันมี 25,040 รายการที่มีเพียง Ultimate บล็อก (25,041 เมื่อรวม marker ของ Ultimate Mini) ทั้งหมดมาจาก list ของโดเมนที่ถูกเข้าชมมากที่สุด Hagezi จัดความเสี่ยงที่ Ultimate ทำให้ใช้งานไม่ได้ว่าสูง ผมไม่ได้เก็บบันทึกว่ามีสิ่งใดใช้งานไม่ได้จาก list เหล่านั้น และไม่ได้ทดสอบ แต่ตามการจัดระดับของ Hagezi ชุดผสมนี้รับความเสี่ยงของ Ultimate และขาดความครอบคลุมของ Pro++

    เจาะลึก: ผมวัดอย่างไร และทำไมการเทียบแบบธรรมดาจึงให้ผลผิด

    OPNsense ใช้รูปแบบ wildcard ของ Hagezi ซึ่งบรรทัดอย่าง *.example.com บล็อก example.com และทุกชื่อใต้มัน ดังนั้นรายการใน list A ถูก list B บล็อกอยู่แล้ว ถ้า B มีรายการนั้นหรือโดเมนแม่ของมันรายการใดรายการหนึ่ง

    การเทียบข้อความธรรมดาพลาดเรื่องนี้ comm รายงานว่า 3,294 รายการของ Pro++ Mini “ไม่อยู่ใน” Ultimate Mini ทั้งหมดยกเว้น 1 รายการถูกครอบคลุม เพราะ Ultimate Mini บล็อกโดเมนแม่แทน มีบรรทัดเดียวสำหรับ omtrdc.net ทั้งโดเมน ซึ่งเป็นโดเมน tracking ของ Adobe ขณะที่ Pro++ Mini ระบุ host ของมัน 998 รายการทีละตัว รายการที่เหลือ 1 รายการคือ marker ของ Hagezi ซึ่งอธิบายด้านล่าง

    tier list ทั้ง 4 วัดด้วยวิธีเดียวกัน:

    Normal + Pro Mini + Pro++ Mini + Ultimate Mini
    ชื่อที่ไม่ซ้ำ 233,710
    ในจำนวนนั้น อยู่ใน Ultimate ด้วย ทั้งหมดยกเว้น 4 (รายการ marker ของ Hagezi)
    รายการของ Pro++ ที่ขาดจากชุดผสม 31,411 จาก 223,551
    ชื่อในชุดผสมที่มีเพียง Ultimate บล็อก 25,040

    การตรวจที่ผมใช้ไล่ขึ้นไปตามโดเมนแม่ เป็น script Python 3 ที่ไม่ต้องติดตั้งอะไรนอกจาก Python เอง script อยู่ก่อน ขั้นตอนหลังจากนั้นบอกวิธีบันทึกและรัน

    #!/usr/bin/env python3
    """hagezi_overlap.py - how much of blocklist A is already blocked by blocklist B.
    
    Reads two Hagezi lists in the wildcard format (the /wildcard/ files, the format
    OPNsense uses). A line "*.example.com" blocks example.com and every name under
    it, so an entry of A counts as covered when the entry itself, or one of its
    parent domains, is in B. A plain text comparison (comm, diff) misses that and
    reports too many differences.
    
    Usage:  python3 hagezi_overlap.py A.txt B.txt
    Author: Vivek Sanghi. Licence: CC BY-NC-SA 4.0, as the blog.
    """
    import re
    import sys
    
    WILDCARD = re.compile(r"^\*\.[a-z0-9_-]+(\.[a-z0-9_-]+)+$")
    
    
    def load(path):
        names = set()
        try:
            f = open(path, encoding="utf-8-sig")
        except OSError as e:
            sys.exit(f"{path}: cannot open ({e.strerror})")
        with f:
            for number, line in enumerate(f, 1):
                line = line.strip().lower()
                if not line or line.startswith("#"):
                    continue
                if not WILDCARD.match(line):
                    sys.exit(f"{path}, line {number}: not a wildcard-format line "
                             "('*.example.com'). Download the /wildcard/ version of the list.")
                names.add(line[2:])
        if not names:
            sys.exit(f"{path}: no entries found; check the download")
        return names
    
    
    def covered(name, blocked):
        while True:
            if name in blocked:
                return True
            if "." not in name:
                return False
            name = name.split(".", 1)[1]
    
    
    def main():
        if len(sys.argv) != 3:
            sys.exit("usage: hagezi_overlap.py A.txt B.txt")
        a, b = load(sys.argv[1]), load(sys.argv[2])
        missing = sorted(n for n in a if not covered(n, b))
        print(f"{sys.argv[1]}: {len(a):,} entries; {len(a) - len(missing):,} already "
              f"blocked by {sys.argv[2]}; {len(missing):,} not")
        for n in missing[:10]:
            print(f"  not covered: {n}")
        if len(missing) > 10:
            print(f"  ... and {len(missing) - 10:,} more")
    
    
    if __name__ == "__main__":
        main()
    

    ก่อนเริ่ม ส่วนนี้สำหรับ Windows PC คุณต้องมี Python 3 (ขั้นที่ 3 ตรวจให้) ขั้นตอนสร้างโฟลเดอร์ 1 โฟลเดอร์ในโฟลเดอร์ผู้ใช้ของคุณ ดาวน์โหลดไฟล์ list 2 ไฟล์ขนาดไม่กี่เมกะไบต์ลงไป และอ่านไฟล์เหล่านั้น ไม่เปลี่ยนอย่างอื่น ควรเผื่อเวลา 10 นาที เพื่อย้อนกลับ ให้ลบโฟลเดอร์ใน File Explorer บน Mac หรือ Linux ใช้ Terminal, python3 แทน py และ curl แทน curl.exe

    1. คลิกเมนู Start พิมพ์ powershell แล้วกด Enter หน้าต่างเปิดขึ้นพร้อม prompt ที่ขึ้นต้นด้วย PS
    2. สร้างโฟลเดอร์และเข้าไปในโฟลเดอร์นั้น แต่ละบรรทัดใช้เวลาครู่หนึ่ง รันทีละบรรทัด:

      mkdir hagezi-check
      cd hagezi-check

      prompt ควรลงท้ายด้วย hagezi-check ถ้าบรรทัดแรกบอกว่ามีโฟลเดอร์อยู่แล้ว ให้เลือกชื่ออื่นและใช้ในทั้งสองบรรทัด

    3. ตรวจว่าติดตั้ง Python แล้ว:

      py --version

      คุณควรเห็นบรรทัดเช่น Python 3.12.4 ถ้า PowerShell บอกว่าไม่รู้จัก py ให้ติดตั้ง Python 3 จาก python.org (ติ๊ก “Add python.exe to PATH” ใน installer) ปิด PowerShell และเริ่มใหม่ที่ขั้นที่ 1

    4. สร้างไฟล์ script ขั้นนี้จะเปิด Notepad:

      notepad hagezi_overlap.py

      Notepad ถามว่าจะสร้างไฟล์ใหม่หรือไม่ คลิก Yes วาง script จากกล่องด้านบน (คลิก Copy บนกล่อง แล้ว Ctrl + V ใน Notepad) กด Ctrl + S แล้วปิด Notepad ถ้า Notepad เปิดโดยไม่ถาม ให้บันทึกด้วย File, Save as พิมพ์ hagezi_overlap.py โดยใส่ในเครื่องหมายคำพูด เป็นชื่อไฟล์ ตรวจว่าโฟลเดอร์คือ hagezi-check แล้วคลิก Save

    5. ดาวน์โหลด list 2 รายการลงโฟลเดอร์ บน Windows พิมพ์ curl.exe ไม่ใช่ curl ใน PowerShell รันทีละบรรทัด:

      curl.exe -o pro.plus.mini.txt https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/pro.plus.mini.txt
      curl.exe -o ultimate.mini.txt https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/ultimate.mini.txt

      แต่ละบรรทัดใช้เวลาไม่กี่วินาทีและพิมพ์ตารางความคืบหน้า ถ้าบรรทัดใดลงท้ายด้วยข้อผิดพลาด ให้ตรวจการเชื่อมต่อและรันบรรทัดนั้นอีกครั้ง

    6. รันการตรวจ:

      py hagezi_overlap.py pro.plus.mini.txt ultimate.mini.txt
    7. บน list ที่ผมดาวน์โหลดสำหรับการตรวจนี้ มันพิมพ์ว่า:

      pro.plus.mini.txt: 98,704 entries; 98,703 already blocked by ultimate.mini.txt; 1 not
        not covered: h4g3z1-pro-plus-mini.web.app

      ตัวเลขของคุณจะต่างออกไป เพราะ list เปลี่ยนทุกวัน ถ้าคุณเห็นข้อความแทนตัวเลข แปลว่า script หยุดโดยตั้งใจ ให้อ่านข้อความนั้น เพราะมันระบุชื่อไฟล์และบรรทัด

    ชื่อที่เหลือ 1 ชื่อในแต่ละการเทียบคือ marker ที่ Hagezi ใส่ในทุก list (h4g3z1-<list>.web.app) เพื่อให้คุณรู้ว่าโหลด list ใดอยู่ ถ้าการดาวน์โหลดล้มเหลว หรือไฟล์อยู่ในรูปแบบอื่น script จะหยุดและบอกเช่นนั้น แทนที่จะรายงานตัวเลข

    สิ่งอื่นที่มันให้ บน list ชุดเดียวกัน:

    List A List B รายการของ A ที่ B บล็อกอยู่แล้ว
    Normal (171,454) Pro++ ทั้งหมดยกเว้น marker
    Pro++ (223,551) Ultimate ทั้งหมดยกเว้น marker
    Pro Mini (86,842) Ultimate Mini ทั้งหมดยกเว้น marker
    TIF Mini (212,777) TIF Medium ทั้งหมดยกเว้น marker
    Gambling Mini (118,888) Gambling Medium ทั้งหมดยกเว้น marker
    Fake (17,622) Pro++ ทั้งหมดยกเว้น marker
    Pop-Up Ads (48,277) Pro++ ทั้งหมดยกเว้น 4 (marker และอีก 3 รายการ)
    Badware Hoster (1,088) Pro++ 966
    Ultimate Mini (120,458) Pro++ 95,417

    script ถูกทดสอบกับ list เหล่านี้ และกับไฟล์ที่หายไป ไฟล์ว่าง ไฟล์ที่มีแต่ comment การดาวน์โหลดที่ล้มเหลว หน้าเว็บ และ list ในรูปแบบ adblock, hosts และ plain-domain

    จำนวนชื่อที่โหลดเข้ามาไม่ได้เปลี่ยนไปตามสิ่งที่ผมทำ ในวันที่ล้างครั้งแรก router โหลด 2,840,117 ชื่อก่อนล้าง และ 3,188,234 ชื่อหลังล้าง โดยใช้ 10 list แทน 18 list: ระหว่างการดาวน์โหลด 2 ครั้งในวันนั้น TIF โตขึ้น 426,519 รายการ ต่อมา โดยที่ผมไม่ได้เปลี่ยนอะไร จำนวนนี้เคลื่อนจาก 2,739,044 ไปเป็น 3,229,041 ใน 4 วัน จากขนาด list ที่ผมดาวน์โหลดสำหรับการตรวจนี้ ประมาณสองในสามของชื่ออยู่บน TIF และประมาณร้อยละ 7 อยู่บน Pro++

    เจาะลึก: ตัวเลขจาก router พร้อมข้อควรระวัง

    ชื่อที่โหลด จาก log ของ router (“blocklist loaded. length is …” คือจำนวนชื่อที่ไม่ซ้ำ):

    เมื่อใด List ชื่อที่โหลด
    วันล้างครั้งแรก ก่อนล้าง 18 list เดิม 2,840,117
    วันล้างครั้งแรก หลังล้าง ชุดใหม่ 3,188,234
    5 วันต่อมา ชุดเดิม 2,739,044
    9 วันต่อมา ชุดเดิม 3,229,041
    18 วันต่อมา ชุดเดิม 3,198,953

    สัดส่วนของ query ที่ถูกบล็อก จาก Reporting → Unbound DNS:

    ช่วงเวลา Query ถูกบล็อก
    วันล้างครั้งแรก อ่านในวันนั้น ไม่ได้บันทึก ร้อยละ 12.9
    ช่วงประมาณ 38 ชั่วโมง อ่านภายหลัง 110,248 8,600 (ร้อยละ 7.80)

    ค่าร้อยละทั้งสองครอบคลุม list ต่างกัน วันต่างกัน และสิ่งใดก็ตามที่เครือข่ายทำอยู่ในช่วงนั้น จึงไม่ใช่ก่อนและหลัง

    สิ่งที่ผมติ๊กตอนนี้

    การตั้งค่าบน router ของผมแสดง:

    • Hagezi Pro++ (full)
    • TIF (full)
    • Gambling (full)
    • Fake, Pop-Up Ads, Badware Hoster และ “Safesearch not supported”
    • OISD NSFW
    • list ของ Hagezi 2 รายการตาม URL ได้แก่เซิร์ฟเวอร์ encrypted-DNS และ tracker ของ LG TV
    • Abuse.ch ThreatFox ตาม URL พร้อม key ฟรี (ดูด้านล่าง)

    ผมเลือก Pro++ แทน Pro ที่ Hagezi แนะนำ เพื่อ tracker ของอุปกรณ์ เพราะ Pro++ คือที่ที่เขาบล็อกเกือบทั้งหมด

    2 รายการในนี้ซ้ำกัน cheat sheet ของ Hagezi ระบุว่า Fake และ Pop-Up Ads อยู่ใน Pro++ สำหรับ Fake ผลการวัดตรงกัน และเอาออกได้โดยไม่เปลี่ยนสิ่งที่ถูกบล็อก บน list ที่ผมดาวน์โหลด Pop-Up Ads มี 3 ชื่อที่ไม่มีใน Pro++, TIF, Gambling, Hoster หรือ Fake การทิ้งมันจะทำให้เสีย 3 ชื่อนั้น ผมไม่ได้เทียบ ThreatFox หรือ list 2 รายการที่ใส่ตาม URL Fake และ Pop-Up Ads ยังติ๊กอยู่ทั้งคู่

    ThreatFox หยุดดาวน์โหลด และตอนนี้ดาวน์โหลดได้อีกครั้ง ทุกการอัปเดตบันทึก “unable to download blocklist … and no cache available” ที่อยู่ที่รายการในตัวของ OPNsense ใช้สำหรับมันตอบ “410 Gone” และหน้า export ของ abuse.ch ขอ Auth-Key ก่อนจะให้ host file release 26.7 รุ่นหลังลบรายการในตัวออกด้วยเหตุนี้ และชี้ผู้ใช้ไปที่ “URLs of Blocklists” abuse.ch ออก key ให้ฟรีผ่านพอร์ทัลยืนยันตัวตนของตน ผมเพิ่ม list ด้วย URL โดยใส่ key ไว้ในที่อยู่ หน้า export ของ abuse.ch ขอ key ใน URL และตัวดาวน์โหลดของ OPNsense ไม่ส่ง header ใดเลย ขั้นตอนด้านล่างแสดงรูปแบบของที่อยู่ การอัปเดตที่เพิ่มมันบันทึก “blocklist download” ด้วย 28,889 บรรทัดสำหรับมัน เป็นชื่อ 28,869 ชื่อ และไม่มีข้อผิดพลาด list อื่นโหลดจาก cache ในการอัปเดตนั้น จากจำนวนชื่อที่โหลดตามที่ router นับเอง จำนวนเพิ่มจาก 2,765,172 เป็น 2,782,246 ดังนั้น 17,074 จาก 28,869 ชื่อยังไม่ได้ถูกโหลดอยู่แล้วภายใต้ชื่อที่ตรงตัวนั้น และประมาณ 11,800 ชื่อถูกโหลดอยู่แล้ว การนับเทียบชื่อตามตัวอักษร ชื่อที่โดเมนแม่ถูก list อื่นบล็อกอยู่แล้วจึงนับเป็นชื่อใหม่ Hagezi ไม่ระบุว่า ThreatFox เป็นแหล่งที่มา

    key ทำงานเหมือนรหัสผ่าน router เก็บมันไว้ใน configuration และทุกการอัปเดตเขียนที่อยู่ รวมทั้ง key ลงใน resolver log อย่าให้ key ปรากฏใน screenshot, log ที่แชร์, ไฟล์สำรอง configuration หรือ remote log server ที่ออกจากมือคุณไป ถ้ามันรั่ว ให้ขอ key ใหม่จากพอร์ทัลเดียวกันและเปลี่ยนที่อยู่

    เจาะลึก: เพิ่ม ThreatFox ด้วย key

    ก่อนเริ่ม ขั้นตอนนี้เพิ่ม list 1 รายการให้ policy ของคุณ ควรเผื่อเวลา 10 นาที ไม่มีอะไรถูกลบ เพื่อย้อนกลับ ให้ลบที่อยู่ออกจากช่องเดิมแล้ว apply อีกครั้ง

    1. ใน browser เปิด https://auth.abuse.ch สร้างบัญชีถ้ายังไม่มี และขอ Auth-Key key ใช้ได้ฟรี คัดลอกมันลงไฟล์ข้อความเฉพาะจนถึงขั้นที่ 4 ซึ่งคุณวางมันครั้งเดียว แล้วลบไฟล์นั้น
    2. ล็อกอินเข้า router คลิก Services แล้ว Unbound DNS แล้ว Blocklists
    3. ที่ปลายด้านขวาของแถว policy ของคุณ คลิกไอคอนดินสอ (Edit) หน้าต่างชื่อ Edit Blocklist เปิดขึ้น
    4. คลิกใน URLs of Blocklists และพิมพ์ที่อยู่ด้านล่าง โดยใส่ key ของคุณแทน YOUR_KEY และไม่มีช่องว่าง กด Enter เพื่อให้มันเป็น tag ของตัวเอง (tag คือ 1 รายการที่แสดงเป็นกล่องเล็กในช่อง):

      https://threatfox-api.abuse.ch/v2/files/exports/YOUR_KEY/hostfile.txt

      key อยู่ระหว่าง exports/ และ /hostfile.txt

    5. คลิก Save แล้ว Apply router ดาวน์โหลด list ใหม่อีกครั้ง รอ 1 ถึง 2 นาที

    6. คลิก Services, Unbound DNS, Log File ค้นหา download และติ๊ก Informational ในช่อง severity คุณควรเห็น “blocklist download:” และจำนวนบรรทัดสำหรับที่อยู่ ThreatFox ถ้าบรรทัดบอก “unable to download” ให้ตรวจ key และที่อยู่ว่ามีช่องว่างหลงอยู่หรือไม่
    7. อย่าแชร์หน้าจอนั้น บรรทัดนั้นแสดงที่อยู่พร้อม key ของคุณ
    เจาะลึก: Badware Hoster และ list 2 รายการที่เพิ่มด้วย URL

    Badware Hoster เป็น list เดี่ยวของ Hagezi และ 966 จาก 1,088 รายการของมันอยู่ใน Pro++ แล้ว ส่วนที่เหลือบล็อกผู้ให้บริการ hosting ทั้งรายที่โผล่ใน threat feed ซ้ำ ๆ Hagezi เตือนว่าเว็บไซต์ที่ถูกต้องบน host เหล่านั้นถูกบล็อกไปด้วย และปล่อยให้ผู้ที่รัน list เป็นคนปลดบล็อกเอง

    list 2 รายการที่เพิ่มด้วย URL เป็นของ Hagezi ในรูปแบบ wildcard:

    https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/doh.txt
    https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/wildcard/native.lgwebos.txt

    list แรกระบุเซิร์ฟเวอร์ encrypted-DNS ตามชื่อ เป็นส่วนหนึ่งของการกันไม่ให้อุปกรณ์เลี่ยง router list ที่สองระบุเซิร์ฟเวอร์โฆษณาและ tracking ของ LG webOS แต่ละรายการมีเรื่องของตัวเอง สำหรับโพสต์แยกต่างหาก

    tick-box ของ Hagezi ในตัวของ OPNsense 26.7 ดาวน์โหลดจาก mirror ของ Hagezi hagezi-mirror.dnsbunker.org ตามที่ log แสดง Hagezi บอกว่า mirror นั้นเผยแพร่ build ใหม่ราวทุก 4 ถึง 8 ชั่วโมง สำเนาจาก jsDelivr อัปเดตวันละครั้ง

    สิ่งที่ DNS บล็อกไม่ได้

    โฆษณาในแอป YouTube และ Instagram มาจากโดเมนเดียวกับวิดีโอและโพสต์ การบล็อกด้วยชื่อจึงบล็อกเนื้อหาไปด้วย FAQ ของ Hagezi กล่าวประเด็นทั่วไปไว้ว่า โฆษณาบางส่วนโหลดจากโดเมนเดียวกับเนื้อหา และ content blocker ใน browser หรือ blocker ระดับแอปบนโทรศัพท์คือชั้นที่จับมันได้ ผมยอมให้โฆษณาในแอปผ่านเข้ามา

    นอกจากนี้ DNS blocklist กรองเฉพาะอุปกรณ์ที่ถาม router อุปกรณ์ที่มี DNS แบบเข้ารหัสหรือ hard-coded ของตัวเองจะเลี่ยงมันไป นั่นเป็นอีกโพสต์หนึ่ง

    งานนี้ทำอย่างไร

    Claude อ่านเอกสารและ list เปรียบเทียบกัน และอ่าน router ของผมผ่าน session ใน browser ที่ผมล็อกอินไว้ ได้แก่การตั้งค่า resolver log และ tester ผมตัดสินว่าจะเปลี่ยนอะไร ใน session เรื่อง allowlist การเปลี่ยนแปลงเดียวบน router คือการเขียน allowlist ใหม่

    โมเดลผิดพลาดหลายเรื่อง การแก้ allowlist ด้วยชื่อเปล่ามาจาก session แรก และใน session หนึ่งมันยังบอกผมว่าการอัปเดต blocklist ตอนกลางคืนล้าง cache ของ Unbound log ของ router แสดงว่าการอัปเดตโหลด list เข้า Unbound ที่กำลังรันอยู่ โดยไม่ restart คู่มือบอกว่าการ apply การตั้งค่า blocklist ไม่ restart Unbound และ source โหลด list ใหม่เข้า process ที่กำลังรันอยู่ การตั้งค่า flush มีผลเฉพาะตอนที่ Unbound หยุด

    โมเดลที่มี session ล็อกอินบน router เป็นความเสี่ยงในตัวมันเอง resolver log ที่มันอ่านมีชื่อที่เว็บไซต์ใดก็ทำให้อุปกรณ์ lookup ได้ และชื่อหนึ่งอาจมีข้อความที่เขียนขึ้นเพื่อชักนำโมเดล ใน session เรื่อง allowlist ผมให้มันอ่านอย่างเดียว นอกจากการเปลี่ยน allowlist นั่นเป็นคำสั่งถึงโมเดล ไม่ใช่การควบคุม ผู้ใช้ OPNsense แบบอ่านอย่างเดียวจะเป็นการควบคุม resolver log ยังมีที่อยู่ ThreatFox พร้อม key ดังนั้น session ที่อ่าน log จะเห็น key ถ้าคุณให้โมเดลอ่าน log นั้น ให้เปลี่ยน key ภายหลัง

    ใน session แรก ผมยังเปลี่ยนการตั้งค่า Unbound 5 อย่างและ cron job 1 งาน router แสดงว่าทั้ง 6 อย่างตั้งค่าไว้

    เจาะลึก: แต่ละการตั้งค่า และวิธีย้อน DNS over TLS
    การตั้งค่า (หน้า) ก่อน หลัง
    Flush DNS Cache during reload (General) เปิด ปิด
    Prefetch Support (Advanced) ปิด เปิด
    Serve Expired Responses (Advanced) ปิด เปิด; TTL for Expired Responses 86,400 s
    Use System Nameservers (Query Forwarding) เปิด ปิด
    DNS over TLS forwarders ไม่มี Cloudflare และ Quad9
    งานอัปเดต blocklist (System → Settings → Cron) ช่วงเวลาที่ใช้ร่วมกับงานอื่น ช่วงเวลาของตัวเอง

    Prefetch รีเฟรชรายการยอดนิยมก่อนที่มันจะหมดอายุ คู่มือระบุต้นทุนไว้ที่ DNS traffic เพิ่มขึ้นประมาณร้อยละ 10

    Serve Expired Responses ตอบจาก cache ด้วย record ที่หมดอายุแล้ว แทนที่จะให้อุปกรณ์รอ เมื่อเปิด จะมีช่องเพิ่มขึ้น ช่อง “TTL for Expired Responses” จำกัดว่าหลังหมดอายุนานเท่าใดจึงยังให้คำตอบเก่าได้ ผมตั้ง 86,400 วินาที ซึ่งเป็นขอบล่างของช่วง 86,400 ถึง 259,200 ที่คู่มือแนะนำ

    ผลร่วมกันของสองการตั้งค่าที่ผมไม่ได้ทดสอบ เมื่อปิดการ flush cache และอนุญาตคำตอบที่เก่า ชื่อที่ list เพิ่งบล็อกอาจยังถูกตอบจาก cache ของ Unbound ต่อไปอีกระยะหนึ่ง ถ้าการบล็อกไม่มีผลทันที นั่นคือสิ่งแรกที่ผมจะดู

    Use System Nameservers คู่มือบอกว่า system nameserver ถูกเลือกก่อนรายการ catch-all ใด ๆ ใน Query Forwarding และ DNS over TLS การปิดมันทำให้รายการ DNS over TLS รับ query ไปแทน รายการทั้ง 4 ใต้ Services → Unbound DNS → DNS over TLS:

    Server IP Port Verify CN
    1.1.1.1 853 cloudflare-dns.com
    1.0.0.1 853 cloudflare-dns.com
    9.9.9.9 853 dns.quad9.net
    149.112.112.112 853 dns.quad9.net

    query ที่ router ส่งไปยังเซิร์ฟเวอร์เหล่านี้ออกไปแบบเข้ารหัส firewall rule ที่ปฏิเสธ port 853 จาก LAN เพื่อกันไม่ให้อุปกรณ์ใช้ DNS แบบเข้ารหัสของตัวเอง ไม่กระทบมัน เพราะมันออกจากตัว router เอง

    เวลาอัปเดต ถูกย้ายไปอยู่ในช่วงเวลาของตัวเอง เพื่อให้การอัปเดตไม่ใช้เวลาเดียวกับงานตามกำหนดอื่นอีก

    หากต้องการย้อนการเปลี่ยนแปลง DNS over TLS:

    ก่อนเริ่ม ขั้นตอนนี้เปลี่ยนการตั้งค่า DNS ของ router และใช้เวลา 5 นาที DNS ยังทำงานผ่านการตั้งค่าที่เหลืออยู่ จดรายการทั้ง 4 ไว้ก่อน (ตารางด้านบน) คุณต้องใช้มันเพื่อใส่การเปลี่ยนแปลงกลับคืน

    1. เปิดหน้าตั้งค่าของ router แล้ว sign in คุณควรเห็นหน้า Lobby
    2. คลิก Services แล้ว Unbound DNS แล้ว DNS over TLS ตารางแสดงรายการ
    3. ที่ปลายด้านขวาของแถวแรก คลิกไอคอนดินสอ (Edit) หน้าต่างชื่อ Edit server เปิดขึ้น เอาเครื่องหมายติ๊กออกจาก Enabled แล้วคลิก Save ทำเช่นเดียวกันกับแถวอื่นทุกแถว
    4. ที่ด้านบนของหน้าเดียวกัน ติ๊ก Use System Nameservers ช่องเดียวกันนี้ปรากฏใต้ Query Forwarding ด้วย มันเป็นการตั้งค่าเดียว
    5. คลิก Apply ที่ด้านล่างของหน้า Unbound โหลดใหม่ภายในไม่กี่วินาที
    6. ตรวจ จากอุปกรณ์ในเครือข่าย เปิดเว็บไซต์ใดก็ได้ที่คุณยังไม่ได้เข้าวันนี้ มันควรโหลดได้ ถ้าใน System → Settings → General ไม่มี nameserver เลย Unbound จะ resolve จาก root server เองแทนที่จะ forward ถ้าต้องการให้ใช้เซิร์ฟเวอร์ของผู้ให้บริการของคุณ ให้เพิ่มไว้ที่นั่น
    7. เพื่อใส่การเปลี่ยนแปลงกลับ ให้ติ๊ก Enabled ที่แต่ละรายการอีกครั้ง เอาเครื่องหมายติ๊กออกจาก Use System Nameservers และคลิก Apply

    แหล่งที่มา

  • Tailscale’s default policy allows root SSH. Tailworm made me read it.

    Tailscale’s default policy allows root SSH. Tailworm made me read it.

    11 min read

    Are you affected? Tailworm’s SSH findings only matter on a device that runs Tailscale SSH, and a device runs it only if someone turned it on, with tailscale set --ssh or with a switch in an app that wraps it. Windows, iPhone, Android, the Mac app and Synology and QNAP devices cannot run it. Tailscale’s documentation lists the server for Linux and, in the open-source command-line build, for macOS; the source code also builds it for FreeBSD and OpenBSD. Some NAS and router software has a switch for it: the admin console’s Machines page shows which devices report running it (step 2 of the check). Version 1.104.4 or later fixes the vulnerabilities Tailscale’s own post describes; some of the report’s eleven findings concern headscale or unreleased code. If a device runs the server, update that device.

    Separately: if you have never edited your Tailscale access controls, the default policy lets you open a Tailscale SSH session as root (the administrator account) on any of your own devices that runs the server, after signing in again in a browser. Anyone who takes over one of your untagged devices (a tag is a label such as tag:server; most home devices have none) may be able to do the same; the default rule does not cover tagged devices. If no device runs the server, the rule has nothing to act on today; this is housekeeping, not an emergency. Deleting the ssh section closes it. The five-minute check below shows how, in a safe order.

    The access policy Tailscale wrote when I created my tailnet (my Tailscale network) allowed a root SSH session on my own devices. I had never opened it. Claude, an AI model, pointed it out in its review of my first draft of this post, while we checked my network against Tailworm.

    Tailworm is a report published over the weekend of 24 October 2026: eleven findings across Tailscale and headscale, the most serious in Tailscale’s built-in SSH server. In the researcher’s lab, an attacker who controlled one device became root on other machines that ran Tailscale SSH under a rule allowing that device in. Tailscale had not released a fix when the report appeared.

    Below is a five-minute check for your own tailnet. What the attack needs, and what I found, follow it.

    New to the command line? How to read the boxes

    PS> means: type this in PowerShell on Windows (Start menu → type powershell → Enter). $ means: type this in a terminal on Linux or a Mac, or on a remote machine after you have logged in with ssh (a command that logs you in to another machine). Do not type the $ or PS> itself.

    Each line that starts with $ or PS> is one command. Click that $ to copy just that line, paste it, press Enter, and wait for it to finish before the next. A box with a Copy button at the top holds one command (or one file), so copy it whole. A dashed box shows what you should see back; you do not type it.

    A five-minute check for your own tailnet

    Before you start

    • You need: a computer (the steps are awkward on a phone), a browser and a sign-in to your tailnet with the Owner or Admin role (a Network admin cannot remove devices; an IT admin cannot edit the policy).
    • How long, and how to undo: about five minutes for “Look”, which changes nothing. Every change to the policy starts with a saved copy of it, and every box says whether it only looks or changes something.

    Look: nothing changes

    1. Open the admin console. Open a web browser, go to console.tailscale.com/admin/machines and sign in with the account that owns your tailnet. This only opens a page and takes about a minute. You should see a table of your devices. If you cannot open the page, your account may lack the Owner or Admin role; ask whoever has it.
    2. Find devices that run Tailscale SSH. Above the table, click Filters, choose Property, then Tailscale SSH. The table shrinks to the devices that report running the server. An empty table means none does. If you cannot find Filters, see Tailscale’s page on filtering devices.
    3. Optional: confirm on one device. The collapsed block under this list shows how, on Linux or on a Mac with the command-line build.
    4. Read your policy. In the console’s top menu, click Access controls. If the visual editor opens, switch to the JSON editor. Click inside the text, press Ctrl+F (Cmd+F on a Mac), type "ssh" and press Enter. No match means the policy has no SSH rule, and you can skip to “For everyone” below. A match that looks like the rule shown under “The policy I never wrote” below means your policy allows root sessions on your own devices; if it looks different, read its "users" line: root in it allows root sessions. If step 2 showed devices, go to “If you do use Tailscale SSH” below; if its table was empty, go to “If you do not use Tailscale SSH”.
    Optional: confirm on one device (Linux, or a Mac with the command-line build)

    Open a terminal: on a Mac press Cmd+Space, type terminal and press Enter; on Linux open your terminal app, or log in to a remote machine with ssh <your-user>@<device-address> (ssh also works in PowerShell on Windows). Then run the command below. grep -i runssh keeps only the line that mentions RunSSH.

    tailscale debug prefs | grep -i runssh

    It answers at once.

    "RunSSH": false,

    true means the device runs the server. If nothing is printed or the shell says tailscale: command not found, rely on step 2: the Mac app and Windows cannot run the server.

    What Tailworm needs

    I listed what the attack needs and checked each item against my own setup.

    The devices on one Tailscale account form a tailnet, and a policy file in the admin console decides which device may reach which.

    Tailscale SSH is an SSH server inside the Tailscale service, started on a device by tailscale set --ssh. The policy file, not a password or a key, decides who may log in and as which local account. According to the report, when such a session forwarded a Unix socket (a file-like channel that programs on one machine use to talk to each other), the Tailscale service did the work with root’s rights, and a gap between the check and the use of the socket got past the checks meant to limit it. A session allowed in as an ordinary user could act as root.

    The SSH attack needs three things:

    1. A target device running Tailscale SSH.
    2. A rule in the policy file that lets the attacker’s device open an SSH session on that target, with forwarding allowed.
    3. An attacker who already controls a device the rule covers.

    Tailworm does not provide the third; the attacker brings it: a vulnerable web application, a malicious package, phishing, stolen passwords. It is not an attack from the open internet.

    What I found

    What the attack needs What I found Where to look on yours
    Tailscale SSH running on the target Not running on any of my devices when I checked The admin console’s Machines page, filtered by property “Tailscale SSH” (step 2 of the check)
    A policy rule allowing an SSH session Yes: the default rule. Root or an ordinary account, on my own devices, after signing in again The policy file (step 4 of the check)
    A foothold on a device the rule covers Possible, as on any network —
    The other findings Apply to the features they involve: app connectors, tailscale serve, the relay connection every client makes and headscale (an open-source replacement for Tailscale’s hosted control server) The admin console

    So the first thing the attack needs was missing. The second, a rule allowing a session, was in place by default. Tailscale’s documentation does not say whether the default rule allows forwarding, which the socket attack needs.

    Deep dive: other ways to check each item
    • If you run OPNsense. The Tailscale plugin keeps its settings behind an API. The read-only call GET /api/tailscale/settings/get returns "enableSSH":"0" when the SSH server is off. Tailscale’s documentation lists the SSH server for Linux and macOS only, but its source code builds it for FreeBSD and OpenBSD too, and the OPNsense plugin has a switch for it.
    • Every device. In the admin console: Machines → Filters → Property → Tailscale SSH. If no device matches, none reports running the server.
    • A Linux device, from the inside. The --ssh switch sets a preference called RunSSH. tailscale debug prefs | grep -i runssh shows "RunSSH": false when the server is off. tailscale set --ssh=false turns it off.
    • Versions. The report tested 1.104.2 and says nothing about earlier versions. Tailscale’s fix is in 1.104.4.
    Deep dive: what the report found, and what Tailscale said
    • What was tested. Tailscale 1.104.2 and headscale 0.29.5 (an open-source replacement for Tailscale’s hosted control server), unmodified, in a lab, from 22 to 24 October 2026.
    • Findings 1 to 3, SSH socket forwarding. Local and remote forwarding of Unix sockets (ssh -L and ssh -R) were carried out by the root-run Tailscale service. A path check was made at one moment and the socket used at another, and a fast loop inside the session won the gap. In the lab this gave root through the Docker socket, replaced root-owned sockets with the attacker’s own, and captured a key used to enrol new devices, which then joined an attacker’s machine to the network. The report showed that last step end to end only with Tailnet Lock off. With Tailnet Lock on, it captured the material needed to disable the lock but did not use it.
    • Finding 5, SSH memory exhaustion. A logged-in session could make the root-run Tailscale service keep allocating memory.
    • What Tailscale said. It said the issues “require urgent attention” and that the SSH vulnerabilities “primarily concerned how permissions were enforced” after a connection had been authorized; it disputes that the issues amount to a worm and calls this lateral movement limited to connections the policy already allows.
    • Wormability. In the lab, one compromised device reached every device the policy allowed, in under a second per step. The report names one control that stopped the spread: rules written as one source to one destination. Keys held in hardware (a TPM or Secure Enclave) stopped a stolen device identity from lasting.
    • Among the other findings. An app-connector design that does not check where traffic is going (Tailscale says this version, Conn25, has not been released); tailscale serve forwarding to the service’s own control socket; memory exhaustion in the relay client (I found no bulletin for it); and denial of service against headscale.
    • The bulletins. Tailscale published four, dated 26 October, all fixed in 1.104.4: TS-2026-014 (SSH socket forwarding; Tailscale now forwards as the logged-in user, not as root), TS-2026-015 (SSH memory exhaustion), TS-2026-016 (tailscale serve reaching privileged sockets) and TS-2026-017 (Serve over HTTP/2 could pass one mount’s Tailscale-App-Capabilities values to another mount on the same node). Until a device is updated, Tailscale’s mitigation for the forwarding flaw is TS_SSH_DISABLE_FORWARDING=1 in the Tailscale service’s environment; the stopgap under “Then change what you found” shows how.
    • Earlier fixes in the same area. The bulletins of June and July already covered SSH socket forwarding that did not respect symlink permissions (TS-2026-004, 3 June) and a way round autogroup:nonroot (TS-2026-009, 13 July), both fixed in 1.98.9.
    • Forwarding and the default rule. Tailscale’s SSH server forwards only when the matched rule carries a forwarding permission from Tailscale’s coordination server (allowLocalPortForwarding and allowRemotePortForwarding in the source code). Tailscale’s public documentation does not say how a policy grants that or whether the default rule does. The report says to set per-rule forwarding fields to false on Tailscale’s hosted service but does not name them; I could not find them in Tailscale’s policy documentation. Bulletin TS-2026-014 says the issue affects users who “allow local or remote forwarding in their access policies”.
    • Disclosure. Tailscale says it received the report on the morning of Saturday 24 October and the report was published two hours later; it was already investigating related issues. The Hacker News reported that the researcher described it as “reported but not coordinated”.

    The policy I never wrote

    When you create a tailnet, Tailscale gives it a default policy. Its documentation describes it: every device may reach every other device on every port (I call this allow-all below), and every user may open a Tailscale SSH session on their own devices, in check mode, as root or as an ordinary user. The SSH part looks like this:

    "ssh": [
      {
        "action": "check",
        "src":    ["autogroup:member"],
        "dst":    ["autogroup:self"],
        "users":  ["autogroup:nonroot", "root"]
      }
    ]

    Any user of the tailnet (autogroup:member) may connect to the devices that user owns (autogroup:self; tagged devices are not included), as any local account except root (autogroup:nonroot), or as root. Mine had this rule, and allow-all with it. Tailscale’s policy-file page describes the default ssh rule with autogroup:nonroot and does not mention root; its SSH page and its example policies include root, as shown above.

    The rule cannot tell me apart from someone who has taken over one of my devices. To Tailscale, a connection from one of my devices is me. If a Linux device on the tailnet ran tailscale set --ssh, someone who had taken over another of my devices could open a root session on it. That is the rule working as designed, not a flaw. Check mode asks for a browser sign-in of mine, and one approval can stay in force for 12 hours (see below).

    Check mode asks for a fresh sign-in in the browser before the session starts. With the default check period, Tailscale’s documentation says one check-mode sign-in lets you reach that device and any other device in the tailnet for 12 hours without signing in again. It does not say whether that also covers a session opened from a different device. The report describes how an attacker on a device can wait for your next approval or prompt you for one, so check mode slows this down and does not stop it.

    Tailworm needed socket forwarding to turn an ordinary account into root. The default rule needed none, only a check-mode approval. That is documented behaviour, not a vulnerability. Updating to 1.104.4 does not change it either: a session allowed in as root is root by design.

    What I changed

    The policy. The new one has no ssh section. Tailscale’s documentation says that removing the SSH rules disables Tailscale SSH across the tailnet. Grants can replace allow-all with only what is needed, for example:

    1. Exit nodes, if you use them: access to autogroup:internet.
    2. The few devices you must manage, and nothing more. Keep this grant narrow: any device it covers stays reachable.

    Replacing allow-all has a cost: anything that relied on devices reaching each other stops, such as file sharing, a media server or a subnet route. Give each its own grant first.

    Then tests. A policy file can carry tests: statements such as “this user may reach this port” that Tailscale checks every time the file changes. It refuses the change if one fails. Tests can say what must work and what must be refused, for example that SSH, file sharing and remote desktop (ports 22, 445 and 3389) are refused on a device that does not need them.

    Deep dive: an example policy

    This is a shape, not a template. It cuts off everything except exit nodes; pasted as it is, it would cut you off from your own NAS or media server. Addresses and the e-mail are placeholders.

    {
      "grants": [
        // 1. Use exit nodes.
        {"src": ["autogroup:member"], "dst": ["autogroup:internet"], "ip": ["*"]},
    
        // 2. Add a grant for each device you must reach, and no more.
    
        // Nothing else: other devices accept no inbound tailnet traffic.
      ],
    
      // An empty "acls" list: Tailscale's documentation gives this form for deny-all;
      // omitting the section is documented as allow-all.
      "acls": [],
    
      // No "ssh" section: no Tailscale SSH session is allowed anywhere.
    
      "tests": [
        {
          "src":    "you@example.com",
          // "accept": ["100.x.y.2:445"],  one line like this for each thing that must work.
          "deny":   ["100.x.y.3:22", "100.x.y.3:445", "100.x.y.3:3389"], // a device that must refuse these
        },
      ],
    }

    A grant for a NAS that should serve file shares to the users of your tailnet, and nothing else, would look like this (the port is an example, and you add one tcp: entry for each other service it must serve; nas is a name you define in the policy’s hosts section, for example "hosts": {"nas": "100.x.y.2"}):

    {"src": ["autogroup:member"], "dst": ["nas"], "ip": ["tcp:445"]},

    Notes:

    • Only devices with access to autogroup:internet can use exit nodes, which is why grant 1 is written that way.
    • Tests check the rules, not the network: a passing test does not prove that a device answers.
    • Why "acls": [] stays. Tailscale’s documentation says that omitting the acls section is equivalent to the default allow-all policy, and its deny-all example is "acls": []. It does not say what omission means in a policy that has grants. Keep the empty list and let tests decide: a deny test for a port that allow-all would open fails while allow-all is in force.
    • Keep a copy of the old policy before saving (step 1 of “If you do not use Tailscale SSH: switch it off everywhere” below does this). Tailscale also lets you revert a change from the Configuration logs page.
    Deep dive: the method I would use again

    List what the attack needs; check each item on your own devices and note how; look for what is wrong even where the attack does not apply; and sort the rest into what to change, what to watch and what risk to accept.

    Then change what you found

    If you do not use Tailscale SSH: switch it off everywhere

    Before you start: this changes your policy so that no device accepts a Tailscale SSH session. Do not do it if Tailscale SSH is your only way into some machine. It takes about three minutes. To undo it, paste the saved copy back (step 1) and save, or revert the change from the Configuration logs page.

    1. Save a copy of the policy. In the JSON editor click inside the text and press Ctrl+A (Cmd+A on a Mac), then Ctrl+C (Cmd+C). Open Notepad (Start menu → type notepad → Enter) or TextEdit on a Mac (Format → Make Plain Text first), paste with Ctrl+V (Cmd+V), and save the file as policy-backup.json in your Documents folder. The file should hold the whole policy, starting with {.
    2. Delete the ssh section. Back in the console, select everything from "ssh": [ down to the ] that lines up under it (not the ] inside the rule), with the comma after it if there is one, and press Delete. The policy file allows a spare comma. Leave the other sections as they were.
    3. Save. Click Save. Tailscale checks the policy, and any tests in it, before it applies the change. You should see the console confirm the save. If it reports a syntax error, a comma or bracket is out of place: paste the saved copy back and repeat from step 2. If it names an sshTests entry, delete that test as well.
    4. Check. Reload the page, press Ctrl+F (Cmd+F) and search for "ssh". There should be no match. A device that opted in keeps running the server until you run tailscale set --ssh=false on it.

    If you do use Tailscale SSH: update, then narrow the rule

    Before you start: updating ends every open Tailscale SSH session on that device. Do not run the update from a Tailscale SSH session. Use another way in: a keyboard and screen on the machine, or an ordinary ssh login on your local network. An ssh login to the device’s Tailscale address (100.…) also drops when Tailscale restarts, and a drop mid-update can interrupt the install. The commands below are for Debian, Ubuntu and Raspberry Pi OS with Tailscale’s own package repository. For other systems, see Tailscale’s page on updating.

    1. Log in to the device by another way and open a terminal on it. You should see its shell prompt.
    2. See what version it runs.
    tailscale version

    The first line is the version number. 1.104.4 or later has the fixes. Anything lower needs the update.

    1. Update. sudo runs a command as administrator and may ask for your password; nothing shows as you type, so type it and press Enter.
    sudo apt update
    sudo apt install --only-upgrade tailscale

    Each takes under a minute. Tailscale restarts for a few seconds. If an update is cut off part-way, sudo dpkg --configure -a finishes it. If apt says tailscale is already the newest version, the device either has the fix or did not get Tailscale from Tailscale’s repository.

    1. Check again with tailscale version. The first line should read 1.104.4 or later.
    2. Narrow the rule. If you log in as root on some host, such as a Proxmox server, or on a host where no other account has sudo, this removes that access: check first. Save a copy of the policy (step 1 of “If you do not use Tailscale SSH: switch it off everywhere”) before you edit. Then in the console go to Access controls, JSON editor, find the "users" line of your ssh rule and delete , "root" from it:
    "users":  ["autogroup:nonroot", "root"]
    "users":  ["autogroup:nonroot"]

    Click Save. The rule no longer hands out root sessions; use sudo after you log in. On a host where your account has passwordless sudo, this slows an intruder down and does not stop one. This does not replace the update: the July bulletin TS-2026-009 was a way round autogroup:nonroot. Also limit src and dst to the people and devices that need SSH.

    Stopgap: switch off SSH forwarding on a device you cannot update yet

    Use this only where the package source you use does not yet offer 1.104.4 or later. Tailscale’s mitigation for the forwarding flaw is the setting TS_SSH_DISABLE_FORWARDING=1 in the Tailscale service’s environment. On Debian-style installs the service reads /etc/default/tailscaled (the tailscaled.service file in Tailscale’s source names it as EnvironmentFile). I tested the commands below against copies of that file, not against a running Tailscale service. The restart ends open Tailscale SSH sessions, so run these from another way in. The commands assume systemd.

    1. Back up the file. If the command says No such file or directory, this device keeps the setting elsewhere; stop and read Tailscale’s page for your install. Run it once: a second run replaces the backup with the edited file.
    sudo cp /etc/default/tailscaled /etc/default/tailscaled.bak
    1. Add the setting. The line starts with a blank line so it cannot join the last line of the file.
    printf '\nTS_SSH_DISABLE_FORWARDING=1\n' | sudo tee -a /etc/default/tailscaled

    It prints what it added. Run it once: a second run adds the line twice.

    1. Restart the service.
    sudo systemctl restart tailscaled
    1. Check that the running service has it.
    sudo cat /proc/$(systemctl show -p MainPID --value tailscaled)/environ | tr '\0' '\n' | grep TS_SSH
    TS_SSH_DISABLE_FORWARDING=1

    No output means the service did not pick the setting up: check that the line is in the file with grep TS_SSH /etc/default/tailscaled, then repeat step 3. /proc/0/environ: No such file or directory means the service is not running.

    1. To undo it, remove the line and restart. Do this too once the device runs 1.104.4 or later; the setting is a stopgap. Removing the line is safe even if a package upgrade has replaced the file since step 1; the backup stays as a record. An upgrade may ask whether to keep your edited file:
    sudo sed -i '/^TS_SSH_DISABLE_FORWARDING=1$/d' /etc/default/tailscaled
    sudo systemctl restart tailscaled

    If sed says it cannot read the file, there is nothing to undo on this device.

    For everyone

    1. Remove devices you no longer look after, before they leave your hands. Do not remove a device you can reach only over Tailscale: you would need to be at the machine to add it back. In the console open Machines, find the device by name in the search bar, open the menu next to it, choose Remove and then Remove machine in the dialog. The device disappears from the list. If you remove one by mistake, sign the device in again to add it back; if your tailnet requires device approval, an admin must approve it.
    2. Look again at allow-all. Search Access controls for "acls" and "grants". A rule whose source is * and whose destination is * or *:* is allow-all: every device may reach every other on every port. The steps to replace it follow.
    Replace allow-all, step by step

    Before you start: this changes your policy and can cut devices off from each other. Do it when you can test each service afterwards. It takes 15 to 30 minutes. To undo it, paste the saved copy of the policy back (step 1 of “If you do not use Tailscale SSH: switch it off everywhere”) and save, or revert the change from the Configuration logs page. If a phone or laptop of yours uses an exit node, test its internet access after each save: a wrong exit-node grant cuts it off.

    1. Write down what your devices need from each other: file shares, a media server, a subnet route, a printer. Use paper or a text file.
    2. Save a copy of the policy as described above.
    3. Add one grant for each need in the "grants" section (add the section if there is none; allow-all is in "acls"), like the NAS example in “an example policy” earlier. Use the NAS’s Tailscale address (the Machines page shows it) in place of nas if you have not defined that name. Add a grant for exit nodes if you use them.
    4. Add tests for what must work, as in the same example. Click Save. If a test fails, Tailscale refuses the change and names the test.
    5. Delete the allow-all rule but keep the "acls" section as "acls": []: Tailscale’s documentation gives that form for deny-all and says omitting the section is equivalent to allow-all. Add tests for what must not work (such as ports 22, 445 and 3389 on a device that should not accept them), and click Save again. Those tests fail while allow-all is still there, which is why they come now.
    6. Test each service from a device that uses it. If one fails, add its grant, or paste the saved copy back.

    Status

    Version 1.104.4 was tagged late on 27 October 2026 (UTC); Tailscale’s changelog dates it 28 October. Version 1.104.5, released on 2 November 2026, fixes Tailscale SSH connection stalls and restart hangs, and stops check-mode sessions disconnecting when an approval expires; update to the current release. On 10 November 2026 the bulletins page (TS-2026-014 to TS-2026-017, dated 26 October) showed no CVE numbers.

    How this was done

    I did the checking with Claude, Anthropic’s AI model. It drafted the replacement policy and its tests, and this post. Claude’s review of my first draft pointed out that the default rule already allows root. Claude then checked that against Tailscale’s documentation; the open-source code does not contain the default policy.

    Glossary
    • Tailscale: a mesh VPN built on WireGuard, with a hosted service that handles sign-in and keys.
    • Tailnet: the set of devices on one Tailscale account.
    • Policy file: the tailnet’s access rules, edited in the admin console. Grants decide which devices may reach which; the ssh section decides who may open Tailscale SSH sessions; tests check the rules every time they change.
    • Allow-all: the default acls rule that lets every device reach every other device on every port.
    • Tag: a label such as tag:server that gives a device an identity of its own instead of a user’s; tagged devices are not covered by autogroup:self.
    • autogroup:member / self / nonroot: any user of the tailnet; the devices a user owns (not tagged ones); any local account except root.
    • Tailscale SSH: an SSH server built into the Tailscale service, which decides who may log in from the policy file instead of passwords or keys.
    • Check mode: an ssh rule action that asks the user to sign in again before a session starts; one sign-in lasts 12 hours by default.
    • Exit node: a device on the tailnet that other devices can send their internet traffic through.
    • root: the administrator account on Linux and macOS, which can do anything on the machine.
    • Subnet route: a device that lets the tailnet reach a whole local network behind it.
    • Unix socket: a file-like endpoint that programs on the same machine use to talk to each other, such as Docker’s control socket.
    • Port forwarding (in SSH): carrying another connection, such as one to a socket, through an SSH session.
    • Tailnet Lock: a Tailscale feature that requires trusted devices to sign every new device before it can join.
    • Foothold: a device an attacker already controls, from which further attacks start.
    • headscale: an open-source replacement for Tailscale’s hosted control server.
    • CVE: a public identifier for a specific vulnerability.
    • sudo: a command prefix that runs the command as administrator; it may ask for your password.
    • ssh: a command that logs you in to another machine.

    Sources

    Tailscale की default policy root SSH की अनुमति देती है। Tailworm ने मुझसे उसे पढ़वाया।

    पढ़ने का समय: 17 मिनट

    Code, commands और technical terms अंग्रेज़ी में ही रखे गए हैं।

    क्या आप प्रभावित हैं? Tailworm की SSH findings सिर्फ़ उस device पर मायने रखती हैं जिस पर Tailscale SSH चलता है, और कोई device इसे तभी चलाता है जब किसी ने इसे चालू किया हो, tailscale set --ssh से या इसे अपने अंदर चलाने वाले किसी app के switch से। Windows, iPhone, Android, Mac app और Synology व QNAP devices इसे नहीं चला सकते। Tailscale के documentation में यह server Linux के लिए और, open-source command-line build में, macOS के लिए दर्ज है; source code इसे FreeBSD और OpenBSD के लिए भी build करता है। कुछ NAS और router software में इसके लिए एक switch होता है: admin console का Machines page दिखाता है कि कौन-से devices इसे चलाने की report देते हैं (जाँच का चरण 2)। Version 1.104.4 या उसके बाद का version उन vulnerabilities को fix करता है जिन्हें Tailscale की अपनी post बताती है; report की ग्यारह findings में से कुछ headscale या unreleased code से जुड़ी हैं। अगर किसी device पर यह server चलता है, तो उस device को update करें।

    इससे अलग: अगर आपने अपने Tailscale access controls कभी edit नहीं किए, तो default policy आपको अपने किसी भी ऐसे device पर, जिस पर यह server चलता है, browser में फिर से sign in करने के बाद root (administrator account) के रूप में Tailscale SSH session खोलने देती है। जो कोई आपके किसी untagged device पर कब्ज़ा कर ले (tag tag:server जैसा एक label है; ज़्यादातर घरेलू devices में कोई tag नहीं होता), वह भी शायद ऐसा कर सके; default rule tagged devices को कवर नहीं करता। अगर किसी device पर server नहीं चलता, तो आज इस rule के पास करने को कुछ नहीं है; यह रखरखाव का काम है, आपात स्थिति नहीं। ssh section हटाने से यह बंद हो जाता है। नीचे दी गई पाँच मिनट की जाँच सुरक्षित क्रम में यह करना बताती है।

    जब मैंने अपना tailnet (मेरा Tailscale network) बनाया, तब Tailscale ने जो access policy लिखी, उसमें मेरे अपने devices पर root SSH session की अनुमति थी। मैंने उसे कभी खोला नहीं था। Claude, एक AI model, ने मेरे इस post के पहले draft की अपनी समीक्षा में इसकी ओर इशारा किया, जब हम मेरे network को Tailworm की findings से मिलाकर जाँच रहे थे।

    Tailworm एक report है जो 24 अक्टूबर 2026 वाले weekend पर प्रकाशित हुई: Tailscale और headscale में ग्यारह findings, जिनमें सबसे गंभीर Tailscale के built-in SSH server में है। Researcher की lab में, जिस attacker के नियंत्रण में एक device था, वह उन दूसरी machines पर root बन गया जो Tailscale SSH चला रही थीं और जिन पर उस device को आने देने वाला rule मौजूद था। Report आने के समय Tailscale ने कोई fix release नहीं किया था।

    नीचे आपके अपने tailnet के लिए पाँच मिनट की जाँच है। Attack को क्या चाहिए, और मुझे क्या मिला, यह उसके बाद आता है।

    Command line में नए हैं? Boxes कैसे पढ़ें

    PS> का मतलब: इसे Windows में PowerShell में type करें (Start menu → powershell type करें → Enter)। $ का मतलब: इसे Linux या Mac के terminal में type करें, या किसी remote machine पर, जब आप ssh (दूसरी machine में login करने वाली command) से login कर चुके हों। $ या PS> को खुद type न करें।

    हर वह line जो $ या PS> से शुरू होती है, एक command है। सिर्फ़ वह line copy करने के लिए उस $ पर click करें, उसे paste करें, Enter दबाएँ, और अगली command से पहले उसके पूरा होने का इंतज़ार करें। ऊपर Copy button वाला box एक command (या एक file) रखता है, इसलिए उसे पूरा copy करें। Dashed box दिखाता है कि जवाब में आपको क्या दिखना चाहिए; उसे आप type नहीं करते।

    अपने tailnet के लिए पाँच मिनट की जाँच

    शुरू करने से पहले

    • आपको चाहिए: एक computer (phone पर ये चरण असुविधाजनक हैं), एक browser और आपके tailnet में Owner या Admin role वाला sign-in (Network admin devices नहीं हटा सकता; IT admin policy edit नहीं कर सकता)।
    • कितना समय लगेगा, और undo कैसे करें: “देखें” में लगभग पाँच मिनट, जो कुछ नहीं बदलता। Policy में हर बदलाव उसकी सहेजी हुई copy से शुरू होता है, और हर box बताता है कि वह सिर्फ़ देखता है या कुछ बदलता है।

    देखें: कुछ नहीं बदलता

    1. Admin console खोलें। Web browser खोलें, console.tailscale.com/admin/machines पर जाएँ और उस account से sign in करें जो आपके tailnet का मालिक है। इसमें सिर्फ़ एक page खुलता है और लगभग एक मिनट लगता है। आपको अपने devices की table दिखनी चाहिए। अगर page नहीं खुलता, तो हो सकता है आपके account के पास Owner या Admin role न हो; जिसके पास हो उससे पूछें।
    2. Tailscale SSH चलाने वाले devices खोजें। Table के ऊपर Filters पर click करें, Property चुनें, फिर Tailscale SSH। Table उन devices तक सिमट जाती है जो server चलाने की report देते हैं। खाली table का मतलब है कि कोई नहीं देता। अगर Filters नहीं मिलता, तो Tailscale का devices को filter करने वाला page देखें।
    3. वैकल्पिक: एक device पर पुष्टि करें। इस list के नीचे का collapsed block बताता है कि Linux पर, या command-line build वाले Mac पर, कैसे।
    4. अपनी policy पढ़ें। Console के top menu में Access controls पर click करें। अगर visual editor खुले, तो JSON editor पर switch करें। Text के अंदर click करें, Ctrl+F (Mac पर Cmd+F) दबाएँ, "ssh" type करें और Enter दबाएँ। कोई match नहीं मिला तो policy में कोई SSH rule नहीं है, और आप नीचे “सबके लिए” पर जा सकते हैं। नीचे “वह policy जो मैंने कभी लिखी नहीं” में दिखाए rule जैसा match मिला तो आपकी policy आपके अपने devices पर root sessions की अनुमति देती है; अगर वह अलग दिखे, तो उसकी "users" line पढ़ें: उसमें root हो तो root sessions की अनुमति है। अगर चरण 2 में devices दिखे थे, तो नीचे “अगर आप Tailscale SSH इस्तेमाल करते हैं” पर जाएँ; अगर उसकी table खाली थी, तो “अगर आप Tailscale SSH इस्तेमाल नहीं करते” पर जाएँ।
    वैकल्पिक: एक device पर पुष्टि करें (Linux, या command-line build वाला Mac)

    Terminal खोलें: Mac पर Cmd+Space दबाएँ, terminal type करें और Enter दबाएँ; Linux पर अपना terminal app खोलें, या ssh <your-user>@<device-address> से किसी remote machine में login करें (ssh Windows के PowerShell में भी चलता है)। फिर नीचे की command चलाएँ। grep -i runssh सिर्फ़ वही line रखता है जिसमें RunSSH है।

    tailscale debug prefs | grep -i runssh

    यह तुरंत जवाब देता है।

    "RunSSH": false,

    true का मतलब है कि device server चलाता है। अगर कुछ print नहीं होता या shell कहता है tailscale: command not found, तो चरण 2 पर भरोसा करें: Mac app और Windows server नहीं चला सकते।

    Tailworm को क्या चाहिए

    मैंने सूची बनाई कि attack को क्या चाहिए, और हर चीज़ को अपने setup से मिलाकर देखा।

    एक Tailscale account के devices मिलकर एक tailnet बनाते हैं, और admin console में एक policy file तय करती है कि कौन-सा device किस device तक पहुँच सकता है।

    Tailscale SSH, Tailscale service के अंदर का एक SSH server है, जो किसी device पर tailscale set --ssh से शुरू होता है। कौन login कर सकता है और किस local account के रूप में, यह कोई password या key नहीं, policy file तय करती है। Report के अनुसार, जब ऐसा कोई session किसी Unix socket (file जैसा एक channel, जिसे एक ही machine के programs आपस में बात करने के लिए इस्तेमाल करते हैं) को forward करता था, तो Tailscale service यह काम root के अधिकारों से करती थी, और socket की जाँच और उसके इस्तेमाल के बीच का एक अंतराल उन checks से निकल गया जो इसे सीमित करने के लिए थे। जिस session को साधारण user के रूप में आने दिया गया था, वह root की तरह काम कर सकता था।

    SSH attack को तीन चीज़ें चाहिए:

    1. एक target device जिस पर Tailscale SSH चल रहा हो।
    2. Policy file में एक rule जो attacker के device को उस target पर SSH session खोलने दे, forwarding की अनुमति के साथ।
    3. एक attacker जिसके नियंत्रण में पहले से कोई ऐसा device हो जो उस rule के दायरे में आता है।

    तीसरी चीज़ Tailworm नहीं देता; attacker उसे खुद लाता है: कोई vulnerable web application, कोई malicious package, phishing, चोरी हुए passwords। यह खुले internet से होने वाला attack नहीं है।

    मुझे क्या मिला

    Attack को क्या चाहिए मुझे क्या मिला आपके यहाँ कहाँ देखें
    Target पर Tailscale SSH चलना जब मैंने जाँच की, मेरे किसी device पर नहीं चल रहा था Admin console का Machines page, property “Tailscale SSH” से filter किया हुआ (जाँच का चरण 2)
    SSH session की अनुमति देने वाला policy rule हाँ: default rule। मेरे अपने devices पर root या साधारण account, फिर से sign in करने के बाद Policy file (जाँच का चरण 4)
    Rule के दायरे में आने वाले device पर foothold संभव है, जैसा किसी भी network में —
    बाकी findings उन features पर लागू होती हैं जिनसे वे जुड़ी हैं: app connectors, tailscale serve, वह relay connection जो हर client बनाता है, और headscale (Tailscale के hosted control server का open-source विकल्प) Admin console

    तो attack को जिस पहली चीज़ की ज़रूरत है, वह मौजूद नहीं थी। दूसरी, session की अनुमति देने वाला rule, default रूप से मौजूद था। Tailscale का documentation नहीं बताता कि default rule forwarding की अनुमति देता है या नहीं, जो socket attack को चाहिए।

    विस्तार से: हर चीज़ को जाँचने के दूसरे तरीके
    • अगर आप OPNsense चलाते हैं। Tailscale plugin अपनी settings एक API के पीछे रखता है। Read-only call GET /api/tailscale/settings/get SSH server बंद होने पर "enableSSH":"0" लौटाता है। Tailscale का documentation SSH server सिर्फ़ Linux और macOS के लिए बताता है, पर उसका source code इसे FreeBSD और OpenBSD के लिए भी build करता है, और OPNsense plugin में इसका एक switch है।
    • हर device। Admin console में: Machines → Filters → Property → Tailscale SSH। अगर कोई device match नहीं करता, तो किसी device ने server चलाने की report नहीं दी।
    • Linux device, अंदर से। --ssh switch RunSSH नाम की एक preference सेट करता है। tailscale debug prefs | grep -i runssh server बंद होने पर "RunSSH": false दिखाता है। tailscale set --ssh=false इसे बंद करता है।
    • Versions। Report ने 1.104.2 को test किया और उससे पहले के versions के बारे में कुछ नहीं कहती। Tailscale का fix 1.104.4 में है।
    विस्तार से: report में क्या मिला, और Tailscale ने क्या कहा
    • क्या test हुआ। Tailscale 1.104.2 और headscale 0.29.5 (Tailscale के hosted control server का open-source विकल्प), बिना किसी बदलाव के, एक lab में, 22 से 24 अक्टूबर 2026 तक।
    • Findings 1 से 3, SSH socket forwarding। Unix sockets की local और remote forwarding (ssh -L और ssh -R) root के रूप में चलने वाली Tailscale service करती थी। Path की जाँच एक क्षण पर हुई और socket दूसरे क्षण पर इस्तेमाल हुआ, और session के अंदर एक तेज़ loop उस अंतराल में race जीत गया। Lab में इससे Docker socket के ज़रिए root मिला, root के स्वामित्व वाले sockets की जगह attacker के अपने sockets रख दिए गए, और नए devices को enrol करने वाली एक key पकड़ ली गई, जिससे attacker की एक machine network में जुड़ गई। Report ने यह आख़िरी चरण पूरा सिर्फ़ तब दिखाया जब Tailnet Lock बंद था। Tailnet Lock चालू होने पर, उसने lock बंद करने के लिए ज़रूरी सामग्री पकड़ी, पर उसका इस्तेमाल नहीं किया।
    • Finding 5, SSH memory exhaustion। Login किया हुआ session root के रूप में चलने वाली Tailscale service से लगातार memory allocate करवा सकता था।
    • Tailscale ने क्या कहा। उसने कहा कि इन issues पर “require urgent attention” (यानी तुरंत ध्यान चाहिए), और SSH vulnerabilities “primarily concerned how permissions were enforced” (मुख्यतः यह कि connection के authorize होने के बाद permissions कैसे लागू हुईं); वह इससे असहमत है कि ये issues किसी worm के बराबर हैं, और इसे lateral movement कहता है जो उन connections तक सीमित है जिन्हें policy पहले से अनुमति देती है।
    • Wormability। Lab में एक compromised device उन सभी devices तक पहुँचा जिन्हें policy ने अनुमति दी थी, हर चरण में एक सेकंड से कम समय में। Report एक control का नाम बताती है जिसने फैलाव रोका: एक source से एक destination तक लिखे गए rules। Hardware में रखी keys (TPM या Secure Enclave) ने चोरी हुई device identity को टिकने से रोका।
    • बाकी findings में। एक app-connector design जो यह नहीं जाँचता कि traffic कहाँ जा रहा है (Tailscale के अनुसार यह version, Conn25, release नहीं हुआ है); tailscale serve का service के अपने control socket तक forward करना; relay client में memory exhaustion (मुझे इसके लिए कोई bulletin नहीं मिला); और headscale पर denial of service।
    • Bulletins। Tailscale ने चार प्रकाशित किए, 26 अक्टूबर की तारीख़ के, सब 1.104.4 में fix हुए: TS-2026-014 (SSH socket forwarding; Tailscale अब login किए हुए user के रूप में forward करता है, root के रूप में नहीं), TS-2026-015 (SSH memory exhaustion), TS-2026-016 (tailscale serve का privileged sockets तक पहुँचना) और TS-2026-017 (HTTP/2 पर Serve एक mount के Tailscale-App-Capabilities values को उसी node के किसी दूसरे mount तक पहुँचा सकता था)। जब तक device update नहीं होता, forwarding की खामी के लिए Tailscale का mitigation Tailscale service के environment में TS_SSH_DISABLE_FORWARDING=1 है; “फिर जो मिला, उसे बदलें” में दिया गया stopgap बताता है कि कैसे।
    • उसी क्षेत्र के पहले के fixes। जून और जुलाई के bulletins में पहले ही उस SSH socket forwarding खामी का समाधान था जो symlink permissions का सम्मान नहीं करती थी (TS-2026-004, 3 जून) और autogroup:nonroot को पार करने के एक रास्ते का (TS-2026-009, 13 जुलाई); दोनों 1.98.9 में fix हुए।
    • Forwarding और default rule। Tailscale का SSH server तभी forward करता है जब मेल खाने वाले rule के साथ Tailscale के coordination server की ओर से forwarding की permission हो (source code में allowLocalPortForwarding और allowRemotePortForwarding)। Tailscale का public documentation नहीं बताता कि policy यह permission कैसे देती है या default rule देता है या नहीं। Report कहती है कि Tailscale की hosted service पर प्रति-rule forwarding fields को false करें, पर उनके नाम नहीं बताती; मुझे वे Tailscale के policy documentation में नहीं मिले। Bulletin TS-2026-014 कहता है कि यह issue उन users पर लागू होता है जो “allow local or remote forwarding in their access policies” (यानी अपनी access policies में local या remote forwarding की अनुमति देते हैं)।
    • Disclosure। Tailscale के अनुसार उसे report शनिवार 24 अक्टूबर की सुबह मिली और report दो घंटे बाद प्रकाशित हो गई; वह पहले से ही संबंधित issues की जाँच कर रहा था। The Hacker News ने बताया कि researcher ने इसे “reported but not coordinated” बताया।

    वह policy जो मैंने कभी लिखी नहीं

    जब आप tailnet बनाते हैं, Tailscale उसे एक default policy देता है। उसका documentation इसे बताता है: हर device बाकी हर device तक हर port पर पहुँच सकता है (नीचे मैं इसे allow-all कहता हूँ), और हर user अपने devices पर check mode में, root या साधारण user के रूप में, Tailscale SSH session खोल सकता है। SSH वाला हिस्सा ऐसा दिखता है:

    "ssh": [
      {
        "action": "check",
        "src":    ["autogroup:member"],
        "dst":    ["autogroup:self"],
        "users":  ["autogroup:nonroot", "root"]
      }
    ]

    Tailnet का कोई भी user (autogroup:member) उन devices से connect कर सकता है जो उस user के हैं (autogroup:self; tagged devices शामिल नहीं हैं), root को छोड़कर किसी भी local account के रूप में (autogroup:nonroot), या root के रूप में। मेरे पास यही rule था, और उसके साथ allow-all भी। Tailscale का policy-file page default ssh rule को autogroup:nonroot के साथ बताता है और root का ज़िक्र नहीं करता; उसका SSH page और उसकी example policies में root शामिल है, जैसा ऊपर दिखाया गया है।

    यह rule मुझमें और उस व्यक्ति में फ़र्क नहीं कर सकता जिसने मेरे किसी device पर कब्ज़ा कर लिया हो। Tailscale के लिए मेरे device से आया connection मैं ही हूँ। अगर tailnet का कोई Linux device tailscale set --ssh चला लेता, तो मेरे किसी दूसरे device पर कब्ज़ा करने वाला उस पर root session खोल सकता था। यह rule का design के अनुसार काम करना है, कोई खामी नहीं। Check mode मेरा browser sign-in माँगता है, और एक मंज़ूरी 12 घंटे तक लागू रह सकती है (नीचे देखें)।

    Check mode session शुरू होने से पहले browser में नया sign-in माँगता है। Default check period के साथ, Tailscale का documentation कहता है कि check mode का एक sign-in आपको उस device तक और tailnet के बाकी किसी भी device तक 12 घंटे के लिए बिना फिर sign in किए पहुँचने देता है। वह यह नहीं बताता कि यह किसी दूसरे device से खोले गए session को भी कवर करता है या नहीं। Report बताती है कि किसी device पर बैठा attacker आपकी अगली मंज़ूरी का इंतज़ार कर सकता है या आपसे उसे माँग सकता है, इसलिए check mode इसे धीमा करता है, रोकता नहीं।

    Tailworm को साधारण account को root बनाने के लिए socket forwarding चाहिए थी। Default rule को कुछ नहीं चाहिए था, सिर्फ़ check-mode की मंज़ूरी। यह documentation में बताया गया व्यवहार है, कोई vulnerability नहीं। 1.104.4 पर update करने से भी यह नहीं बदलता: जिस session को root के रूप में आने दिया गया, वह design से root है।

    मैंने क्या बदला

    Policy। नई policy में ssh section नहीं है। Tailscale का documentation कहता है कि SSH rules हटाने से पूरे tailnet में Tailscale SSH बंद हो जाता है। Grants से allow-all की जगह सिर्फ़ वही दिया जा सकता है जिसकी ज़रूरत है, जैसे:

    1. Exit nodes, अगर आप उन्हें इस्तेमाल करते हैं: autogroup:internet तक access।
    2. वे थोड़े devices जिन्हें आपको manage करना ही है, और कुछ नहीं। इस grant को संकरा रखें: जो भी device इसके दायरे में है, वह पहुँच में रहता है।

    Allow-all को बदलने की एक कीमत है: जो कुछ devices के एक-दूसरे तक पहुँचने पर टिका था, वह रुक जाता है, जैसे file sharing, media server या subnet route। पहले हर एक को उसका अपना grant दें।

    फिर tests। Policy file में tests हो सकते हैं: ऐसे कथन जैसे “यह user इस port तक पहुँच सकता है”, जिन्हें Tailscale file बदलने पर हर बार जाँचता है। कोई test fail हो तो वह बदलाव को मना कर देता है। Tests कह सकते हैं कि क्या चलना चाहिए और क्या मना होना चाहिए, जैसे कि जिस device को SSH, file sharing और remote desktop (ports 22, 445 और 3389) की ज़रूरत नहीं, उस पर ये मना हों।

    विस्तार से: एक example policy

    यह एक ढाँचा है, template नहीं। यह exit nodes को छोड़कर बाकी सब कुछ काट देता है; जैसा है वैसा paste करने पर यह आपको आपके अपने NAS या media server से काट देगा। Addresses और e-mail placeholders हैं।

    {
      "grants": [
        // 1. Use exit nodes.
        {"src": ["autogroup:member"], "dst": ["autogroup:internet"], "ip": ["*"]},
    
        // 2. Add a grant for each device you must reach, and no more.
    
        // Nothing else: other devices accept no inbound tailnet traffic.
      ],
    
      // An empty "acls" list: Tailscale's documentation gives this form for deny-all;
      // omitting the section is documented as allow-all.
      "acls": [],
    
      // No "ssh" section: no Tailscale SSH session is allowed anywhere.
    
      "tests": [
        {
          "src":    "you@example.com",
          // "accept": ["100.x.y.2:445"],  one line like this for each thing that must work.
          "deny":   ["100.x.y.3:22", "100.x.y.3:445", "100.x.y.3:3389"], // a device that must refuse these
        },
      ],
    }

    NAS के लिए एक grant, जो आपके tailnet के users को file shares दे और कुछ नहीं, ऐसा दिखेगा (port एक example है, और जितनी दूसरी services उसे देनी हों, उनमें से हर एक के लिए एक tcp: entry जोड़ें; nas वह नाम है जो आप policy के hosts section में परिभाषित करते हैं, जैसे "hosts": {"nas": "100.x.y.2"}):

    {"src": ["autogroup:member"], "dst": ["nas"], "ip": ["tcp:445"]},

    टिप्पणियाँ:

    • सिर्फ़ वे devices exit nodes इस्तेमाल कर सकते हैं जिनके पास autogroup:internet की access है, इसीलिए grant 1 ऐसे लिखा गया है।
    • Tests rules को जाँचते हैं, network को नहीं: test का पास होना यह साबित नहीं करता कि कोई device जवाब देता है।
    • "acls": [] क्यों रहता है। Tailscale का documentation कहता है कि acls section छोड़ देना default allow-all policy के बराबर है, और उसका deny-all example "acls": [] है। यह नहीं बताता कि जिस policy में grants हैं, उसमें section छोड़ने का क्या मतलब है। खाली list रखें और tests को तय करने दें: जिस port को allow-all खोल देता, उसके लिए deny test तब तक fail होता है जब तक allow-all लागू है।
    • Save करने से पहले पुरानी policy की एक copy रखें (नीचे “अगर आप Tailscale SSH इस्तेमाल नहीं करते: उसे हर जगह बंद कर दें” का चरण 1 यह करता है)। Tailscale आपको Configuration logs page से कोई बदलाव revert करने भी देता है।
    विस्तार से: वह तरीका जो मैं फिर अपनाऊँगा

    सूची बनाएँ कि attack को क्या चाहिए; हर चीज़ को अपने devices पर जाँचें और लिखें कैसे; वह भी देखें जो attack लागू न होने पर भी गलत है; और बाकी को छाँटें: क्या बदलना है, किस पर नज़र रखनी है और कौन-सा जोखिम स्वीकार करना है।

    फिर जो मिला, उसे बदलें

    अगर आप Tailscale SSH इस्तेमाल नहीं करते: उसे हर जगह बंद कर दें

    शुरू करने से पहले: यह आपकी policy इस तरह बदलता है कि कोई device Tailscale SSH session स्वीकार नहीं करता। अगर Tailscale SSH किसी machine में जाने का आपका अकेला रास्ता है, तो यह न करें। इसमें लगभग तीन मिनट लगते हैं। Undo करने के लिए सहेजी हुई copy वापस paste करें (चरण 1) और save करें, या Configuration logs page से बदलाव को revert करें।

    1. Policy की copy सहेजें। JSON editor में text के अंदर click करें और Ctrl+A (Mac पर Cmd+A), फिर Ctrl+C (Cmd+C) दबाएँ। Notepad खोलें (Start menu → notepad type करें → Enter) या Mac पर TextEdit (पहले Format → Make Plain Text), Ctrl+V (Cmd+V) से paste करें, और file को अपने Documents folder में policy-backup.json नाम से सहेजें। File में पूरी policy होनी चाहिए, जो { से शुरू होती है।
    2. ssh section हटाएँ। Console में लौटकर "ssh": [ से लेकर उस ] तक सब कुछ चुनें जो उसके ठीक नीचे सीध में है (rule के अंदर वाला ] नहीं), और अगर उसके बाद comma हो तो उसे भी, फिर Delete दबाएँ। Policy file में फ़ालतू comma चल जाता है। बाकी sections को जैसा था वैसा रहने दें।
    3. Save करें। Save पर click करें। बदलाव लागू करने से पहले Tailscale policy को और उसके किसी भी tests को जाँचता है। आपको console में save की पुष्टि दिखनी चाहिए। अगर वह syntax error बताए, तो कोई comma या bracket गलत जगह है: सहेजी हुई copy वापस paste करें और चरण 2 से दोहराएँ। अगर वह किसी sshTests entry का नाम ले, तो उस test को भी हटा दें।
    4. जाँचें। Page reload करें, Ctrl+F (Cmd+F) दबाएँ और "ssh" खोजें। कोई match नहीं होना चाहिए। जिस device ने opt in किया था, वह तब तक server चलाता रहता है जब तक आप उस पर tailscale set --ssh=false नहीं चलाते।

    अगर आप Tailscale SSH इस्तेमाल करते हैं: update करें, फिर rule को सीमित करें

    शुरू करने से पहले: update करने से उस device पर हर खुला Tailscale SSH session खत्म हो जाता है। Update को Tailscale SSH session से न चलाएँ। कोई दूसरा रास्ता इस्तेमाल करें: machine पर keyboard और screen, या अपने local network पर साधारण ssh login। Device के Tailscale address (100.…) पर ssh login भी तब टूट जाता है जब Tailscale restart होता है, और update के बीच में टूटना install में बाधा डाल सकता है। नीचे की commands Debian, Ubuntu और Raspberry Pi OS के लिए हैं, जिनमें Tailscale की अपनी package repository हो। दूसरे systems के लिए Tailscale का update करने वाला page देखें।

    1. किसी दूसरे रास्ते से device में login करें और उस पर terminal खोलें। आपको उसका shell prompt दिखना चाहिए।
    2. देखें कि वह कौन-सा version चला रहा है।
    tailscale version

    पहली line version number है। 1.104.4 या उससे ऊपर में fixes हैं। उससे नीचे वाले को update चाहिए।

    1. Update करें। sudo एक command को administrator के रूप में चलाता है और आपका password माँग सकता है; type करते समय कुछ दिखता नहीं, इसलिए उसे type करें और Enter दबाएँ।
    sudo apt update
    sudo apt install --only-upgrade tailscale

    हर एक में एक मिनट से कम लगता है। Tailscale कुछ सेकंड के लिए restart होता है। अगर update बीच में कट जाए, तो sudo dpkg --configure -a उसे पूरा करता है। अगर apt कहता है कि tailscale पहले से सबसे नया version है, तो device में या तो fix है या device पर Tailscale, Tailscale की अपनी repository से install नहीं हुआ था।

    1. फिर जाँचें, tailscale version से। पहली line में 1.104.4 या उससे ऊपर का version होना चाहिए।
    2. Rule को सीमित करें। अगर आप किसी host पर root के रूप में login करते हैं, जैसे Proxmox server पर, या ऐसे host पर जहाँ किसी दूसरे account के पास sudo नहीं है, तो यह वह access हटा देता है: पहले जाँच लें। Edit करने से पहले policy की copy सहेजें (“अगर आप Tailscale SSH इस्तेमाल नहीं करते: उसे हर जगह बंद कर दें” का चरण 1)। फिर console में Access controls, JSON editor पर जाएँ, अपने ssh rule की "users" line खोजें और उसमें से , "root" हटा दें:
    "users":  ["autogroup:nonroot", "root"]
    "users":  ["autogroup:nonroot"]

    Save पर click करें। Rule अब root sessions नहीं देता; login के बाद sudo इस्तेमाल करें। जिस host पर आपके account के पास बिना password का sudo है, वहाँ यह intruder को धीमा करता है, रोकता नहीं। यह update की जगह नहीं लेता: जुलाई का bulletin TS-2026-009 autogroup:nonroot को पार करने का एक रास्ता था। src और dst को भी सिर्फ़ उन लोगों और devices तक सीमित करें जिन्हें SSH चाहिए।

    Stopgap: जिस device को आप अभी update नहीं कर सकते, उस पर SSH forwarding बंद करें

    इसे सिर्फ़ वहाँ इस्तेमाल करें जहाँ आपका package source अभी 1.104.4 या उसके बाद का version नहीं देता। Forwarding की खामी के लिए Tailscale का mitigation Tailscale service के environment में TS_SSH_DISABLE_FORWARDING=1 setting है। Debian जैसे installs पर service /etc/default/tailscaled पढ़ती है (Tailscale के source में tailscaled.service file इसे EnvironmentFile के रूप में नाम देती है)। मैंने नीचे की commands उस file की copies पर test कीं, चलती Tailscale service पर नहीं। Restart से खुले Tailscale SSH sessions खत्म हो जाते हैं, इसलिए इन्हें किसी दूसरे रास्ते से चलाएँ। ये commands मानकर चलती हैं कि system systemd चलाता है।

    1. File का backup लें। अगर command No such file or directory कहती है, तो इस device पर setting कहीं और रखी जाती है; रुकें और अपने install के लिए Tailscale का page पढ़ें। इसे एक बार चलाएँ: दूसरी बार चलाने पर backup की जगह edit की हुई file आ जाती है।
    sudo cp /etc/default/tailscaled /etc/default/tailscaled.bak
    1. Setting जोड़ें। Line एक खाली line से शुरू होती है ताकि वह file की आख़िरी line से जुड़ न जाए।
    printf '\nTS_SSH_DISABLE_FORWARDING=1\n' | sudo tee -a /etc/default/tailscaled

    यह छापता है कि उसने क्या जोड़ा। इसे एक बार चलाएँ: दूसरी बार चलाने पर line दो बार जुड़ जाती है।

    1. Service को restart करें।
    sudo systemctl restart tailscaled
    1. जाँचें कि चलती service में यह setting है।
    sudo cat /proc/$(systemctl show -p MainPID --value tailscaled)/environ | tr '\0' '\n' | grep TS_SSH
    TS_SSH_DISABLE_FORWARDING=1

    कोई output नहीं मिला तो service ने setting लागू नहीं की: grep TS_SSH /etc/default/tailscaled से जाँचें कि line file में है, फिर चरण 3 दोहराएँ। /proc/0/environ: No such file or directory का मतलब है कि service चल नहीं रही।

    1. Undo करने के लिए, line हटाएँ और restart करें। Device के 1.104.4 या उसके बाद के version पर आने के बाद भी ऐसा करें; यह setting एक stopgap है। Line हटाना तब भी सुरक्षित है जब चरण 1 के बाद किसी package upgrade ने file बदल दी हो; backup एक record के रूप में बना रहता है। Upgrade पूछ सकता है कि आपकी edit की हुई file रखनी है या नहीं:
    sudo sed -i '/^TS_SSH_DISABLE_FORWARDING=1$/d' /etc/default/tailscaled
    sudo systemctl restart tailscaled

    अगर sed कहता है कि वह file पढ़ नहीं सकता, तो इस device पर undo करने को कुछ नहीं है।

    सबके लिए

    1. जिन devices की आप अब देखभाल नहीं करते उन्हें हटाएँ, उनके आपके हाथ से निकलने से पहले। जिस device तक आप सिर्फ़ Tailscale से पहुँच सकते हैं, उसे न हटाएँ: उसे वापस जोड़ने के लिए आपको machine के पास होना पड़ेगा। Console में Machines खोलें, search bar में device को नाम से खोजें, उसके बगल का menu खोलें, Remove चुनें और फिर dialog में Remove machine। Device list से गायब हो जाता है। अगर आपने गलती से कोई device हटा दिया, तो उस device को फिर से sign in करें ताकि वह वापस जुड़ जाए; अगर आपके tailnet में device approval ज़रूरी है, तो admin को उसे मंज़ूर करना होगा।
    2. Allow-all को फिर से देखें। Access controls में "acls" और "grants" खोजें। जिस rule का source * है और destination * या *:*, वह allow-all है: हर device बाकी हर device तक हर port पर पहुँच सकता है। इसे बदलने के चरण आगे हैं।
    Allow-all को बदलें, चरण दर चरण

    शुरू करने से पहले: यह आपकी policy बदलता है और devices को एक-दूसरे से काट सकता है। इसे तब करें जब आप बाद में हर service को test कर सकें। इसमें 15 से 30 मिनट लगते हैं। Undo करने के लिए policy की सहेजी हुई copy वापस paste करें (“अगर आप Tailscale SSH इस्तेमाल नहीं करते: उसे हर जगह बंद कर दें” का चरण 1) और save करें, या Configuration logs page से बदलाव को revert करें। अगर आपका कोई phone या laptop exit node इस्तेमाल करता है, तो हर save के बाद उसका internet access test करें: exit node का गलत grant उसे काट देता है।

    1. लिख लें कि आपके devices को एक-दूसरे से क्या चाहिए: file shares, एक media server, एक subnet route, एक printer। Paper या एक text file इस्तेमाल करें।
    2. Policy की copy सहेजें, जैसा ऊपर बताया गया है।
    3. हर ज़रूरत के लिए एक grant जोड़ें "grants" section में (अगर कोई नहीं है तो section जोड़ें; allow-all "acls" में है), जैसे पहले “एक example policy” में NAS का example। अगर आपने वह नाम परिभाषित नहीं किया है, तो nas की जगह NAS का Tailscale address (Machines page उसे दिखाता है) इस्तेमाल करें। अगर आप exit nodes इस्तेमाल करते हैं, तो उनके लिए एक grant जोड़ें।
    4. जो चलना चाहिए उसके tests जोड़ें, जैसे उसी example में। Save पर click करें। अगर कोई test fail हो, तो Tailscale बदलाव को मना कर देता है और उस test का नाम बताता है।
    5. Allow-all rule हटाएँ, पर "acls" section को "acls": [] के रूप में रखें: Tailscale का documentation deny-all के लिए यही form देता है और कहता है कि section छोड़ना allow-all के बराबर है। जो नहीं चलना चाहिए उसके tests जोड़ें (जैसे उस device पर ports 22, 445 और 3389, जिसे इन्हें नहीं लेना चाहिए), और Save फिर से करें। Allow-all के रहते वे tests fail होते हैं, इसीलिए इन्हें इसी चरण में जोड़ा जाता है।
    6. हर service को test करें उस device से जो उसे इस्तेमाल करता है। अगर कोई fail हो, तो उसका grant जोड़ें, या सहेजी हुई copy वापस paste करें।

    स्थिति

    Version 1.104.4 को 27 अक्टूबर 2026 (UTC) की देर रात tag किया गया; Tailscale का changelog इसे 28 अक्टूबर की तारीख़ देता है। Version 1.104.5, जो 2 नवंबर 2026 को release हुआ, Tailscale SSH connection stalls और restart hangs को fix करता है, और approval की अवधि खत्म होने पर check-mode sessions का disconnect होना रोकता है; मौजूदा release पर update करें। 10 नवंबर 2026 को bulletins page (TS-2026-014 से TS-2026-017, 26 अक्टूबर की तारीख़ के) पर कोई CVE number नहीं था।

    यह कैसे किया गया

    मैंने यह जाँच Claude, Anthropic के AI model, के साथ की। उसने replacement policy और उसके tests का draft बनाया, और यह post भी। मेरे पहले draft की Claude की समीक्षा ने बताया कि default rule पहले से root की अनुमति देता है। Claude ने फिर इसे Tailscale के documentation से जाँचा; open-source code में default policy नहीं है।

    शब्दावली
    • Tailscale: WireGuard पर बना एक mesh VPN, जिसके साथ एक hosted service है जो sign-in और keys सँभालती है।
    • Tailnet: एक Tailscale account के devices का समूह।
    • Policy file: tailnet के access rules, जो admin console में edit होते हैं। Grants तय करते हैं कि कौन-सा device किस तक पहुँच सकता है; ssh section तय करता है कि Tailscale SSH sessions कौन खोल सकता है; tests हर बदलाव पर rules को जाँचते हैं।
    • Allow-all: default acls rule जो हर device को बाकी हर device तक हर port पर पहुँचने देता है।
    • Tag: tag:server जैसा label, जो device को user की जगह अपनी एक अलग पहचान देता है; tagged devices autogroup:self के दायरे में नहीं आते।
    • autogroup:member / self / nonroot: tailnet का कोई भी user; वे devices जो किसी user के हैं (tagged वाले नहीं); root को छोड़कर कोई भी local account।
    • Tailscale SSH: Tailscale service में बना एक SSH server, जो passwords या keys की जगह policy file से तय करता है कि कौन login कर सकता है।
    • Check mode: ssh rule की एक action जो session शुरू होने से पहले user से फिर sign in करवाती है; एक sign-in default रूप से 12 घंटे चलता है।
    • Exit node: tailnet का एक device जिसके ज़रिए दूसरे devices अपना internet traffic भेज सकते हैं।
    • root: Linux और macOS का administrator account, जो machine पर कुछ भी कर सकता है।
    • Subnet route: एक device जो tailnet को अपने पीछे के पूरे local network तक पहुँचने देता है।
    • Unix socket: file जैसा एक endpoint जिसे एक ही machine के programs आपस में बात करने के लिए इस्तेमाल करते हैं, जैसे Docker का control socket।
    • Port forwarding (SSH में): किसी दूसरे connection को, जैसे socket तक के connection को, SSH session के ज़रिए ले जाना।
    • Tailnet Lock: Tailscale का एक feature जो माँगता है कि भरोसेमंद devices हर नए device पर sign करें, तभी वह जुड़ सकता है।
    • Foothold: वह device जिस पर attacker का पहले से नियंत्रण है, और जहाँ से आगे के attacks शुरू होते हैं।
    • headscale: Tailscale के hosted control server का open-source विकल्प।
    • CVE: किसी ख़ास vulnerability का public identifier।
    • sudo: एक command prefix जो command को administrator के रूप में चलाता है; वह आपका password माँग सकता है।
    • ssh: एक command जो आपको दूसरी machine में login कराती है।

    स्रोत

    Tailscale default policy root SSH ని అనుమతిస్తుంది. Tailworm నన్ను దాన్ని చదివేలా చేసింది.

    చదవడానికి 15 నిమిషాలు

    Code, commands, సాంకేతిక పదాలను ఇంగ్లీష్‌లోనే ఉంచాను.

    మీ మీద ప్రభావం ఉందా? Tailworm SSH findings, Tailscale SSH నడిపే device మీద మాత్రమే వర్తిస్తాయి; ఏ device అయినా దాన్ని నడిపేది, ఎవరైనా tailscale set --ssh తో, లేదా దాన్ని wrap చేసే app లోని switch తో, on చేసినప్పుడు మాత్రమే. Windows, iPhone, Android, Mac app, Synology, QNAP devices దాన్ని నడపలేవు. Tailscale documentation ఆ server ని Linux కోసం, open-source command-line build లో macOS కోసం కూడా పేర్కొంటుంది; source code దాన్ని FreeBSD, OpenBSD కోసం కూడా build చేస్తుంది. కొన్ని NAS, router software లో దానికి ఒక switch ఉంటుంది: ఏ devices దాన్ని నడుపుతున్నట్లు report చేస్తున్నాయో admin console లోని Machines page చూపిస్తుంది (చెక్ లో 2వ step). Tailscale తన సొంత post లో వివరించిన vulnerabilities ని version 1.104.4 లేదా ఆ తర్వాతిది fix చేస్తుంది; report లోని పదకొండు findings లో కొన్ని headscale కు లేదా విడుదల కాని code కు సంబంధించినవి. ఏ device అయినా server నడిపితే, ఆ device ని update చేయండి.

    ఇది వేరే విషయం: మీరు మీ Tailscale access controls ని ఎప్పుడూ edit చేయకపోతే, default policy వల్ల server నడిపే మీ సొంత devices లో దేని మీదైనా, browser లో మళ్ళీ sign in అయిన తర్వాత, root గా (administrator account) Tailscale SSH session తెరవగలరు. Tag లేని మీ devices లో ఒకదాన్ని (tag అంటే tag:server వంటి label; చాలా home devices కి ఏదీ ఉండదు) ఆక్రమించిన ఎవరైనా అదే చేయగలిగే అవకాశం ఉంది; default rule tagged devices కి వర్తించదు. ఏ device కూడా server నడపకపోతే, ఈ రోజు ఆ rule కి పని చేయడానికి ఏమీ లేదు; ఇది చక్కదిద్దే పని, అత్యవసరం కాదు. ssh section ని delete చేస్తే అది మూసుకుపోతుంది. కింద ఉన్న ఐదు నిమిషాల చెక్ దీన్ని సురక్షితమైన క్రమంలో ఎలా చేయాలో చూపిస్తుంది.

    నేను నా tailnet (నా Tailscale network) ని సృష్టించినప్పుడు Tailscale రాసిన access policy, నా సొంత devices మీద root SSH session ని అనుమతించింది. దాన్ని నేను ఎప్పుడూ తెరిచి చూడలేదు. AI model అయిన Claude, ఈ post యొక్క నా మొదటి draft ని review చేసినప్పుడు దాన్ని ఎత్తి చూపింది; అప్పుడు మేము నా network ని Tailworm report తో పోల్చి చెక్ చేస్తున్నాము.

    Tailworm అనేది 24 అక్టోబర్ 2026 వారాంతంలో ప్రచురితమైన ఒక report: Tailscale, headscale లలో పదకొండు findings; వాటిలో అత్యంత తీవ్రమైనది Tailscale లోని built-in SSH server లో. Researcher lab లో, ఒక device ని అదుపులో ఉంచుకున్న attacker, ఆ device ని లోపలికి అనుమతించే rule కింద Tailscale SSH నడిపే ఇతర machines మీద root అయ్యాడు. Report వచ్చినప్పుడు Tailscale ఇంకా fix విడుదల చేయలేదు.

    కింద మీ సొంత tailnet కోసం ఐదు నిమిషాల చెక్ ఉంది. Attack కి ఏం కావాలో, నేను ఏం కనుగొన్నానో దాని తర్వాత వస్తాయి.

    Command line కొత్తా? Boxes ని ఎలా చదవాలి

    PS> అంటే: Windows లో PowerShell లో టైప్ చేయండి (Start menu → powershell అని టైప్ చేయండి → Enter). $ అంటే: Linux లేదా Mac లోని terminal లో, లేదా ssh (వేరే machine లోకి login చేయించే command) తో login అయిన తర్వాత remote machine లో టైప్ చేయండి. $ లేదా PS> ని టైప్ చేయకండి.

    $ లేదా PS> తో మొదలయ్యే ప్రతి line ఒక command. ఆ $ ని click చేస్తే ఆ line మాత్రమే copy అవుతుంది; దాన్ని paste చేసి, Enter నొక్కి, అది పూర్తయ్యే వరకు ఆగి, ఆ తర్వాతే తదుపరిదానికి వెళ్ళండి. పైన Copy button ఉన్న box లో ఒక command (లేదా ఒక file) ఉంటుంది, కాబట్టి దాన్ని మొత్తం copy చేయండి. Dashed box మీకు తిరిగి కనిపించాల్సిన దాన్ని చూపిస్తుంది; దాన్ని మీరు టైప్ చేయరు.

    మీ సొంత tailnet కోసం ఐదు నిమిషాల చెక్

    మొదలుపెట్టే ముందు

    • మీకు కావాల్సినవి: ఒక computer (phone మీద ఈ steps ఇబ్బందిగా ఉంటాయి), ఒక browser, Owner లేదా Admin role తో మీ tailnet కి sign-in (Network admin devices ని remove చేయలేరు; IT admin policy ని edit చేయలేరు).
    • ఎంత సమయం, ఎలా undo చేయాలి: “చూడండి” కి సుమారు ఐదు నిమిషాలు; అది ఏదీ మార్చదు. Policy లో ప్రతి మార్పు దాని saved copy తో మొదలవుతుంది, ప్రతి box అది చూడటం మాత్రమేనా లేక ఏదైనా మారుస్తుందా అని చెబుతుంది.

    చూడండి: ఏదీ మారదు

    1. Admin console ని తెరవండి. Web browser తెరిచి, console.tailscale.com/admin/machines కి వెళ్ళి, మీ tailnet కి యజమాని అయిన account తో sign in అవ్వండి. ఇది ఒక page ని మాత్రమే తెరుస్తుంది, సుమారు ఒక నిమిషం పడుతుంది. మీ devices table కనిపించాలి. Page తెరవకపోతే, మీ account కి Owner లేదా Admin role లేకపోవచ్చు; ఆ role ఉన్నవారిని అడగండి.
    2. Tailscale SSH నడిపే devices ని కనుగొనండి. Table పైన Filters ని click చేసి, Property ని, ఆ తర్వాత Tailscale SSH ని ఎంచుకోండి. Server నడుపుతున్నట్లు report చేసే devices కి మాత్రమే table తగ్గుతుంది. Table ఖాళీగా ఉంటే ఏ device నడపడం లేదని అర్థం. Filters కనిపించకపోతే, Tailscale యొక్క devices ని filter చేయడం గురించిన page చూడండి.
    3. ఐచ్ఛికం: ఒక device మీద నిర్ధారించుకోండి. ఈ list కింద ఉన్న collapsed block, Linux లో లేదా command-line build ఉన్న Mac లో ఎలా చేయాలో చూపిస్తుంది.
    4. మీ policy ని చదవండి. Console పై menu లో Access controls ని click చేయండి. Visual editor తెరిస్తే JSON editor కి మారండి. Text లోపల click చేసి, Ctrl+F (Mac లో Cmd+F) నొక్కి, "ssh" అని టైప్ చేసి Enter నొక్కండి. Match లేకపోతే policy లో SSH rule లేదని అర్థం, మీరు కింద ఉన్న “అందరికీ” కి వెళ్ళవచ్చు. కింద “నేను ఎప్పుడూ రాయని policy” లో చూపిన rule లా కనిపించే match ఉంటే, మీ policy మీ సొంత devices మీద root sessions ని అనుమతిస్తున్నట్లు; అది వేరేగా కనిపిస్తే, దాని "users" line ని చదవండి: దానిలో root ఉంటే root sessions ని అనుమతిస్తుంది. 2వ step లో devices కనిపిస్తే, కింద ఉన్న “మీరు Tailscale SSH వాడితే” కి వెళ్ళండి; దాని table ఖాళీగా ఉంటే, “మీరు Tailscale SSH వాడకపోతే” కి వెళ్ళండి.
    ఐచ్ఛికం: ఒక device మీద నిర్ధారించుకోండి (Linux, లేదా command-line build ఉన్న Mac)

    Terminal తెరవండి: Mac లో Cmd+Space నొక్కి, terminal అని టైప్ చేసి Enter నొక్కండి; Linux లో మీ terminal app ని తెరవండి, లేదా ssh <your-user>@<device-address> తో remote machine లోకి login అవ్వండి (Windows లోని PowerShell లో కూడా ssh పని చేస్తుంది). ఆ తర్వాత కింది command ని నడపండి. grep -i runssh RunSSH ని పేర్కొనే line ని మాత్రమే ఉంచుతుంది.

    tailscale debug prefs | grep -i runssh

    వెంటనే జవాబు ఇస్తుంది.

    "RunSSH": false,

    true అంటే device server ని నడుపుతోంది. ఏమీ print కాకపోతే, లేదా shell tailscale: command not found అని చెబితే, 2వ step ని ఆధారం చేసుకోండి: Mac app, Windows server ని నడపలేవు.

    Tailworm కి ఏం కావాలి

    Attack కి ఏమేం కావాలో లిస్ట్ చేసి, ప్రతి అంశాన్ని నా సొంత setup తో చెక్ చేశాను.

    ఒక Tailscale account లోని devices కలిసి ఒక tailnet అవుతాయి; ఏ device ఏ device ని చేరుకోవచ్చో admin console లోని policy file నిర్ణయిస్తుంది.

    Tailscale SSH అనేది Tailscale service లోపల ఉండే SSH server; tailscale set --ssh తో device మీద అది మొదలవుతుంది. ఎవరు login కావచ్చో, ఏ local account గా కావచ్చో password గానీ key గానీ కాదు, policy file నిర్ణయిస్తుంది. Report ప్రకారం, అలాంటి session ఒక Unix socket (ఒకే machine లోని programs ఒకదానితో ఒకటి మాట్లాడుకోవడానికి వాడే file లాంటి ఒక మార్గం) ని forward చేసినప్పుడు, ఆ పనిని Tailscale service root హక్కులతో చేసింది; check కి, socket వాడకానికి మధ్య ఉన్న సమయం, దాన్ని పరిమితం చేయడానికి పెట్టిన checks ని దాటేసింది. సాధారణ user గా లోపలికి అనుమతి పొందిన session root గా పని చేయగలిగింది.

    SSH attack కి మూడు విషయాలు కావాలి:

    1. Tailscale SSH నడుపుతున్న ఒక target device.
    2. Attacker device ఆ target మీద SSH session తెరవడానికి, forwarding అనుమతితో సహా, అనుమతించే policy file లోని ఒక rule.
    3. ఆ rule కిందకు వచ్చే ఒక device ని ఇప్పటికే అదుపులో ఉంచుకున్న attacker.

    మూడోది Tailworm ఇవ్వదు; attacker దాన్ని తానే తెచ్చుకుంటాడు: లోపం ఉన్న web application, హానికరమైన package, phishing, దొంగిలించిన passwords. ఇది open internet నుంచి వచ్చే attack కాదు.

    నేను కనుగొన్నది

    Attack కి కావాల్సింది నేను కనుగొన్నది మీ దాంట్లో ఎక్కడ చూడాలి
    Target మీద Tailscale SSH నడుస్తుండటం నేను చెక్ చేసినప్పుడు నా devices లో దేని మీదా నడవడం లేదు Admin console లోని Machines page, “Tailscale SSH” property తో filter చేసి (చెక్ లో 2వ step)
    SSH session ని అనుమతించే policy rule ఉంది: default rule. నా సొంత devices మీద root గా లేదా సాధారణ account గా, మళ్ళీ sign in అయిన తర్వాత Policy file (చెక్ లో 4వ step)
    Rule కిందకు వచ్చే device మీద foothold ఏ network లోనైనా లాగే సాధ్యమే —
    ఇతర findings అవి సంబంధించిన features కే వర్తిస్తాయి: app connectors, tailscale serve, ప్రతి client చేసే relay connection, headscale (Tailscale hosted control server కి open-source ప్రత్యామ్నాయం) Admin console

    అంటే attack కి కావాల్సిన మొదటిది లేదు. రెండోది, session ని అనుమతించే rule, default గానే ఉంది. Socket attack కి కావాల్సిన forwarding ని default rule అనుమతిస్తుందో లేదో Tailscale documentation చెప్పదు.

    లోతుగా: ప్రతి అంశాన్ని చెక్ చేయడానికి ఇతర మార్గాలు
    • మీరు OPNsense నడిపితే. Tailscale plugin తన settings ని ఒక API వెనుక ఉంచుతుంది. Read-only call GET /api/tailscale/settings/get, SSH server off గా ఉన్నప్పుడు "enableSSH":"0" ఇస్తుంది. Tailscale documentation SSH server ని Linux, macOS కోసం మాత్రమే పేర్కొంటుంది, కానీ దాని source code FreeBSD, OpenBSD కోసం కూడా build చేస్తుంది, OPNsense plugin లో దానికి ఒక switch ఉంది.
    • ప్రతి device. Admin console లో: Machines → Filters → Property → Tailscale SSH. ఏ device కూడా సరిపోకపోతే, ఏ device కూడా server నడుపుతున్నట్లు report చేయడం లేదు.
    • Linux device, లోపలి నుంచి. --ssh switch RunSSH అనే preference ని set చేస్తుంది. Server off గా ఉన్నప్పుడు tailscale debug prefs | grep -i runssh "RunSSH": false చూపిస్తుంది. tailscale set --ssh=false దాన్ని off చేస్తుంది.
    • Versions. Report 1.104.2 ని test చేసింది; అంతకంటే ముందు versions గురించి ఏమీ చెప్పదు. Tailscale fix 1.104.4 లో ఉంది.
    లోతుగా: report ఏం కనుగొంది, Tailscale ఏం చెప్పింది
    • ఏం test చేశారు. Tailscale 1.104.2, headscale 0.29.5 (Tailscale hosted control server కి open-source ప్రత్యామ్నాయం), ఏ మార్పూ లేకుండా, ఒక lab లో, 22 నుంచి 24 అక్టోబర్ 2026 వరకు.
    • Findings 1 నుంచి 3, SSH socket forwarding. Unix sockets యొక్క local, remote forwarding (ssh -L, ssh -R) ని root గా నడిచే Tailscale service చేసింది. Path check ఒక క్షణంలో జరిగింది, socket ని వాడింది మరో క్షణంలో; ఆ రెండింటి మధ్య ఉన్న సమయంలో జరిగిన race ని session లోపల వేగంగా తిరిగే ఒక loop గెలిచింది. Lab లో దీని వల్ల Docker socket ద్వారా root దొరికింది, root కి చెందిన sockets ని attacker వాటితో మార్చారు, కొత్త devices ని enrol చేయడానికి వాడే ఒక key ని పట్టుకున్నారు; ఆ key తో attacker machine network లో చేరింది. ఆ చివరి step ని Tailnet Lock off గా ఉన్నప్పుడు మాత్రమే report మొదటి నుంచి చివరి వరకు చూపించింది. Tailnet Lock on గా ఉన్నప్పుడు, lock ని disable చేయడానికి కావాల్సిన material ని పట్టుకుంది, కానీ దాన్ని వాడలేదు.
    • Finding 5, SSH memory exhaustion. Login అయిన ఒక session, root గా నడిచే Tailscale service ని memory ని allocate చేస్తూనే ఉండేలా చేయగలిగింది.
    • Tailscale ఏం చెప్పింది. ఈ issues కి “require urgent attention” (తక్షణ శ్రద్ధ అవసరం) అని, SSH vulnerabilities “primarily concerned how permissions were enforced” (ప్రధానంగా permissions ని ఎలా అమలు చేశారన్నదానికి సంబంధించినవి) అని, అది connection authorize అయిన తర్వాత జరిగేదని చెప్పింది; ఈ issues worm కిందకు వస్తాయన్నదాన్ని అంగీకరించదు; దీన్ని policy ఇప్పటికే అనుమతించే connections కి పరిమితమైన lateral movement అంటుంది.
    • Worm లాగా వ్యాపించే అవకాశం. Lab లో, ఒక compromised device, policy అనుమతించిన ప్రతి device ని, ఒక్కో step కి ఒక సెకనులోపే చేరుకుంది. వ్యాప్తిని ఆపిన ఒక control ని report పేర్కొంటుంది: ఒక source నుంచి ఒక destination కి అని రాసిన rules. Hardware లో ఉంచిన keys (TPM లేదా Secure Enclave) దొంగిలించిన device identity ఎక్కువ కాలం నిలవకుండా ఆపాయి.
    • ఇతర findings లో. Traffic ఎక్కడికి వెళ్తోందో check చేయని ఒక app-connector design (ఈ version, Conn25, ఇంకా విడుదల కాలేదని Tailscale చెబుతోంది); service యొక్క సొంత control socket కి tailscale serve forward చేయడం; relay client లో memory exhaustion (దానికి bulletin నాకు కనిపించలేదు); headscale మీద denial of service.
    • Bulletins. Tailscale నాలుగు ప్రచురించింది, అన్నీ 26 అక్టోబర్ తేదీతో, అన్నీ 1.104.4 లో fix అయ్యాయి: TS-2026-014 (SSH socket forwarding; Tailscale ఇప్పుడు root గా కాకుండా login అయిన user గా forward చేస్తుంది), TS-2026-015 (SSH memory exhaustion), TS-2026-016 (privileged sockets ని చేరుకునే tailscale serve), TS-2026-017 (HTTP/2 మీద Serve, ఒక mount యొక్క Tailscale-App-Capabilities values ని అదే node మీద ఉన్న మరో mount కి పంపగలిగేది). Device ని update చేసే వరకు, forwarding లోపానికి Tailscale సూచించే mitigation, Tailscale service యొక్క environment లో TS_SSH_DISABLE_FORWARDING=1 పెట్టడం; “ఆ తర్వాత, మీరు కనుగొన్నదాన్ని మార్చండి” లోని stopgap అది ఎలాగో చూపిస్తుంది.
    • ఇదే ప్రాంతంలో ముందటి fixes. జూన్, జూలై bulletins ఇప్పటికే symlink permissions ని పాటించని SSH socket forwarding (TS-2026-004, 3 జూన్), autogroup:nonroot ని దాటే ఒక మార్గం (TS-2026-009, 13 జూలై) ని కవర్ చేశాయి; రెండూ 1.98.9 లో fix అయ్యాయి.
    • Forwarding, default rule. Tailscale SSH server, సరిపోలిన rule లో Tailscale coordination server నుంచి వచ్చిన forwarding permission ఉన్నప్పుడు మాత్రమే forward చేస్తుంది (source code లో allowLocalPortForwarding, allowRemotePortForwarding). Policy దాన్ని ఎలా ఇస్తుందో, default rule ఇస్తుందో లేదో Tailscale public documentation చెప్పదు. Tailscale hosted service లో per-rule forwarding fields ని false గా set చేయమని report చెబుతుంది కానీ వాటి పేర్లు చెప్పదు; Tailscale policy documentation లో నాకు అవి కనిపించలేదు. ఈ issue “allow local or remote forwarding in their access policies” (తమ access policies లో local లేదా remote forwarding ని అనుమతించే) users ని ప్రభావితం చేస్తుందని bulletin TS-2026-014 చెబుతోంది.
    • Disclosure. శనివారం 24 అక్టోబర్ ఉదయం report అందిందని, రెండు గంటల తర్వాత report ప్రచురితమైందని Tailscale చెబుతోంది; అప్పటికే అది సంబంధిత issues ని పరిశీలిస్తోంది. Researcher దీన్ని “reported but not coordinated” (report చేశారు కానీ సమన్వయం చేయలేదు) అని వర్ణించినట్లు The Hacker News రాసింది.

    నేను ఎప్పుడూ రాయని policy

    మీరు tailnet సృష్టించినప్పుడు, Tailscale దానికి ఒక default policy ఇస్తుంది. దాని documentation దాన్ని ఇలా వివరిస్తుంది: ప్రతి device ప్రతి ఇతర device ని ప్రతి port మీద చేరుకోవచ్చు (దీన్ని కింద allow-all అంటాను), ప్రతి user తన సొంత devices మీద check mode లో root గా లేదా సాధారణ user గా Tailscale SSH session తెరవవచ్చు. SSH భాగం ఇలా ఉంటుంది:

    "ssh": [
      {
        "action": "check",
        "src":    ["autogroup:member"],
        "dst":    ["autogroup:self"],
        "users":  ["autogroup:nonroot", "root"]
      }
    ]

    Tailnet లోని ఏ user అయినా (autogroup:member) తనకు చెందిన devices కి (autogroup:self; tagged devices చేరవు), root తప్ప ఏ local account గా (autogroup:nonroot) అయినా, లేదా root గా connect కావచ్చు. నా దాంట్లో ఈ rule ఉంది, దానితో పాటు allow-all కూడా. Tailscale యొక్క policy-file page default ssh rule ని autogroup:nonroot తో వివరిస్తుంది, root ని పేర్కొనదు; దాని SSH page, దాని ఉదాహరణ policies లో root ఉంది, పైన చూపినట్లు.

    నన్ను, నా devices లో ఒకదాన్ని ఆక్రమించిన వ్యక్తిని ఈ rule వేరు చేసి చూడలేదు. Tailscale దృష్టిలో నా devices లో ఒకదాని నుంచి వచ్చే connection నేనే. Tailnet లోని ఒక Linux device లో tailscale set --ssh నడిచి ఉంటే, నా మరో device ని ఆక్రమించిన వ్యక్తి ఆ device మీద root session తెరవగలడు. అది rule design ప్రకారం పని చేయడమే, లోపం కాదు. Check mode నా browser sign-in ని అడుగుతుంది, ఒక approval 12 గంటల పాటు అమలులో ఉండవచ్చు (కింద చూడండి).

    Session మొదలవక ముందు check mode browser లో కొత్త sign-in అడుగుతుంది. Default check period తో, ఒక check-mode sign-in తో ఆ device ని, tailnet లోని ఇతర ఏ device ని అయినా మళ్ళీ sign in కాకుండానే 12 గంటల పాటు చేరుకోవచ్చని Tailscale documentation చెబుతుంది. అది వేరే device నుంచి తెరిచిన session కి కూడా వర్తిస్తుందో లేదో అది చెప్పదు. ఒక device మీద ఉన్న attacker మీ తదుపరి approval కోసం ఎలా వేచి ఉండవచ్చో, లేదా దాన్ని ఇవ్వమని మిమ్మల్ని ఎలా prompt చేయవచ్చో report వివరిస్తుంది; కాబట్టి check mode దీన్ని నెమ్మదింపజేస్తుంది, ఆపదు.

    సాధారణ account ని root గా మార్చడానికి Tailworm కి socket forwarding కావాల్సి వచ్చింది. Default rule కి ఏదీ అక్కర్లేదు, ఒక check-mode approval చాలు. ఇది documentation లో ఉన్న ప్రవర్తనే, vulnerability కాదు. 1.104.4 కి update చేయడం కూడా దీన్ని మార్చదు: root గా లోపలికి అనుమతించిన session design ప్రకారమే root.

    నేను ఏం మార్చాను

    Policy. కొత్త దాంట్లో ssh section లేదు. SSH rules ని తొలగిస్తే tailnet అంతటా Tailscale SSH disable అవుతుందని Tailscale documentation చెబుతుంది. Allow-all స్థానంలో అవసరమైనది మాత్రమే grants తో ఇవ్వవచ్చు, ఉదాహరణకు:

    1. Exit nodes వాడితే: autogroup:internet కి access.
    2. మీరు manage చేయాల్సిన కొన్ని devices, అంతకు మించి ఏమీ కాదు. ఈ grant ని పరిమితంగా ఉంచండి: అది కవర్ చేసే ప్రతి device చేరుకునేలానే ఉంటుంది.

    Allow-all ని మార్చడానికి ఒక మూల్యం ఉంది: devices ఒకదాన్ని ఒకటి చేరుకోవడం మీద ఆధారపడిన ప్రతిదీ ఆగిపోతుంది, ఉదాహరణకు file sharing, media server, subnet route. ముందుగా వాటిలో ప్రతిదానికి సొంత grant ఇవ్వండి.

    ఆ తర్వాత tests. Policy file లో tests ఉండవచ్చు: “ఈ user ఈ port ని చేరుకోవచ్చు” వంటి statements; file మారినప్పుడల్లా Tailscale వాటిని check చేస్తుంది. ఏదైనా test fail అయితే ఆ మార్పును తిరస్కరిస్తుంది. ఏది పని చేయాలో, ఏది తిరస్కరించబడాలో tests చెప్పగలవు; ఉదాహరణకు అవసరం లేని device మీద SSH, file sharing, remote desktop (ports 22, 445, 3389) తిరస్కరించబడాలని.

    లోతుగా: ఒక ఉదాహరణ policy

    ఇది ఒక ఆకృతి, template కాదు. Exit nodes తప్ప మిగతావన్నీ కట్ చేస్తుంది; ఉన్నది ఉన్నట్లు paste చేస్తే, మీ సొంత NAS నుంచి, media server నుంచి మిమ్మల్ని కట్ చేస్తుంది. Addresses, e-mail placeholders మాత్రమే.

    {
      "grants": [
        // 1. Use exit nodes.
        {"src": ["autogroup:member"], "dst": ["autogroup:internet"], "ip": ["*"]},
    
        // 2. Add a grant for each device you must reach, and no more.
    
        // Nothing else: other devices accept no inbound tailnet traffic.
      ],
    
      // An empty "acls" list: Tailscale's documentation gives this form for deny-all;
      // omitting the section is documented as allow-all.
      "acls": [],
    
      // No "ssh" section: no Tailscale SSH session is allowed anywhere.
    
      "tests": [
        {
          "src":    "you@example.com",
          // "accept": ["100.x.y.2:445"],  one line like this for each thing that must work.
          "deny":   ["100.x.y.3:22", "100.x.y.3:445", "100.x.y.3:3389"], // a device that must refuse these
        },
      ],
    }

    మీ tailnet లోని users కి file shares అందించాల్సిన, అంతకు మించి ఏమీ చేయని NAS కోసం grant ఇలా ఉంటుంది (port ఒక ఉదాహరణ; అది అందించాల్సిన ప్రతి ఇతర service కోసం ఒక tcp: entry ని చేర్చండి; nas అనేది policy యొక్క hosts section లో మీరు నిర్వచించే పేరు, ఉదాహరణకు "hosts": {"nas": "100.x.y.2"}):

    {"src": ["autogroup:member"], "dst": ["nas"], "ip": ["tcp:445"]},

    గమనికలు:

    • autogroup:internet కి access ఉన్న devices మాత్రమే exit nodes ని వాడగలవు; అందుకే grant 1 అలా రాసి ఉంది.
    • Tests rules ని check చేస్తాయి, network ని కాదు: test pass అయినంత మాత్రాన device స్పందిస్తుందని రుజువు కాదు.
    • "acls": [] ఎందుకు ఉంచాలి. acls section ని వదిలేస్తే అది default allow-all policy తో సమానమని Tailscale documentation చెబుతుంది, దాని deny-all ఉదాహరణ "acls": []. Grants ఉన్న policy లో వదిలేయడానికి అర్థం ఏమిటో అది చెప్పదు. ఖాళీ list ని ఉంచి tests నిర్ణయించనివ్వండి: allow-all తెరిచే port కోసం deny test, allow-all అమలులో ఉన్నంత వరకు fail అవుతుంది.
    • Save చేసే ముందు పాత policy కాపీ ఉంచుకోండి (కింద “మీరు Tailscale SSH వాడకపోతే: అన్ని చోట్లా off చేయండి” లోని 1వ step ఇది చేస్తుంది). Configuration logs page నుంచి ఒక మార్పును revert చేయడానికి కూడా Tailscale అనుమతిస్తుంది.
    లోతుగా: నేను మళ్ళీ వాడే పద్ధతి

    Attack కి ఏం కావాలో list చేయండి; ప్రతి అంశాన్ని మీ సొంత devices మీద check చేసి, ఎలా చేశారో రాసుకోండి; attack వర్తించని చోట కూడా ఏది తప్పుగా ఉందో వెతకండి; మిగిలిన వాటిని ఏం మార్చాలి, ఏం గమనించాలి, ఏ risk ని అంగీకరించాలి అని విభజించండి.

    ఆ తర్వాత, మీరు కనుగొన్నదాన్ని మార్చండి

    మీరు Tailscale SSH వాడకపోతే: అన్ని చోట్లా off చేయండి

    మొదలుపెట్టే ముందు: ఇది మీ policy ని మారుస్తుంది, తద్వారా ఏ device కూడా Tailscale SSH session ని అంగీకరించదు. ఏదైనా machine లోకి Tailscale SSH ఒక్కటే మీ దారి అయితే దీన్ని చేయకండి. సుమారు మూడు నిమిషాలు పడుతుంది. Undo చేయడానికి, saved copy ని తిరిగి paste చేసి (1వ step) save చేయండి, లేదా Configuration logs page నుంచి ఆ మార్పును revert చేయండి.

    1. Policy కాపీ save చేయండి. JSON editor లో text లోపల click చేసి Ctrl+A (Mac లో Cmd+A) నొక్కి, ఆ తర్వాత Ctrl+C (Cmd+C) నొక్కండి. Notepad (Start menu → notepad అని టైప్ చేయండి → Enter) లేదా Mac లో TextEdit (ముందు Format → Make Plain Text) తెరిచి, Ctrl+V (Cmd+V) తో paste చేసి, ఫైల్ ని మీ Documents folder లో policy-backup.json గా save చేయండి. File లో మొత్తం policy ఉండాలి, అది { తో మొదలవుతుంది.
    2. ssh section ని delete చేయండి. Console కి తిరిగి వచ్చి, "ssh": [ నుంచి దాని కింద వరుసలో ఉన్న ] వరకు (rule లోపలి ] కాదు), దాని తర్వాత comma ఉంటే దానితో సహా, అన్నీ select చేసి Delete నొక్కండి. Policy file ఒక అదనపు comma ని అనుమతిస్తుంది. మిగిలిన sections ని ఉన్నట్లే వదిలేయండి.
    3. Save. Save ని click చేయండి. మార్పును అమలు చేసే ముందు Tailscale policy ని, దానిలోని tests ని check చేస్తుంది. Save అయిందని console నిర్ధారించడం కనిపించాలి. Syntax error అని చెబితే, ఏదో comma లేదా bracket చోటు తప్పింది: saved copy ని తిరిగి paste చేసి 2వ step నుంచి మళ్ళీ చేయండి. అది ఒక sshTests entry ని పేర్కొంటే, ఆ test ని కూడా delete చేయండి.
    4. Check. Page ని reload చేసి, Ctrl+F (Cmd+F) నొక్కి "ssh" కోసం వెతకండి. Match ఉండకూడదు. Opt in అయిన device మీద మీరు tailscale set --ssh=false నడిపే వరకు అది server ని నడుపుతూనే ఉంటుంది.

    మీరు Tailscale SSH వాడితే: update చేసి, ఆ తర్వాత rule ని కుదించండి

    మొదలుపెట్టే ముందు: update చేస్తే ఆ device మీద తెరిచి ఉన్న ప్రతి Tailscale SSH session ముగుస్తుంది. Tailscale SSH session నుంచి update ని నడపకండి. లోపలికి వేరే దారి వాడండి: machine కి keyboard, screen కలిపి, లేదా మీ local network లో సాధారణ ssh login. Device యొక్క Tailscale address (100.…) కి చేసిన ssh login కూడా Tailscale restart అయినప్పుడు తెగిపోతుంది, update మధ్యలో తెగిపోతే install కి అంతరాయం కలగవచ్చు. కింది commands Tailscale యొక్క సొంత package repository ఉన్న Debian, Ubuntu, Raspberry Pi OS కోసం. ఇతర systems కోసం, Tailscale యొక్క update చేయడం గురించిన page చూడండి.

    1. వేరే దారిలో device లోకి login అవ్వండి, దానిపై terminal తెరవండి. దాని shell prompt కనిపించాలి.
    2. అది ఏ version నడుపుతోందో చూడండి.
    tailscale version

    మొదటి line version number. 1.104.4 లేదా ఆ తర్వాతి దాంట్లో fixes ఉన్నాయి. అంతకంటే తక్కువైతే update కావాలి.

    1. Update. sudo ఒక command ని administrator గా నడుపుతుంది, మీ password అడగవచ్చు; టైప్ చేస్తున్నప్పుడు ఏదీ కనిపించదు, కాబట్టి టైప్ చేసి Enter నొక్కండి.
    sudo apt update
    sudo apt install --only-upgrade tailscale

    ప్రతిదానికి ఒక నిమిషం లోపు పడుతుంది. Tailscale కొన్ని సెకన్ల పాటు restart అవుతుంది. Update మధ్యలో ఆగిపోతే, sudo dpkg --configure -a దాన్ని పూర్తి చేస్తుంది. tailscale ఇప్పటికే newest version అని apt చెబితే, ఆ device లో fix ఉంది, లేదా అది Tailscale ని Tailscale repository నుంచి తీసుకోలేదు.

    1. tailscale version తో మళ్ళీ check చేయండి. మొదటి line లో 1.104.4 లేదా ఆ తర్వాతిది ఉండాలి.
    2. Rule ని కుదించండి. మీరు ఏదైనా host లో, ఉదాహరణకు Proxmox server లో, root గా login అవుతుంటే, లేదా sudo ఉన్న మరో account లేని host లో, ఇది ఆ access ని తొలగిస్తుంది: ముందు check చేయండి. Edit చేసే ముందు policy కాపీ save చేయండి (“మీరు Tailscale SSH వాడకపోతే: అన్ని చోట్లా off చేయండి” లోని 1వ step). ఆ తర్వాత console లో Access controls, JSON editor కి వెళ్ళి, మీ ssh rule లోని "users" line ని కనుగొని, దాని నుంచి , "root" ని delete చేయండి:
    "users":  ["autogroup:nonroot", "root"]
    "users":  ["autogroup:nonroot"]

    Save ని click చేయండి. ఇప్పుడు rule root sessions ని ఇవ్వదు; login అయిన తర్వాత sudo వాడండి. మీ account కి password లేని sudo ఉన్న host లో, ఇది attacker ని నెమ్మదింపజేస్తుంది, ఆపదు. ఇది update కి ప్రత్యామ్నాయం కాదు: జూలై bulletin TS-2026-009 autogroup:nonroot ని దాటే మార్గం. అలాగే src, dst లను SSH అవసరమైన వ్యక్తులకు, devices కు పరిమితం చేయండి.

    Stopgap: update చేయలేని device మీద SSH forwarding ని off చేయండి

    మీరు వాడే package source ఇంకా 1.104.4 లేదా ఆ తర్వాతిది ఇవ్వని చోట మాత్రమే దీన్ని వాడండి. Forwarding లోపానికి Tailscale సూచించే mitigation, Tailscale service యొక్క environment లో TS_SSH_DISABLE_FORWARDING=1 setting. Debian-style installs లో service /etc/default/tailscaled ని చదువుతుంది (Tailscale source లోని tailscaled.service file దాన్ని EnvironmentFile గా పేర్కొంటుంది). కింది commands ని ఆ file కాపీల మీద test చేశాను, నడుస్తున్న Tailscale service మీద కాదు. Restart వల్ల తెరిచి ఉన్న Tailscale SSH sessions ముగుస్తాయి, కాబట్టి వీటిని లోపలికి వేరే దారి నుంచి నడపండి. ఈ commands systemd ఉందని ఊహిస్తాయి.

    1. File ని back up చేయండి. Command No such file or directory అని చెబితే, ఈ device ఆ setting ని వేరే చోట ఉంచుతుంది; ఆగి, మీ install కోసం Tailscale page ని చదవండి. ఒక్కసారే నడపండి: రెండోసారి నడిపితే backup, edit చేసిన file తో మారిపోతుంది.
    sudo cp /etc/default/tailscaled /etc/default/tailscaled.bak
    1. Setting ని చేర్చండి. File లోని చివరి line తో కలిసిపోకుండా ఉండటానికి ఈ line ఒక ఖాళీ line తో మొదలవుతుంది.
    printf '\nTS_SSH_DISABLE_FORWARDING=1\n' | sudo tee -a /etc/default/tailscaled

    ఇది చేర్చినదాన్ని print చేస్తుంది. ఒక్కసారే నడపండి: రెండోసారి నడిపితే line రెండుసార్లు చేరుతుంది.

    1. Service ని restart చేయండి.
    sudo systemctl restart tailscaled
    1. నడుస్తున్న service కి అది ఉందో check చేయండి.
    sudo cat /proc/$(systemctl show -p MainPID --value tailscaled)/environ | tr '\0' '\n' | grep TS_SSH
    TS_SSH_DISABLE_FORWARDING=1

    Output లేకపోతే service ఆ setting ని తీసుకోలేదని అర్థం: ఆ line file లో ఉందో grep TS_SSH /etc/default/tailscaled తో check చేసి, ఆ తర్వాత 3వ step ని మళ్ళీ చేయండి. /proc/0/environ: No such file or directory అంటే service నడవడం లేదు.

    1. Undo చేయడానికి, ఆ line ని తొలగించి restart చేయండి. Device 1.104.4 లేదా ఆ తర్వాతిది నడిపినప్పుడు కూడా ఇలా చేయండి; ఆ setting ఒక stopgap. 1వ step తర్వాత package upgrade ఆ file ని మార్చేసినా, line ని తొలగించడం సురక్షితమే; backup ఒక record గా మిగులుతుంది. Upgrade, మీరు edit చేసిన file ని ఉంచాలా అని అడగవచ్చు:
    sudo sed -i '/^TS_SSH_DISABLE_FORWARDING=1$/d' /etc/default/tailscaled
    sudo systemctl restart tailscaled

    sed file ని చదవలేనని చెబితే, ఈ device లో undo చేయాల్సింది ఏమీ లేదు.

    అందరికీ

    1. ఇక మీరు చూసుకోని devices ని, అవి మీ చేతుల్లోంచి వెళ్ళే ముందే, remove చేయండి. Tailscale ద్వారా మాత్రమే చేరగలిగే device ని remove చేయకండి: దాన్ని తిరిగి add చేయడానికి మీరు ఆ machine దగ్గర ఉండాలి. Console లో Machines ని తెరిచి, search bar లో పేరుతో device ని కనుగొని, దాని పక్కన menu ని తెరిచి, Remove ని, ఆ తర్వాత dialog లో Remove machine ని ఎంచుకోండి. Device list నుంచి మాయమవుతుంది. పొరపాటున ఒకదాన్ని remove చేస్తే, తిరిగి add చేయడానికి ఆ device ని మళ్ళీ sign in చేయండి; మీ tailnet కి device approval అవసరమైతే, admin approve చేయాలి.
    2. Allow-all ని మళ్ళీ చూడండి. Access controls లో "acls", "grants" కోసం వెతకండి. Source * గా, destination * లేదా *:* గా ఉన్న rule allow-all: ప్రతి device ప్రతి ఇతర device ని ప్రతి port మీద చేరుకోవచ్చు. దాన్ని మార్చే steps కింద ఉన్నాయి.
    Allow-all ని మార్చడం, step by step

    మొదలుపెట్టే ముందు: ఇది మీ policy ని మారుస్తుంది, devices ని ఒకదాని నుంచి ఒకటి కట్ చేయవచ్చు. ఆ తర్వాత ప్రతి service ని test చేయగలిగినప్పుడు చేయండి. 15 నుంచి 30 నిమిషాలు పడుతుంది. Undo చేయడానికి, policy యొక్క saved copy ని తిరిగి paste చేసి (“మీరు Tailscale SSH వాడకపోతే: అన్ని చోట్లా off చేయండి” లోని 1వ step) save చేయండి, లేదా Configuration logs page నుంచి ఆ మార్పును revert చేయండి. మీ phone లేదా laptop exit node ని వాడితే, ప్రతి save తర్వాత దాని internet access ని test చేయండి: exit-node grant తప్పుగా ఉంటే అది తెగిపోతుంది.

    1. మీ devices కి ఒకదాని నుంచి ఒకటి ఏం కావాలో రాసుకోండి: file shares, media server, subnet route, printer. కాగితం లేదా text file వాడండి.
    2. పైన చెప్పినట్లు policy కాపీ save చేయండి.
    3. ప్రతి అవసరానికి ఒక grant ని "grants" section లో చేర్చండి (section లేకపోతే చేర్చండి; allow-all "acls" లో ఉంది), పైన “ఒక ఉదాహరణ policy” లోని NAS ఉదాహరణ లాగా. ఆ పేరును మీరు నిర్వచించకపోతే nas బదులు NAS యొక్క Tailscale address (Machines page లో కనిపిస్తుంది) ని వాడండి. Exit nodes వాడితే వాటికి ఒక grant చేర్చండి.
    4. అదే ఉదాహరణలో లాగా, పని చేయాల్సిన వాటికి tests చేర్చండి. Save ని click చేయండి. ఏదైనా test fail అయితే, Tailscale ఆ మార్పును తిరస్కరించి ఆ test పేరు చెబుతుంది.
    5. Allow-all rule ని delete చేయండి, కానీ "acls" section ని "acls": [] గా ఉంచండి: deny-all కోసం Tailscale documentation ఆ రూపాన్ని ఇస్తుంది, section ని వదిలేస్తే అది allow-all తో సమానమని చెబుతుంది. పని చేయకూడని వాటికి tests చేర్చండి (వాటిని అంగీకరించకూడని device మీద ports 22, 445, 3389 వంటివి), మళ్ళీ Save ని click చేయండి. Allow-all ఇంకా ఉన్నంత వరకు ఆ tests fail అవుతాయి, అందుకే వాటిని ఈ step లోనే చేర్చాలి.
    6. ప్రతి service ని దాన్ని వాడే device నుంచి test చేయండి. ఏదైనా fail అయితే, దాని grant ని చేర్చండి, లేదా saved copy ని తిరిగి paste చేయండి.

    స్థితి

    Version 1.104.4 ని 27 అక్టోబర్ 2026 (UTC) రోజు చివర్లో tag చేశారు; Tailscale changelog దానికి 28 అక్టోబర్ తేదీ ఇచ్చింది. 2 నవంబర్ 2026 న విడుదలైన version 1.104.5, Tailscale SSH connection stalls ని, restart hangs ని fix చేస్తుంది, approval గడువు ముగిసినప్పుడు check-mode sessions disconnect కాకుండా ఆపుతుంది; ప్రస్తుత release కి update చేయండి. 10 నవంబర్ 2026 న bulletins page (TS-2026-014 నుంచి TS-2026-017 వరకు, 26 అక్టోబర్ తేదీతో) లో CVE numbers కనిపించలేదు.

    ఇది ఎలా చేశాను

    ఈ checking ని Anthropic యొక్క AI model అయిన Claude తో కలిసి చేశాను. Replacement policy ని, దాని tests ని, ఈ post ని అది draft చేసింది. నా మొదటి draft ని Claude review చేసినప్పుడు default rule ఇప్పటికే root ని అనుమతిస్తుందని చూపింది. ఆ తర్వాత Claude దాన్ని Tailscale documentation తో check చేసింది; open-source code లో default policy లేదు.

    పదకోశం
    • Tailscale: WireGuard మీద నిర్మించిన mesh VPN; sign-in, keys ని చూసుకునే hosted service తో.
    • Tailnet: ఒక Tailscale account లోని devices సమూహం.
    • Policy file: Tailnet యొక్క access rules, admin console లో edit చేస్తారు. Grants ఏ device ఏ device ని చేరుకోవచ్చో నిర్ణయిస్తాయి; ssh section ఎవరు Tailscale SSH sessions తెరవవచ్చో నిర్ణయిస్తుంది; tests rules మారినప్పుడల్లా వాటిని check చేస్తాయి.
    • Allow-all: ప్రతి device ప్రతి ఇతర device ని ప్రతి port మీద చేరుకోనిచ్చే default acls rule.
    • Tag: tag:server వంటి label; ఇది device కి user గుర్తింపు బదులు దాని సొంత గుర్తింపు ఇస్తుంది; tagged devices autogroup:self కిందకు రావు.
    • autogroup:member / self / nonroot: Tailnet లోని ఏ user అయినా; user కి చెందిన devices (tagged వి కాదు); root తప్ప ఏ local account అయినా.
    • Tailscale SSH: Tailscale service లో built-in గా ఉన్న SSH server; ఎవరు login కావచ్చో passwords లేదా keys బదులు policy file నుంచి నిర్ణయిస్తుంది.
    • Check mode: Session మొదలవక ముందు user ని మళ్ళీ sign in చేయమని అడిగే ssh rule action; ఒక sign-in default గా 12 గంటలు ఉంటుంది.
    • Exit node: ఇతర devices తమ internet traffic ని పంపగలిగే tailnet లోని device.
    • root: Linux, macOS లోని administrator account; machine మీద ఏదైనా చేయగలదు.
    • Subnet route: దాని వెనుక ఉన్న మొత్తం local network ని tailnet చేరుకునేలా చేసే device.
    • Unix socket: ఒకే machine లోని programs ఒకదానితో ఒకటి మాట్లాడుకోవడానికి వాడే file లాంటి endpoint, ఉదాహరణకు Docker యొక్క control socket.
    • Port forwarding (SSH లో): ఒక socket కి connection వంటి మరో connection ని SSH session ద్వారా మోసుకెళ్ళడం.
    • Tailnet Lock: కొత్త device చేరే ముందు నమ్మదగిన devices దానిపై sign చేయాలని కోరే Tailscale feature.
    • Foothold: Attacker ఇప్పటికే అదుపులో ఉంచుకున్న device; తదుపరి attacks దాని నుంచి మొదలవుతాయి.
    • headscale: Tailscale hosted control server కి open-source ప్రత్యామ్నాయం.
    • CVE: ఒక నిర్దిష్ట vulnerability కి public identifier.
    • sudo: Command ని administrator గా నడిపే command prefix; password అడగవచ్చు.
    • ssh: మరో machine లోకి login చేయించే command.

    మూలాలు

    Policy แบบ default ของ Tailscale อนุญาต root SSH. Tailworm ทำให้ผมต้องอ่านมัน

    อ่าน 11 นาที

    โค้ด คำสั่ง และศัพท์เทคนิคคงไว้เป็นภาษาอังกฤษ

    คุณได้รับผลกระทบหรือไม่? ข้อค้นพบด้าน SSH ของ Tailworm มีผลเฉพาะกับอุปกรณ์ที่รัน Tailscale SSH และอุปกรณ์จะรัน server นี้ก็ต่อเมื่อมีคนเปิด ด้วย tailscale set --ssh หรือด้วยสวิตช์ในแอปที่ครอบมันไว้ Windows, iPhone, Android, แอป Mac และอุปกรณ์ Synology กับ QNAP รัน server นี้ไม่ได้ เอกสารของ Tailscale ระบุว่า server นี้มีให้บน Linux และบน macOS เฉพาะรุ่น command-line แบบ open-source ส่วน source code ยัง build ให้ FreeBSD และ OpenBSD ด้วย ซอฟต์แวร์ NAS และ router บางตัวมีสวิตช์สำหรับมัน: หน้า Machines ใน admin console แสดงว่าอุปกรณ์ไหนรายงานว่ารัน server นี้ (ข้อ 2 ของการตรวจ) เวอร์ชัน 1.104.4 หรือใหม่กว่าแก้ช่องโหว่ที่โพสต์ของ Tailscale เองอธิบายไว้ ข้อค้นพบ 11 ข้อของรายงานบางข้อเกี่ยวกับ headscale หรือโค้ดที่ยังไม่ได้เผยแพร่ ถ้าอุปกรณ์เครื่องใดรัน server นี้ ให้อัปเดตเครื่องนั้น

    อีกเรื่องหนึ่ง: ถ้าคุณไม่เคยแก้ access controls ของ Tailscale เลย policy แบบ default ให้คุณเปิด session ของ Tailscale SSH ในฐานะ root (บัญชีผู้ดูแลระบบ) บนอุปกรณ์ของคุณเองเครื่องใดก็ได้ที่รัน server นี้ หลังจากล็อกอินซ้ำใน browser ใครก็ตามที่ยึดอุปกรณ์ของคุณเครื่องที่ไม่มี tag (tag คือป้ายชื่ออย่าง tag:server อุปกรณ์ที่บ้านส่วนใหญ่ไม่มี) อาจทำแบบเดียวกันได้ กฎ default ไม่ครอบคลุมอุปกรณ์ที่มี tag ถ้าไม่มีอุปกรณ์ใดรัน server นี้ กฎนั้นยังไม่มีเครื่องให้มีผลในตอนนี้ นี่เป็นงานดูแลความเรียบร้อย ไม่ใช่เหตุฉุกเฉิน การลบส่วน ssh ปิดช่องนี้ การตรวจ 5 นาที ด้านล่างแสดงวิธีทำตามลำดับที่ปลอดภัย

    access policy ที่ Tailscale เขียนให้ตอนผมสร้าง tailnet (เครือข่าย Tailscale ของผม) อนุญาตให้เปิด SSH session แบบ root บนอุปกรณ์ของผมเอง ผมไม่เคยเปิดดูมันเลย Claude ซึ่งเป็นโมเดล AI ชี้เรื่องนี้ให้เห็นในการตรวจร่างแรกของผมสำหรับโพสต์นี้ ระหว่างที่เราตรวจเครือข่ายของผมเทียบกับ Tailworm

    Tailworm คือรายงานที่เผยแพร่ช่วงสุดสัปดาห์ของวันที่ 24 ตุลาคม 2026 มีข้อค้นพบ 11 ข้อใน Tailscale และ headscale ข้อที่ร้ายแรงที่สุดอยู่ใน SSH server ที่ติดมากับ Tailscale ในแล็บของนักวิจัย ผู้โจมตีที่ควบคุมอุปกรณ์หนึ่งเครื่องได้สิทธิ์ root บนเครื่องอื่นที่รัน Tailscale SSH ภายใต้กฎที่อนุญาตให้อุปกรณ์นั้นเข้ามา ตอนที่รายงานออก Tailscale ยังไม่ได้ปล่อยการแก้ไข

    ด้านล่างคือการตรวจ 5 นาทีสำหรับ tailnet ของคุณเอง ส่วนสิ่งที่การโจมตีต้องใช้ และสิ่งที่ผมพบ อยู่ถัดจากนั้น

    เพิ่งเริ่มใช้ command line? วิธีอ่านกล่องคำสั่ง

    PS> หมายถึง: พิมพ์ใน PowerShell บน Windows (เมนู Start → พิมพ์ powershell → Enter) $ หมายถึง: พิมพ์ใน terminal บน Linux หรือ Mac หรือบนเครื่องระยะไกลหลังจากที่คุณล็อกอินด้วย ssh (คำสั่งที่ใช้ล็อกอินเข้าเครื่องอื่น) อย่าพิมพ์ $ หรือ PS> เอง

    แต่ละบรรทัดที่ขึ้นต้นด้วย $ หรือ PS> คือคำสั่งหนึ่งคำสั่ง คลิกที่ $ เพื่อคัดลอกเฉพาะบรรทัดนั้น วางลงไป กด Enter และรอให้ทำงานเสร็จก่อนจะไปคำสั่งถัดไป กล่องที่มีปุ่ม Copy อยู่ด้านบนเก็บคำสั่งเดียว (หรือไฟล์เดียว) จึงต้องคัดลอกทั้งกล่อง กล่องเส้นประแสดงสิ่งที่คุณควรเห็นตอบกลับมา คุณไม่ต้องพิมพ์มัน

    ตรวจ tailnet ของคุณเองใน 5 นาที

    ก่อนเริ่ม

    • สิ่งที่ต้องมี: คอมพิวเตอร์ (ขั้นตอนเหล่านี้ทำบนโทรศัพท์ได้ยาก), browser และบัญชีที่ล็อกอินเข้า tailnet ของคุณได้ด้วย role Owner หรือ Admin (role Network admin ลบอุปกรณ์ไม่ได้ role IT admin แก้ policy ไม่ได้)
    • ใช้เวลาเท่าไร และย้อนกลับอย่างไร: ประมาณ 5 นาทีสำหรับส่วน “ดู” ซึ่งไม่เปลี่ยนอะไร ทุกการเปลี่ยน policy เริ่มด้วยการเก็บสำเนา และทุกกล่องบอกว่าแค่ดูหรือเปลี่ยนอะไร

    ดู: ไม่มีอะไรเปลี่ยน

    1. เปิด admin console เปิด web browser ไปที่ console.tailscale.com/admin/machines และล็อกอินด้วยบัญชีที่เป็นเจ้าของ tailnet ของคุณ ขั้นนี้แค่เปิดหน้าเว็บ ใช้เวลาประมาณ 1 นาที คุณควรเห็นตารางอุปกรณ์ของคุณ ถ้าเปิดหน้านี้ไม่ได้ บัญชีของคุณอาจไม่มี role Owner หรือ Admin ให้ถามคนที่มี
    2. หาอุปกรณ์ที่รัน Tailscale SSH เหนือตาราง คลิก Filters เลือก Property แล้วเลือก Tailscale SSH ตารางจะเหลือเฉพาะอุปกรณ์ที่รายงานว่ารัน server นี้ ตารางว่างหมายความว่าไม่มีเครื่องไหนรัน ถ้าหา Filters ไม่เจอ ดู หน้าว่าด้วยการกรองอุปกรณ์ ของ Tailscale
    3. ไม่บังคับ: ยืนยันบนอุปกรณ์หนึ่งเครื่อง กล่องที่พับอยู่ใต้รายการนี้แสดงวิธี บน Linux หรือบน Mac ที่ใช้ รุ่น command-line
    4. อ่าน policy ของคุณ ในเมนูด้านบนของ console คลิก Access controls ถ้าเปิดเป็น visual editor ให้สลับไปที่ JSON editor คลิกในข้อความ กด Ctrl+F (Cmd+F บน Mac) พิมพ์ "ssh" แล้วกด Enter ถ้าไม่พบ แสดงว่า policy ไม่มีกฎ SSH และคุณข้ามไปที่ “สำหรับทุกคน” ด้านล่างได้ ถ้าพบส่วนที่หน้าตาเหมือนกฎที่แสดงไว้ใต้หัวข้อ “Policy ที่ผมไม่เคยเขียน” ด้านล่าง แสดงว่า policy ของคุณอนุญาต root session บนอุปกรณ์ของคุณเอง ถ้าหน้าตาต่างไป ให้อ่านบรรทัด "users" ของมัน: ถ้ามี root อยู่ในนั้น แสดงว่าอนุญาต root session ถ้าข้อ 2 แสดงอุปกรณ์ ให้ไปที่ “ถ้าคุณใช้ Tailscale SSH” ด้านล่าง ถ้าตารางของข้อ 2 ว่าง ให้ไปที่ “ถ้าคุณไม่ใช้ Tailscale SSH”
    ไม่บังคับ: ยืนยันบนอุปกรณ์หนึ่งเครื่อง (Linux หรือ Mac ที่ใช้รุ่น command-line)

    เปิด terminal: บน Mac กด Cmd+Space พิมพ์ terminal แล้วกด Enter บน Linux เปิดแอป terminal หรือล็อกอินเข้าเครื่องระยะไกลด้วย ssh <your-user>@<device-address> (ssh ใช้ได้ใน PowerShell บน Windows ด้วย) จากนั้นรันคำสั่งด้านล่าง grep -i runssh เก็บไว้เฉพาะบรรทัดที่มีคำว่า RunSSH

    tailscale debug prefs | grep -i runssh

    ตอบกลับทันที

    "RunSSH": false,

    true หมายความว่าอุปกรณ์รัน server นี้ ถ้าไม่มีอะไรแสดงออกมา หรือ shell ขึ้นว่า tailscale: command not found ให้ใช้ผลจากข้อ 2 แทน เพราะแอป Mac และ Windows รัน server นี้ไม่ได้

    สิ่งที่ Tailworm ต้องใช้

    ผมไล่รายการสิ่งที่การโจมตีนี้ต้องใช้ และตรวจทีละข้อเทียบกับระบบของผมเอง

    อุปกรณ์ในบัญชี Tailscale เดียวกันรวมกันเป็น tailnet และ policy file ใน admin console เป็นตัวกำหนดว่าอุปกรณ์ไหนเข้าถึงอุปกรณ์ไหนได้

    Tailscale SSH คือ SSH server ที่อยู่ภายใน service ของ Tailscale เริ่มทำงานบนอุปกรณ์ด้วย tailscale set --ssh ตัวที่กำหนดว่าใครล็อกอินได้ และในฐานะบัญชีไหนในเครื่อง คือ policy file ไม่ใช่รหัสผ่านหรือ key ตามรายงาน เมื่อ session แบบนี้ทำ forwarding ของ Unix socket (จุดเชื่อมต่อที่มีลักษณะคล้ายไฟล์ ซึ่งโปรแกรมบนเครื่องเดียวกันใช้คุยกัน) service ของ Tailscale ทำงานนั้นด้วยสิทธิ์ของ root และช่องว่างระหว่างการตรวจกับการใช้ socket ทำให้ผ่านการตรวจที่มีไว้จำกัดมันไปได้ session ที่ได้รับอนุญาตให้เข้ามาในฐานะ user ธรรมดาจึงทำงานในฐานะ root ได้

    การโจมตีผ่าน SSH ต้องมีสามอย่าง:

    1. อุปกรณ์เป้าหมายที่รัน Tailscale SSH
    2. กฎใน policy file ที่ให้อุปกรณ์ของผู้โจมตีเปิด SSH session บนเป้าหมายนั้นได้ โดยอนุญาต forwarding ด้วย
    3. ผู้โจมตีที่ควบคุมอุปกรณ์ที่กฎนั้นครอบคลุมอยู่แล้ว

    Tailworm ไม่ได้ให้ข้อที่สาม ผู้โจมตีต้องหามาเอง: web application ที่มีช่องโหว่, package ที่เป็นอันตราย, phishing, รหัสผ่านที่ถูกขโมย นี่ไม่ใช่การโจมตีที่มาจาก internet สาธารณะ

    สิ่งที่ผมพบ

    สิ่งที่การโจมตีต้องใช้ สิ่งที่ผมพบ ตรวจที่ไหนบนระบบของคุณ
    Tailscale SSH รันอยู่บนเป้าหมาย ตอนที่ผมตรวจ ไม่ได้รันบนอุปกรณ์เครื่องใดของผมเลย หน้า Machines ใน admin console กรองด้วย property “Tailscale SSH” (ข้อ 2 ของการตรวจ)
    กฎใน policy ที่อนุญาต SSH session มี: กฎ default ซึ่งให้เข้าได้ทั้งแบบ root และบัญชีธรรมดา บนอุปกรณ์ของผมเอง หลังล็อกอินซ้ำ policy file (ข้อ 4 ของการตรวจ)
    foothold บนอุปกรณ์ที่กฎครอบคลุม เป็นไปได้ เหมือนเครือข่ายทั่วไป —
    ข้อค้นพบอื่น ๆ ใช้กับฟีเจอร์ที่เกี่ยวข้อง: app connector, tailscale serve, การเชื่อมต่อ relay ที่ client ทุกตัวทำ และ headscale (ตัวแทนแบบ open-source ของ control server แบบ hosted ของ Tailscale) admin console

    ดังนั้น สิ่งแรกที่การโจมตีต้องใช้จึงไม่มีอยู่ ส่วนสิ่งที่สอง คือกฎที่อนุญาต session มีอยู่แล้วโดย default เอกสารของ Tailscale ไม่ได้บอกว่ากฎ default อนุญาต forwarding หรือไม่ ซึ่งเป็นสิ่งที่การโจมตีผ่าน socket ต้องใช้

    เจาะลึก: วิธีตรวจแต่ละข้อแบบอื่น
    • ถ้าคุณใช้ OPNsense plugin Tailscale เก็บค่าตั้งไว้หลัง API การเรียกแบบอ่านอย่างเดียว GET /api/tailscale/settings/get คืนค่า "enableSSH":"0" เมื่อ SSH server ปิดอยู่ เอกสารของ Tailscale ระบุ SSH server เฉพาะ Linux และ macOS แต่ source code ของ Tailscale build server นี้สำหรับ FreeBSD และ OpenBSD ด้วย และ plugin ของ OPNsense มีสวิตช์สำหรับมัน
    • ทุกอุปกรณ์ ใน admin console: Machines → Filters → Property → Tailscale SSH ถ้าไม่มีอุปกรณ์ใดตรงเงื่อนไข แสดงว่าไม่มีเครื่องไหนรายงานว่ารัน server นี้
    • อุปกรณ์ Linux ตรวจจากภายในเครื่อง สวิตช์ --ssh ตั้งค่า preference ชื่อ RunSSH คำสั่ง tailscale debug prefs | grep -i runssh แสดง "RunSSH": false เมื่อ server ปิดอยู่ ส่วน tailscale set --ssh=false ใช้ปิดมัน
    • เวอร์ชัน รายงานทดสอบ 1.104.2 และไม่ได้พูดถึงเวอร์ชันก่อนหน้า การแก้ไขของ Tailscale อยู่ใน 1.104.4
    เจาะลึก: รายงานพบอะไร และ Tailscale ว่าอย่างไร
    • สิ่งที่ทดสอบ Tailscale 1.104.2 และ headscale 0.29.5 (ตัวแทนแบบ open-source ของ control server แบบ hosted ของ Tailscale) โดยไม่ได้ดัดแปลง ในแล็บ ระหว่างวันที่ 22 ถึง 24 ตุลาคม 2026
    • ข้อค้นพบที่ 1 ถึง 3: SSH socket forwarding การ forwarding ของ Unix socket ทั้งแบบ local และ remote (ssh -L และ ssh -R) ทำโดย service ของ Tailscale ที่รันด้วยสิทธิ์ root การตรวจ path ทำในจังหวะหนึ่ง แต่ใช้ socket ในอีกจังหวะหนึ่ง และ loop ที่วนเร็วภายใน session แย่งใช้ช่องว่างนั้นได้ก่อน (race) ในแล็บ วิธีนี้ได้ root ผ่าน Docker socket, แทนที่ socket ที่ root เป็นเจ้าของด้วย socket ของผู้โจมตีเอง และดักจับ key ที่ใช้ลงทะเบียนอุปกรณ์ใหม่ ซึ่งหลังจากนั้นพาเครื่องของผู้โจมตีเข้าร่วมเครือข่าย รายงานแสดงขั้นสุดท้ายนี้ตั้งแต่ต้นจนจบเฉพาะเมื่อ Tailnet Lock ปิดอยู่ เมื่อ Tailnet Lock เปิดอยู่ รายงานดักจับข้อมูลที่ต้องใช้เพื่อปิด lock ได้ แต่ไม่ได้นำไปใช้
    • ข้อค้นพบที่ 5: SSH ทำให้หน่วยความจำหมด session ที่ล็อกอินแล้วทำให้ service ของ Tailscale ที่รันด้วยสิทธิ์ root จองหน่วยความจำเพิ่มไปเรื่อย ๆ ได้
    • สิ่งที่ Tailscale บอก Tailscale บอกว่าปัญหาเหล่านี้ “require urgent attention” (ต้องได้รับความสนใจโดยเร่งด่วน) และช่องโหว่ SSH “primarily concerned how permissions were enforced” (เกี่ยวกับวิธีบังคับใช้สิทธิ์เป็นหลัก) หลังจากที่การเชื่อมต่อได้รับอนุญาตแล้ว Tailscale โต้แย้งว่าปัญหาเหล่านี้ถือเป็น worm ไม่ได้ และเรียกสิ่งนี้ว่าการเคลื่อนที่ไปยังเครื่องอื่น (lateral movement) ที่จำกัดอยู่แค่การเชื่อมต่อที่ policy อนุญาตอยู่แล้ว
    • Wormability ในแล็บ อุปกรณ์ที่ถูกเจาะหนึ่งเครื่องเข้าถึงทุกอุปกรณ์ที่ policy อนุญาต ใช้เวลาไม่ถึงหนึ่งวินาทีต่อขั้น รายงานระบุมาตรการหนึ่งที่หยุดการแพร่ได้ คือกฎที่เขียนแบบต้นทางหนึ่งไปปลายทางหนึ่ง key ที่เก็บในฮาร์ดแวร์ (TPM หรือ Secure Enclave) ป้องกันไม่ให้ตัวตนของอุปกรณ์ที่ถูกขโมยใช้ได้ต่อไป
    • ข้อค้นพบอื่น ๆ บางข้อ การออกแบบ app connector ที่ไม่ตรวจว่า traffic กำลังไปที่ไหน (Tailscale บอกว่าเวอร์ชันนี้ คือ Conn25 ยังไม่ได้เผยแพร่); tailscale serve ที่ forward ไปยัง control socket ของ service เอง; หน่วยความจำหมดใน relay client (ผมไม่พบ bulletin สำหรับข้อนี้); และ denial of service ต่อ headscale
    • Bulletin Tailscale เผยแพร่สี่ฉบับ ลงวันที่ 26 ตุลาคม ทั้งหมดแก้แล้วใน 1.104.4: TS-2026-014 (SSH socket forwarding ตอนนี้ Tailscale ทำ forwarding ในฐานะ user ที่ล็อกอิน ไม่ใช่ในฐานะ root), TS-2026-015 (SSH ทำให้หน่วยความจำหมด), TS-2026-016 (tailscale serve เข้าถึง socket ที่มีสิทธิ์สูง) และ TS-2026-017 (Serve ผ่าน HTTP/2 อาจส่งค่า Tailscale-App-Capabilities ของ mount หนึ่งไปให้อีก mount หนึ่งบน node เดียวกัน) ระหว่างที่อุปกรณ์ยังไม่ได้อัปเดต มาตรการบรรเทาของ Tailscale สำหรับช่องโหว่ด้าน forwarding คือ TS_SSH_DISABLE_FORWARDING=1 ใน environment ของ service Tailscale ส่วนมาตรการชั่วคราวใต้หัวข้อ “จากนั้นเปลี่ยนสิ่งที่คุณพบ” ด้านล่างแสดงวิธีทำ
    • การแก้ไขก่อนหน้านี้ในส่วนเดียวกัน bulletin ของเดือนมิถุนายนและกรกฎาคมครอบคลุมเรื่อง SSH socket forwarding ที่ไม่เคารพสิทธิ์ของ symlink (TS-2026-004, 3 มิถุนายน) และวิธีเลี่ยง autogroup:nonroot (TS-2026-009, 13 กรกฎาคม) ไว้แล้ว ทั้งสองข้อแก้แล้วใน 1.98.9
    • Forwarding กับกฎ default SSH server ของ Tailscale จะทำ forwarding เฉพาะเมื่อกฎที่ตรงกันมีสิทธิ์ forwarding ที่ได้มาจาก coordination server ของ Tailscale (allowLocalPortForwarding และ allowRemotePortForwarding ใน source code) เอกสารสาธารณะของ Tailscale ไม่ได้บอกว่า policy ให้สิทธิ์นี้อย่างไร หรือกฎ default ให้สิทธิ์นี้หรือไม่ รายงานบอกให้ตั้ง field ของ forwarding รายกฎเป็น false บน hosted service ของ Tailscale แต่ไม่ได้ระบุชื่อ field เหล่านั้น ผมหา field เหล่านั้นในเอกสาร policy ของ Tailscale ไม่พบ Bulletin TS-2026-014 ระบุว่าปัญหานี้กระทบผู้ใช้ที่ “allow local or remote forwarding in their access policies” (อนุญาต local หรือ remote forwarding ใน access policy ของตน)
    • การเปิดเผยข้อมูล Tailscale บอกว่าได้รับรายงานในเช้าวันเสาร์ที่ 24 ตุลาคม และรายงานถูกเผยแพร่สองชั่วโมงหลังจากนั้น ขณะนั้น Tailscale กำลังสืบสวนปัญหาที่เกี่ยวข้องอยู่แล้ว The Hacker News รายงานว่านักวิจัยอธิบายเรื่องนี้ว่า “reported but not coordinated” (แจ้งแล้วแต่ไม่ได้ประสานงาน)

    Policy ที่ผมไม่เคยเขียน

    เมื่อคุณสร้าง tailnet Tailscale จะให้ policy แบบ default มาด้วย เอกสารของ Tailscale อธิบายไว้ว่า ทุกอุปกรณ์เข้าถึงอุปกรณ์อื่นได้ทุกเครื่องทุก port (ข้างล่างผมเรียกส่วนนี้ว่า allow-all) และผู้ใช้ทุกคนเปิด session ของ Tailscale SSH บนอุปกรณ์ของตัวเองได้ใน check mode ในฐานะ root หรือ user ธรรมดา ส่วน SSH มีหน้าตาแบบนี้:

    "ssh": [
      {
        "action": "check",
        "src":    ["autogroup:member"],
        "dst":    ["autogroup:self"],
        "users":  ["autogroup:nonroot", "root"]
      }
    ]

    ผู้ใช้คนใดก็ตามของ tailnet (autogroup:member) เชื่อมต่อกับอุปกรณ์ที่ผู้ใช้คนนั้นเป็นเจ้าของ (autogroup:self ไม่รวมอุปกรณ์ที่มี tag) ได้ในฐานะบัญชีในเครื่องบัญชีใดก็ได้ ยกเว้น root (autogroup:nonroot) หรือในฐานะ root ก็ได้ ของผมมีกฎนี้ และมี allow-all ร่วมด้วย หน้า policy file ของ Tailscale อธิบายกฎ ssh แบบ default ด้วย autogroup:nonroot และไม่ได้พูดถึง root ส่วนหน้า SSH และ policy ตัวอย่างของ Tailscale มี root ดังที่แสดงไว้ข้างบน

    กฎนี้แยกผมออกจากคนที่ยึดอุปกรณ์เครื่องหนึ่งของผมไม่ได้ สำหรับ Tailscale การเชื่อมต่อจากอุปกรณ์ของผมเครื่องใดก็คือผม ถ้าอุปกรณ์ Linux เครื่องหนึ่งใน tailnet รัน tailscale set --ssh คนที่ยึดอุปกรณ์อีกเครื่องของผมได้ก็เปิด root session บนเครื่องนั้นได้ นั่นคือกฎที่ทำงานตามการออกแบบ ไม่ใช่ช่องโหว่ Check mode ขอให้ผมล็อกอินใน browser และการอนุมัติหนึ่งครั้งอาจมีผลอยู่ 12 ชั่วโมง (ดูข้างล่าง)

    Check mode ขอให้ล็อกอินใหม่ใน browser ก่อนที่ session จะเริ่ม ด้วย check period แบบ default เอกสารของ Tailscale ระบุว่าการล็อกอินใน check mode หนึ่งครั้งทำให้คุณเข้าเครื่องนั้นและอุปกรณ์เครื่องอื่นใน tailnet ได้เป็นเวลา 12 ชั่วโมงโดยไม่ต้องล็อกอินอีก เอกสารไม่ได้บอกว่าครอบคลุม session ที่เปิดจากอุปกรณ์อีกเครื่องด้วยหรือไม่ รายงานอธิบายว่าผู้โจมตีที่อยู่บนอุปกรณ์เครื่องหนึ่งรอให้คุณอนุมัติครั้งถัดไป หรือกระตุ้นให้คุณอนุมัติได้ ดังนั้น check mode ทำให้ช้าลงแต่ไม่ได้หยุดการโจมตี

    Tailworm ต้องอาศัย socket forwarding เพื่อเปลี่ยนบัญชีธรรมดาให้เป็น root กฎ default ไม่ต้องใช้ socket forwarding เลย ใช้เพียงการอนุมัติใน check mode นี่เป็นพฤติกรรมที่เอกสารระบุไว้ ไม่ใช่ช่องโหว่ การอัปเดตเป็น 1.104.4 ก็ไม่ได้เปลี่ยนเรื่องนี้ session ที่ได้รับอนุญาตให้เข้ามาในฐานะ root ก็คือ root ตามการออกแบบ

    สิ่งที่ผมเปลี่ยน

    Policy ฉบับใหม่ไม่มีส่วน ssh เอกสารของ Tailscale ระบุว่าการลบกฎ SSH ทำให้ Tailscale SSH ถูกปิดทั้ง tailnet grant ใช้แทนที่ allow-all ได้ โดยให้เฉพาะสิ่งที่จำเป็น เช่น:

    1. Exit node ถ้าคุณใช้: สิทธิ์เข้าถึง autogroup:internet
    2. อุปกรณ์ไม่กี่เครื่องที่คุณต้องดูแล และไม่มีอะไรเกินนั้น ให้ grant นี้แคบไว้ อุปกรณ์ใดที่ grant ครอบคลุมจะยังเข้าถึงได้

    การแทนที่ allow-all มีต้นทุน: สิ่งที่พึ่งพาการที่อุปกรณ์เข้าถึงกันได้จะหยุดทำงาน เช่น การแชร์ไฟล์, media server หรือ subnet route ให้ grant แยกของแต่ละอย่างก่อน

    จากนั้นเป็น test policy file ใส่ test ได้ คือข้อความอย่างเช่น “ผู้ใช้คนนี้เข้าถึง port นี้ได้” ที่ Tailscale ตรวจทุกครั้งที่ไฟล์เปลี่ยน ถ้า test ข้อใดไม่ผ่าน Tailscale จะไม่รับการเปลี่ยนแปลงนั้น test ระบุได้ว่าอะไรต้องใช้ได้และอะไรต้องถูกปฏิเสธ เช่น SSH, การแชร์ไฟล์ และ remote desktop (port 22, 445 และ 3389) ถูกปฏิเสธบนอุปกรณ์ที่ไม่ต้องใช้

    เจาะลึก: ตัวอย่าง policy

    นี่เป็นเพียงรูปแบบ ไม่ใช่แม่แบบ มันตัดทุกอย่างยกเว้น exit node ถ้านำไปวางตามที่เป็นอยู่ มันจะตัดคุณออกจาก NAS หรือ media server ของคุณเอง address และอีเมลเป็นค่าตัวอย่างแทนของจริง

    {
      "grants": [
        // 1. Use exit nodes.
        {"src": ["autogroup:member"], "dst": ["autogroup:internet"], "ip": ["*"]},
    
        // 2. Add a grant for each device you must reach, and no more.
    
        // Nothing else: other devices accept no inbound tailnet traffic.
      ],
    
      // An empty "acls" list: Tailscale's documentation gives this form for deny-all;
      // omitting the section is documented as allow-all.
      "acls": [],
    
      // No "ssh" section: no Tailscale SSH session is allowed anywhere.
    
      "tests": [
        {
          "src":    "you@example.com",
          // "accept": ["100.x.y.2:445"],  one line like this for each thing that must work.
          "deny":   ["100.x.y.3:22", "100.x.y.3:445", "100.x.y.3:3389"], // a device that must refuse these
        },
      ],
    }

    grant สำหรับ NAS ที่ควรให้บริการไฟล์แชร์แก่ผู้ใช้ของ tailnet ของคุณ และไม่ทำอย่างอื่น จะมีหน้าตาแบบนี้ (port เป็นตัวอย่าง และให้เพิ่มรายการ tcp: หนึ่งรายการสำหรับแต่ละบริการอื่นที่ NAS ต้องให้บริการ และ nas เป็นชื่อที่คุณกำหนดเองในส่วน hosts ของ policy เช่น "hosts": {"nas": "100.x.y.2"}):

    {"src": ["autogroup:member"], "dst": ["nas"], "ip": ["tcp:445"]},

    หมายเหตุ:

    • เฉพาะอุปกรณ์ที่มีสิทธิ์เข้าถึง autogroup:internet เท่านั้นที่ใช้ exit node ได้ grant ข้อ 1 จึงเขียนแบบนั้น
    • test ตรวจกฎ ไม่ได้ตรวจเครือข่าย test ที่ผ่านไม่ได้พิสูจน์ว่าอุปกรณ์ตอบสนอง
    • ทำไมต้องคง "acls": [] ไว้ เอกสารของ Tailscale ระบุว่าการไม่ใส่ส่วน acls เทียบเท่ากับ policy allow-all แบบ default และตัวอย่าง deny-all ของเอกสารคือ "acls": [] เอกสารไม่ได้บอกว่าการไม่ใส่หมายถึงอะไรใน policy ที่มี grant ให้คงรายการว่างไว้ แล้วให้ test เป็นตัวตัดสิน: test แบบ deny สำหรับ port ที่ allow-all จะเปิดให้ จะไม่ผ่านตราบที่ allow-all ยังมีผลอยู่
    • เก็บสำเนา policy เดิมไว้ก่อนบันทึก (ข้อ 1 ของ “ถ้าคุณไม่ใช้ Tailscale SSH: ปิดให้หมดทุกเครื่อง” ด้านล่างทำสิ่งนี้) Tailscale ยังให้ย้อนการเปลี่ยนแปลงได้จากหน้า Configuration logs
    เจาะลึก: วิธีที่ผมจะใช้อีก

    ไล่รายการสิ่งที่การโจมตีต้องใช้ ตรวจทีละข้อบนอุปกรณ์ของคุณเองและจดวิธีตรวจไว้ มองหาสิ่งที่ผิดแม้ในจุดที่การโจมตีไม่ได้ใช้ แล้วแบ่งที่เหลือเป็นสิ่งที่ต้องเปลี่ยน สิ่งที่ต้องเฝ้าดู และความเสี่ยงที่จะยอมรับ

    จากนั้นเปลี่ยนสิ่งที่คุณพบ

    ถ้าคุณไม่ใช้ Tailscale SSH: ปิดให้หมดทุกเครื่อง

    ก่อนเริ่ม: ขั้นตอนนี้เปลี่ยน policy ของคุณเพื่อไม่ให้อุปกรณ์ใดรับ Tailscale SSH session อย่าทำถ้า Tailscale SSH เป็นทางเดียวที่คุณเข้าเครื่องใดเครื่องหนึ่งได้ ใช้เวลาประมาณ 3 นาที ถ้าจะย้อนกลับ ให้วางสำเนาที่เก็บไว้กลับเข้าไป (ข้อ 1) แล้วบันทึก หรือย้อนการเปลี่ยนแปลงจากหน้า Configuration logs

    1. เก็บสำเนา policy ใน JSON editor คลิกในข้อความ แล้วกด Ctrl+A (Cmd+A บน Mac) จากนั้นกด Ctrl+C (Cmd+C) เปิด Notepad (เมนู Start → พิมพ์ notepad → Enter) หรือ TextEdit บน Mac (เลือก Format → Make Plain Text ก่อน) วางด้วย Ctrl+V (Cmd+V) และบันทึกไฟล์เป็น policy-backup.json ในโฟลเดอร์ Documents ไฟล์ควรมี policy ทั้งหมด โดยขึ้นต้นด้วย {
    2. ลบส่วน ssh กลับมาที่ console เลือกทุกอย่างตั้งแต่ "ssh": [ ลงไปถึง ] ที่ตรงแนวกับมันด้านล่าง (ไม่ใช่ ] ที่อยู่ในกฎ) รวมถึง comma ที่ตามมาถ้ามี แล้วกด Delete policy file ยอมให้มี comma เกินได้ ส่วนอื่นให้คงไว้ตามเดิม
    3. บันทึก คลิก Save Tailscale ตรวจ policy และ test ที่อยู่ในนั้นก่อนจะใช้การเปลี่ยนแปลง คุณควรเห็น console ยืนยันว่าบันทึกแล้ว ถ้ามีรายงาน syntax error แสดงว่ามี comma หรือวงเล็บอยู่ผิดที่ ให้วางสำเนาที่เก็บไว้กลับเข้าไป แล้วทำซ้ำตั้งแต่ข้อ 2 ถ้ามันระบุรายการ sshTests ให้ลบ test นั้นด้วย
    4. ตรวจ โหลดหน้าใหม่ กด Ctrl+F (Cmd+F) แล้วค้นหา "ssh" ไม่ควรพบ อุปกรณ์ที่เคยเปิดใช้ไว้เองจะยังรัน server ต่อไปจนกว่าคุณจะรัน tailscale set --ssh=false บนเครื่องนั้น

    ถ้าคุณใช้ Tailscale SSH: อัปเดต แล้วจำกัดกฎให้แคบลง

    ก่อนเริ่ม: การอัปเดตทำให้ Tailscale SSH session ที่เปิดอยู่ทุกอันบนเครื่องนั้นสิ้นสุดลง อย่ารันการอัปเดตจาก Tailscale SSH session ให้เข้าเครื่องด้วยทางอื่น: ใช้คีย์บอร์ดและจอที่ตัวเครื่อง หรือล็อกอินด้วย ssh ธรรมดาใน local network ของคุณ การล็อกอินด้วย ssh ไปยัง address Tailscale ของอุปกรณ์ (100.…) ก็หลุดเช่นกันเมื่อ Tailscale restart และการหลุดกลางทางระหว่างอัปเดตอาจทำให้การติดตั้งสะดุด คำสั่งด้านล่างใช้กับ Debian, Ubuntu และ Raspberry Pi OS ที่ใช้ package repository ของ Tailscale เอง สำหรับระบบอื่น ดู หน้าว่าด้วยการอัปเดต ของ Tailscale

    1. ล็อกอินเข้าเครื่องด้วยทางอื่น แล้วเปิด terminal บนเครื่องนั้น คุณควรเห็น shell prompt ของเครื่อง
    2. ดูว่าเครื่องรันเวอร์ชันอะไร
    tailscale version

    บรรทัดแรกคือเลขเวอร์ชัน ถ้าเป็น 1.104.4 หรือใหม่กว่า แสดงว่ามีการแก้ไขแล้ว ถ้าต่ำกว่านั้นต้องอัปเดต

    1. อัปเดต sudo รันคำสั่งในฐานะผู้ดูแลระบบ และอาจขอรหัสผ่านของคุณ ขณะพิมพ์จะไม่มีอะไรแสดงบนจอ ให้พิมพ์ให้ครบแล้วกด Enter
    sudo apt update
    sudo apt install --only-upgrade tailscale

    แต่ละคำสั่งใช้เวลาไม่ถึงนาที Tailscale restart ไม่กี่วินาที ถ้าการอัปเดตหยุดกลางคัน คำสั่ง sudo dpkg --configure -a จะทำต่อให้เสร็จ ถ้า apt ขึ้นว่า tailscale เป็นเวอร์ชันล่าสุดอยู่แล้ว แสดงว่าอุปกรณ์มีการแก้ไขแล้ว หรือไม่ได้รับ Tailscale มาจาก repository ของ Tailscale

    1. ตรวจอีกครั้ง ด้วย tailscale version บรรทัดแรกควรเป็น 1.104.4 หรือใหม่กว่า
    2. จำกัดกฎให้แคบลง ถ้าคุณล็อกอินเป็น root บน host บางเครื่อง เช่น Proxmox server หรือบน host ที่ไม่มีบัญชีอื่นใดใช้ sudo ได้ การทำขั้นนี้จะตัดการเข้าถึงนั้น ให้ตรวจก่อน เก็บสำเนา policy (ข้อ 1 ของ “ถ้าคุณไม่ใช้ Tailscale SSH: ปิดให้หมดทุกเครื่อง”) ก่อนแก้ จากนั้นใน console ไปที่ Access controls, JSON editor หาบรรทัด "users" ของกฎ ssh และลบ , "root" ออกจากบรรทัดนั้น:
    "users":  ["autogroup:nonroot", "root"]
    "users":  ["autogroup:nonroot"]

    คลิก Save กฎนี้จะไม่ให้ root session อีกต่อไป ให้ใช้ sudo หลังล็อกอิน บน host ที่บัญชีของคุณใช้ sudo ได้โดยไม่ต้องใส่รหัสผ่าน ขั้นนี้ทำให้ผู้บุกรุกช้าลงแต่หยุดไม่ได้ ขั้นนี้ไม่ได้ใช้แทนการอัปเดต: bulletin เดือนกรกฎาคม TS-2026-009 เป็นวิธีเลี่ยง autogroup:nonroot นอกจากนี้ให้จำกัด src และ dst เฉพาะคนและอุปกรณ์ที่ต้องใช้ SSH

    มาตรการชั่วคราว: ปิด SSH forwarding บนอุปกรณ์ที่ยังอัปเดตไม่ได้

    ใช้ขั้นตอนนี้เฉพาะเมื่อ package source ที่คุณใช้ยังไม่มี 1.104.4 หรือใหม่กว่า มาตรการบรรเทาของ Tailscale สำหรับช่องโหว่ด้าน forwarding คือการตั้งค่า TS_SSH_DISABLE_FORWARDING=1 ใน environment ของ service Tailscale บนการติดตั้งแบบ Debian service อ่านไฟล์ /etc/default/tailscaled (ไฟล์ tailscaled.service ใน source ของ Tailscale ระบุไฟล์นี้เป็น EnvironmentFile) ผมทดสอบคำสั่งด้านล่างกับสำเนาของไฟล์นั้น ไม่ได้ทดสอบกับ service Tailscale ที่กำลังรันอยู่ การ restart ทำให้ Tailscale SSH session ที่เปิดอยู่สิ้นสุดลง จึงให้รันคำสั่งเหล่านี้จากทางเข้าอื่น คำสั่งเหล่านี้ถือว่าระบบใช้ systemd

    1. สำรองไฟล์ ถ้าคำสั่งขึ้นว่า No such file or directory แสดงว่าอุปกรณ์นี้เก็บค่าตั้งไว้ที่อื่น ให้หยุดและอ่านหน้าของ Tailscale สำหรับการติดตั้งแบบของคุณ รันครั้งเดียวพอ: การรันครั้งที่สองจะเขียนทับไฟล์สำรองด้วยไฟล์ที่แก้แล้ว
    sudo cp /etc/default/tailscaled /etc/default/tailscaled.bak
    1. เพิ่มค่าตั้ง บรรทัดที่เพิ่มเริ่มด้วยบรรทัดว่าง เพื่อไม่ให้ไปต่อกับบรรทัดสุดท้ายของไฟล์
    printf '\nTS_SSH_DISABLE_FORWARDING=1\n' | sudo tee -a /etc/default/tailscaled

    คำสั่งแสดงสิ่งที่เพิ่ม รันครั้งเดียวพอ: การรันครั้งที่สองจะทำให้ในไฟล์มีบรรทัดนี้สองบรรทัด

    1. Restart service
    sudo systemctl restart tailscaled
    1. ตรวจว่า service ที่กำลังรันได้ค่านี้
    sudo cat /proc/$(systemctl show -p MainPID --value tailscaled)/environ | tr '\0' '\n' | grep TS_SSH
    TS_SSH_DISABLE_FORWARDING=1

    ถ้าไม่มี output แสดงว่า service ไม่ได้รับค่าตั้งนี้: ให้ตรวจว่าบรรทัดนี้อยู่ในไฟล์ด้วย grep TS_SSH /etc/default/tailscaled แล้วทำข้อ 3 ซ้ำ /proc/0/environ: No such file or directory หมายความว่า service ไม่ได้รันอยู่

    1. ถ้าจะย้อนกลับ ให้ลบบรรทัดนั้นออกและ restart ทำเช่นนี้ด้วยเมื่ออุปกรณ์รัน 1.104.4 หรือใหม่กว่าแล้ว เพราะค่าตั้งนี้เป็นมาตรการชั่วคราว การลบบรรทัดทำได้อย่างปลอดภัยแม้การอัปเดต package จะแทนที่ไฟล์ไปแล้วหลังข้อ 1 ไฟล์สำรองยังอยู่เป็นบันทึก การอัปเดตอาจถามว่าจะเก็บไฟล์ที่คุณแก้ไว้หรือไม่:
    sudo sed -i '/^TS_SSH_DISABLE_FORWARDING=1$/d' /etc/default/tailscaled
    sudo systemctl restart tailscaled

    ถ้า sed ขึ้นว่าอ่านไฟล์ไม่ได้ แสดงว่าไม่มีอะไรให้ย้อนกลับบนอุปกรณ์นี้

    สำหรับทุกคน

    1. ลบอุปกรณ์ที่คุณไม่ได้ดูแลแล้ว ก่อนที่อุปกรณ์นั้นจะหลุดจากมือคุณ อย่าลบอุปกรณ์ที่คุณเข้าถึงได้ทาง Tailscale เท่านั้น เพราะคุณต้องไปอยู่ที่เครื่องนั้นเพื่อเพิ่มกลับ ใน console เปิด Machines หาอุปกรณ์ตามชื่อในช่องค้นหา เปิดเมนูข้างอุปกรณ์ เลือก Remove แล้วเลือก Remove machine ในหน้าต่างยืนยัน อุปกรณ์จะหายไปจากรายการ ถ้าลบผิดเครื่อง ให้ล็อกอินอุปกรณ์นั้นอีกครั้งเพื่อเพิ่มกลับ ถ้า tailnet ของคุณกำหนดให้ต้องอนุมัติอุปกรณ์ ผู้ดูแล (admin) ต้องเป็นคนอนุมัติ
    2. ดู allow-all อีกครั้ง ค้นหา "acls" และ "grants" ใน Access controls กฎที่ต้นทางเป็น * และปลายทางเป็น * หรือ *:* คือ allow-all: ทุกอุปกรณ์เข้าถึงอุปกรณ์อื่นได้ทุกเครื่องทุก port ขั้นตอนการแทนที่อยู่ถัดไป
    แทนที่ allow-all ทีละขั้น

    ก่อนเริ่ม: ขั้นตอนนี้เปลี่ยน policy ของคุณและอาจตัดอุปกรณ์ออกจากกัน ให้ทำเมื่อคุณทดสอบแต่ละ service ได้หลังจากนั้น ใช้เวลา 15 ถึง 30 นาที ถ้าจะย้อนกลับ ให้วางสำเนา policy ที่เก็บไว้กลับเข้าไป (ข้อ 1 ของ “ถ้าคุณไม่ใช้ Tailscale SSH: ปิดให้หมดทุกเครื่อง”) แล้วบันทึก หรือย้อนการเปลี่ยนแปลงจากหน้า Configuration logs ถ้าโทรศัพท์หรือแล็ปท็อปของคุณใช้ exit node ให้ทดสอบการใช้ internet ของเครื่องนั้นหลังบันทึกแต่ละครั้ง: grant ของ exit node ที่ผิดจะทำให้เครื่องนั้นใช้ internet ไม่ได้

    1. จดว่าอุปกรณ์ของคุณต้องใช้อะไรจากกัน: ไฟล์แชร์, media server, subnet route, เครื่องพิมพ์ ใช้กระดาษหรือไฟล์ข้อความ
    2. เก็บสำเนา policy ตามที่อธิบายไว้ข้างบน
    3. เพิ่ม grant หนึ่งรายการต่อความต้องการหนึ่งอย่าง ในส่วน "grants" (ถ้ายังไม่มีส่วนนี้ให้เพิ่มเข้าไป กฎ allow-all อยู่ในส่วน "acls") เหมือนตัวอย่าง NAS ใน “ตัวอย่าง policy” ก่อนหน้านี้ ใช้ address Tailscale ของ NAS (หน้า Machines แสดงไว้) แทน nas ถ้าคุณยังไม่ได้กำหนดชื่อนั้น เพิ่ม grant สำหรับ exit node ถ้าคุณใช้
    4. เพิ่ม test สำหรับสิ่งที่ต้องใช้ได้ ตามตัวอย่างเดียวกัน คลิก Save ถ้า test ไม่ผ่าน Tailscale จะไม่รับการเปลี่ยนแปลงและระบุชื่อ test นั้น
    5. ลบกฎ allow-all แต่คงส่วน "acls" ไว้เป็น "acls": [] เอกสารของ Tailscale ใช้รูปแบบนั้นสำหรับ deny-all และระบุว่าการไม่ใส่ส่วนนี้เทียบเท่า allow-all เพิ่ม test สำหรับสิ่งที่ต้องใช้ไม่ได้ (เช่น port 22, 445 และ 3389 บนอุปกรณ์ที่ไม่ควรรับ) แล้วคลิก Save อีกครั้ง test เหล่านั้นจะไม่ผ่านตราบที่ allow-all ยังอยู่ จึงเพิ่มในตอนนี้
    6. ทดสอบแต่ละ service จากอุปกรณ์ที่ใช้มัน ถ้าอันไหนไม่ทำงาน ให้เพิ่ม grant ของมัน หรือวางสำเนาที่เก็บไว้กลับเข้าไป

    สถานะ

    เวอร์ชัน 1.104.4 ถูก tag เมื่อช่วงดึกวันที่ 27 ตุลาคม 2026 (UTC) changelog ของ Tailscale ลงวันที่ 28 ตุลาคม เวอร์ชัน 1.104.5 ซึ่งออกเมื่อวันที่ 2 พฤศจิกายน 2026 แก้ปัญหา Tailscale SSH connection ค้าง และการค้างตอน restart และทำให้ session แบบ check-mode ไม่ถูกตัดการเชื่อมต่อเมื่อการอนุมัติหมดอายุ ให้อัปเดตเป็นรุ่นปัจจุบัน เมื่อวันที่ 10 พฤศจิกายน 2026 หน้า bulletin (TS-2026-014 ถึง TS-2026-017 ลงวันที่ 26 ตุลาคม) ไม่แสดงหมายเลข CVE

    วิธีทำงานนี้

    ผมตรวจด้วย Claude ซึ่งเป็นโมเดล AI ของ Anthropic Claude ร่าง policy ที่ใช้แทนและ test ของมัน รวมทั้งบทความนี้ การที่ Claude ตรวจร่างแรกของผมทำให้เห็นว่ากฎ default อนุญาต root อยู่แล้ว จากนั้น Claude ตรวจเรื่องนี้เทียบกับเอกสารของ Tailscale (open-source code ไม่มี policy แบบ default อยู่)

    ศัพท์
    • Tailscale: mesh VPN ที่สร้างบน WireGuard มี hosted service ที่จัดการการล็อกอินและ key
    • Tailnet: กลุ่มอุปกรณ์ในบัญชี Tailscale เดียวกัน
    • Policy file: กฎการเข้าถึงของ tailnet แก้ใน admin console Grants กำหนดว่าอุปกรณ์ไหนเข้าถึงอุปกรณ์ไหนได้ ส่วน ssh กำหนดว่าใครเปิด Tailscale SSH session ได้ tests ตรวจกฎทุกครั้งที่กฎเปลี่ยน
    • Allow-all: กฎ acls แบบ default ที่ให้ทุกอุปกรณ์เข้าถึงอุปกรณ์อื่นได้ทุกเครื่องทุก port
    • Tag: ป้ายชื่ออย่าง tag:server ที่ให้อุปกรณ์มีตัวตนของตัวเองแทนที่จะเป็นตัวตนของผู้ใช้ อุปกรณ์ที่มี tag ไม่ถูกครอบคลุมโดย autogroup:self
    • autogroup:member / self / nonroot: ผู้ใช้คนใดก็ได้ของ tailnet; อุปกรณ์ที่ผู้ใช้เป็นเจ้าของ (ไม่รวมอุปกรณ์ที่มี tag); บัญชีในเครื่องบัญชีใดก็ได้ยกเว้น root
    • Tailscale SSH: SSH server ที่ติดมากับ service ของ Tailscale ซึ่งตัดสินว่าใครล็อกอินได้จาก policy file แทนรหัสผ่านหรือ key
    • Check mode: action ของกฎ ssh ที่ให้ผู้ใช้ล็อกอินใหม่ก่อนที่ session จะเริ่ม การล็อกอินหนึ่งครั้งมีผล 12 ชั่วโมงโดย default
    • Exit node: อุปกรณ์ใน tailnet ที่อุปกรณ์อื่นส่ง traffic ออก internet ผ่านได้
    • root: บัญชีผู้ดูแลระบบบน Linux และ macOS ซึ่งทำอะไรก็ได้บนเครื่อง
    • Subnet route: อุปกรณ์ที่ให้ tailnet เข้าถึง local network ทั้งวงที่อยู่หลังมัน
    • Unix socket: จุดเชื่อมต่อที่มีลักษณะคล้ายไฟล์ ซึ่งโปรแกรมบนเครื่องเดียวกันใช้คุยกัน เช่น control socket ของ Docker
    • Port forwarding (ใน SSH): การส่งการเชื่อมต่ออื่น เช่นการเชื่อมต่อไปยัง socket ผ่าน SSH session
    • Tailnet Lock: ฟีเจอร์ของ Tailscale ที่กำหนดให้อุปกรณ์ที่เชื่อถือได้ต้องเซ็นรับรองอุปกรณ์ใหม่ทุกเครื่องก่อนที่จะเข้าร่วมได้
    • Foothold: อุปกรณ์ที่ผู้โจมตีควบคุมอยู่แล้ว และใช้เป็นจุดเริ่มโจมตีต่อ
    • headscale: ตัวแทนแบบ open-source ของ control server แบบ hosted ของ Tailscale
    • CVE: หมายเลขสาธารณะที่ระบุช่องโหว่เฉพาะรายการ
    • sudo: คำนำหน้าคำสั่งที่รันคำสั่งในฐานะผู้ดูแลระบบ อาจขอรหัสผ่านของคุณ
    • ssh: คำสั่งที่ใช้ล็อกอินเข้าเครื่องอื่น

    แหล่งอ้างอิง

  • The paste is still in its box

    The paste is still in its box

    Choose a language: English, Hindi, Telugu or Thai.

    On 15 October 2026 I had two fixes for one problem on my desk: a 4 g tube of ARCTIC MX-7 thermal paste and a 120 mm Noctua fan. The problem was my router, a fanless mini PC running OPNsense in a closed plywood cabinet. The day before, its CPU had touched 91 °C.

    The advice I found online was to open the case and replace the paste. I fitted the fan first, because it needed no screwdriver. Before I did, I decided which result would send me back for the paste.

    I never needed it. The router had been logging its own temperature all along. Between 16 September and the evening of 15 October, no hour averaged below 60 °C. In the four days after the fan went on, no hour averaged above 49 °C. The paste is still in its box.

    I did this work with Claude, Anthropic’s AI model, which could read my router through my own browser session. I chose the parts, fitted the fan and set the rule. Claude pulled the temperature records and did the arithmetic, and on 28 October it read back the router’s hourly data for this post.

    The box and the cabinet

    The router is a six-port fanless mini PC sold under the name “Shenzhen Weibu”. Inside is an Intel Pentium Gold 8505: one performance core and four efficient cores, six threads, 15 W base power and up to 55 W in turbo, according to Intel’s specification page. It has 20 GB of RAM and six Intel I226-V 2.5 GbE ports, and runs OPNsense 26.7. The case is the heatsink. Its top is a block of fins.

    It sits in a closed plywood cabinet with other network gear. A slotted grille in the cabinet’s side panel is the only planned way out for warm air.

    The router before the fan, seen from its USB end: a black case whose top is a block of fins, beside the slotted grille in the cabinet's side panel

    Was 91 °C dangerous? Not by Intel’s numbers. The same page lists the chip’s maximum junction temperature (TJUNCTION) as 100 °C, and a processor at that limit slows itself down rather than failing. The 91 °C was also only the highest sampled reading; the router reads the sensor once a minute, so the peaks in between went unrecorded. Even so, the heat had become a reason to look at a new router. The hourly average sat near 70 °C day and night, and the SSD, the memory and the network chips share the same hot case. Heat shortens the life of electronics in general, though I measured neither that nor the SSD’s temperature on this box.

    Why the fan went first

    A repaste is the usual advice for a hot mini PC, and it may well have helped. It would also have meant:

    • a configuration backup first;
    • 99 per cent isopropyl alcohol and lint-free wipes;
    • 45 to 60 minutes with the network offline;
    • opening a sealed case whose screws and thermal pads I had never seen.

    A fan lying on the fins needed none of that, and could come off in a second. It has costs of its own. It gives up what a fanless box is for: no noise, no dust drawn in, no moving part to wear out.

    So I set the rule before fitting it: repaste only if the overnight readings still reach the 80s with the fan in place.

    The fan

    I chose a Noctua NF-F12 5V PWM. Noctua’s specification gives 120 mm, 5 V, up to 1,500 rpm, 0.65 W typical and 22.4 dB(A) at full speed, with a USB power cable in the box. Mine plugs into one of the router’s own USB ports. Powered from USB, the fan gets no speed signal, and Noctua’s own guide says a PWM fan with no signal runs at full speed. Noctua marks it “5V PWM version, not for use in PCs”: a PC’s 12 V fan header is the wrong supply for it.

    On my router, the 120 mm fan covers most of the top. Pick a fan about the size of the router’s top. Noctua also sells 5 V versions in smaller sizes, such as the 80 mm NF-A8 5V PWM. A cheaper 5 V USB fan would also move air; I have not tried one.

    I fitted it at about 17:30 on 15 October. It lies flat on the top fins, not screwed down, blowing down into them. Reading a photo, Claude first had the airflow the wrong way round; I checked the arrow moulded into the frame. Either direction should help, but I wanted to know which one I was measuring.

    The Noctua fan lying flat on the router's finned top, seen from above The router from its network-port end, cabled, with the fan resting on top

    What the router recorded

    OPNsense reads the CPU temperature once a minute and keeps hourly averages for weeks. How to read yours is further down.

    Line chart of the router's hourly average CPU temperature from 16 September 2026 to four days after the fan was fitted. It runs between about 65 and 74 °C until 9 October, peaks at 77 °C during the clean-up on 10 October, settles between about 60 and 71 °C, and falls to about 46 °C in the hour after the fan was fitted at 17:30 on 15 October, where it stays.

    Hourly averages of cpu0, from the router’s hourly archive:

    Period Hours Average Lowest hour Highest hour
    16 September – 9 October 567 69.7 °C 65.3 °C 73.7 °C
    11 October – 15 October, until the fan 114 66.2 °C 60.5 °C 70.9 °C
    15 October, after the fan (four days) 100 46.4 °C 42.6 °C 48.6 °C

    I left out 10 October, the day of a configuration clean-up described below. Against the days just before it, the fan took about 20 °C off the average. The before and after ranges do not overlap: the coolest hour before the fan was 12 °C warmer than the warmest hour after it.

    The rule I had set was about the overnight readings. On 15 October I read the 03:00–10:00 window from the per-minute record, and on 16 October I read the same window again:

    cpu0, 03:00–10:00 15 October, no fan 16 October, fan
    Average 65.6 °C 46.7 °C
    Maximum 90.3 °C 73.6 °C
    Readings at 80 °C or above 19 0

    No reading reached the 80s. The rule said leave the case shut.

    My rule used single readings, and single readings jump. Each is one instant: on 28 October consecutive minutes read 35.3, 68.2, 69.0 and 35.7 °C. An average over hours would have made a better test. By hourly averages the gap is wider still: no hour after the fan went above 48.6 °C.

    Deep dive: the 15 October per-minute windows

    Read from the per-minute record on 15 October.

    Window, 15 October 2026 Readings Average Median 95th percentile Maximum At 80 °C or above
    03:00–10:00, no fan 420 65.6 °C 69.0 °C 79.8 °C 90.3 °C 19
    12:00–17:20, no fan 320 65.5 °C 68.7 °C 80.1 °C 90.7 °C 16
    17:31–19:12, fan 101 46.0 °C 48.7 °C 60.5 °C 69.6 °C 0
    19:20–19:37, after a firmware update and reboot 17 54.1 °C 57.1 °C 70.8 °C 70.8 °C 0

    The last row is higher because the router had just rebooted after a firmware update and was loading about 2.7 million blocklist entries. It is not a resting figure.

    What this does and does not show

    It shows that a fan was enough here. It does not show that a repaste would not also have helped; I never tried one. The fan does not take heat out of the cabinet. It forces cabinet air through the router’s fins. The closed cabinet made the starting point worse, so the gain here is probably larger than it would be in open air.

    • I did not measure the room temperature. The drop came within one hour, and a room does not cool 20 °C in an hour. The router also reacts little to the daily cycle: from 16 September to 9 October, the average for each hour of the day stayed between 69.2 and 70.3 °C, a swing of about 1 °C.
    • The firmware changed the same evening. The router installed a firmware update at 19:12 on 15 October. The drop came first: the 101 minutes between fitting the fan and the update averaged 46.0 °C.
    • A configuration clean-up came five days earlier. On 10 October I removed a WireGuard VPN client, an unused proxy stack (Squid, ClamAV, Redis and their companions) and the NAT rules that fed it, trimmed my DNS blocklists, and unplugged a USB network adapter. The hourly average was 69.7 °C from 16 September to 9 October and 66.2 °C from 11 October until the fan. That fall came in steps over three or four days, and I cannot separate those changes from the weather. It is why the comparison above uses only the days just before the fan.
    • No power settings changed. The router’s configuration history goes back to 13 October (30 revisions) and shows no change to power settings, thermal settings or tunables in that time.
    • I did not control the load. These are ordinary days on a home network.
    • It is one router in one cabinet.
    A hunch I did not prove: the dashboard

    On 13 October, with about 20 hours of uptime, I compared CPU time by process. Unbound, the DNS resolver, had used 16 seconds, about 0.02 per cent of one core, while answering about 10,000 unwanted lookups a day from devices on the network. The PHP processes that serve the web interface and the API had used 5 minutes 9 seconds, about 20 times as much, and that snapshot misses PHP workers that had already exited.

    Even so, 5 minutes in 20 hours is about 0.4 per cent of one core. If the open dashboard, whose widgets refresh every few seconds, raised the temperature, it did so in short bursts. I suspected those bursts behind some 78 °C spikes I saw that week. I did not test it.

    Reading your own router

    OPNsense draws its health records under Reporting → Health. To look at the CPU temperature graph:

    1. Open the router’s web interface in a browser: type the address you use to manage the router into the address bar, press Enter, and log in. If you do not know the address, ask whoever set the router up. A router uses its own security certificate, so the browser may warn that the connection is not private; for your own router’s address that is expected. Click Advanced, then the link that continues to the address (Proceed in Chrome, Accept the Risk and Continue in Firefox).
    2. In the menu, open Reporting → Health. The page loads in a few seconds and changes nothing. It lists its reports by topic.
    3. Find the CPU temperature report in the page’s list of reports. If there is none, open System → Settings → Miscellaneous → Thermal Sensors; mine is set to “Intel Core CPU on-die thermal sensor (coretemp)”. Changing that setting changes the router: write down the old value first, press Save*, and wait a few minutes while the router takes its readings. To undo it, choose the old value again; setting it back to none needs a reboot.

    The same data comes from the router’s API, at GET /api/diagnostics/systemhealth/get_system_health/cputemp-system/0. The number at the end picks an archive: /0 is one value a minute, and higher numbers are coarser. How long each lasts depends on when the router’s temperature database was created:

    Archive My router (database from an older OPNsense) A new OPNsense 26.x install
    /0 1 minute, 1,000 slots: 16 hours 40 minutes 1 minute, 1,200 slots: 20 hours
    /1 5 minutes, 1,000 slots: about 3½ days 5 minutes, 720 slots: 60 hours
    /2 1 hour, 1,000 slots: about 6 weeks 1 hour, 1,860 slots: about 11 weeks
    /3 12 hours, 3,000 slots: about 4 years 1 day, 2,284 slots: about 6 years

    OPNsense keeps an existing database through upgrades, so an older router keeps the older layout. The last column is from the 26.7 source code; I have not seen a new install.

    Two things follow. Read last night’s per-minute record this morning; by the evening those minutes are gone, and only the coarser averages remain. And the hourly archive is long enough for a before-and-after you did not plan. Mine already held a month of “before” when I fitted the fan.

    Deep dive: what the archives hold, and why hourly figures hide spikes

    The API serves only averages. OPNsense’s fetchData.py processes only the round-robin archives whose consolidation function is AVERAGE, and builds one “set” per archive. The router stores one instant reading of the sensor each minute; each hourly value is the average of those readings. A single reading of 91 °C barely moves it.

    Slots with no reading come back as empty values. The same script drops empty slots only at the start of a series. So the count of slots understates the archive’s length when its oldest slots are empty, as on a young database. The snippet below reports readings and empty slots separately.

    Deep dive: a console snippet to summarise your own router (for a PC)

    The Health graph shows the shape. This prints the numbers: the average, median, 95th percentile and maximum, and how many readings reached 80 °C, for one archive. It sends one read request (a GET) to the router’s own health API and changes nothing.

    Before you start

    • You need a PC with Chrome or Firefox, and a login to the router’s web interface that can open Reporting → Health.
    • You type in the browser’s developer console, on the router’s own page. You install nothing.
    • It takes two to three minutes.
    • It changes nothing on the router or the PC, so there is nothing to undo. Close the console when you finish.
    • In the boxes below, Copy copies the whole box. A dashed box shows what you should see; you do not type it.

    Steps

    1. Open the router’s web interface in Chrome or Firefox: type the address you use to manage the router into the address bar, press Enter, and log in. You should see the OPNsense dashboard. If no login page appears, check the address and that the PC is on the home network. If the browser warns that the connection is not private, see the note in step 1 of the graph steps above.
    2. Stay on any OPNsense page and open the browser console: Ctrl+Shift+J in Chrome or Ctrl+Shift+K in Firefox on Windows and Linux; Cmd+Option+J or Cmd+Option+K on a Mac. A panel opens beside or below the page, with a line to type on. If it opens on another tab, click the Console tab.
    3. Click Copy in the box below. It copies the whole snippet.

      // Paste into the browser console on any OPNsense page while logged in.
      // Read-only: one GET to the router's own health API. Changes nothing.
      (async () => {
        const LEVEL = 0; // archive: 0 is the finest (one value a minute); higher numbers are coarser. How many exist depends on the router.
        const url = '/api/diagnostics/systemhealth/get_system_health/cputemp-system/' + LEVEL;
        let d;
        try {
          const r = await fetch(url);
          if (r.status === 401) { console.log('HTTP 401: not logged in. Log in to the OPNsense web interface in this browser, then paste again.'); return; }
          if (r.status === 403) { console.log('HTTP 403: logged in, but this user may not read Reporting > Health. Use an account with that privilege.'); return; }
          if (!r.ok) { console.log('HTTP ' + r.status + ' from ' + url); return; }
          d = await r.json();
        } catch (e) {
          console.log('No JSON came back (' + e.message + '). Run this on an OPNsense page while logged in.'); return;
        }
        const series = d && d.set && d.set.data && d.set.data[0];
        if (!series || !Array.isArray(series.values)) { console.log('No temperature series at LEVEL ' + LEVEL + '. A higher LEVEL may not exist on this router; at LEVEL 0, check that Reporting > Health shows a CPU temperature graph.'); return; }
        const pts = series.values.filter(p => p[1] !== null && !isNaN(p[1]));
        const empty = series.values.length - pts.length;
        if (pts.length === 0) { console.log('The series ' + series.key + ' has no readings at this level.'); return; }
        const v = pts.map(p => p[1]).sort((a, b) => a - b);
        const n = v.length;
        const median = n % 2 ? v[(n - 1) / 2] : (v[n / 2 - 1] + v[n / 2]) / 2;
        const p95 = v[Math.min(n - 1, Math.ceil(0.95 * n) - 1)]; // nearest-rank
        const when = t => new Date(t).toLocaleString(); // your browser's time zone; each time marks the end of its interval
        console.log('Series ' + series.key + ', one value every ' + d.set.step_size + ' s');
        console.log('From ' + when(pts[0][0]) + ' to ' + when(pts[n - 1][0]) + ': ' + n + ' readings, ' + empty + ' empty slots');
        console.log('Average ' + (v.reduce((a, b) => a + b, 0) / n).toFixed(1) + ' °C, median ' + median.toFixed(1) +
          ', 95th percentile ' + p95.toFixed(1) + ', maximum ' + v[n - 1].toFixed(1));
        console.log('Readings at 80 °C or above: ' + v.filter(x => x >= 80).length);
      })();
    4. Click the line in the console, paste with Ctrl+V (Cmd+V on a Mac) and press Enter. Browsers may block pasting into the console, because pasting a stranger’s code into a logged-in page is a known trick. Read the snippet before you allow it. If the browser asks you to type “allow pasting”, do what its message says, then paste again.

    5. Within a second or two you should see four lines (ignore a line that starts with “Promise”): the series name, the time range with the number of readings and empty slots, the summary figures, and the count of readings at 80 °C or above. Times are in your browser’s time zone, and each marks the end of its interval. On my router, on 28 October 2026, it printed this (I left out the times; their format follows your browser’s settings):

      Series cpu0temp, one value every 60 s
      From <start time> to <end time>: 1000 readings, 0 empty slots
      Average 43.9 °C, median 47.7, 95th percentile 57.8, maximum 72.5
      Readings at 80 °C or above: 0
    6. “HTTP 401” means the browser is not logged in to OPNsense: log in and repeat step 4. “HTTP 403” means you are logged in as a user without access to Reporting → Health.

    7. To read the hourly archive, paste the snippet into a plain text editor first (Notepad on Windows, TextEdit set to plain text on a Mac), change const LEVEL = 0; to const LEVEL = 2;, copy all of it from there, and repeat steps 4 and 5.
    8. Compare the average with the level of the Reporting → Health graph for the same archive. They should agree.
    9. When you finish, close the panel with the × at its top right. Nothing was changed on the router.

    The verdict

    The case stays shut and the paste stays in its box.

    What is left is small. Fasten the fan, and lift it: rubber feet of 10 to 15 mm would hold it in place and let air reach the fins under its hub, which a fan lying flat starves. That is general practice for fans over heatsinks; I have not measured it here. Keep the side grille clear. The cabinet as a whole is a separate problem: the fan can cool the router only towards the temperature of the cabinet air, which is warmer than the room. I worked through that separately and may write it up.

    Before the fan, the heat was a reason to look at a new router. It is not any more.

    What I would tell someone with a fanless box in a warm cupboard

    1. Read what the router already records before you open anything. On OPNsense that is Reporting → Health, or the API above.
    2. Check how long each archive lasts on your router. It depends on when its database was created.
    3. Decide which result sends you to the next step, before you change anything.
    4. Judge averages, not single readings. Consecutive minute readings can differ by 30 °C.
    5. Try the cheap, reversible fix first, and weigh what it costs: a fan brings noise and dust to a box bought to have neither.
    Glossary
    • Fanless (passive) cooling: the case is the heatsink; heat leaves by conduction and natural airflow, with no fan.
    • Thermal paste / repaste: the compound between the CPU and the heatsink that fills microscopic gaps. Repasting means cleaning off the old compound and applying new.
    • P-core / E-core: Intel’s performance and efficient cores in one chip. The Pentium Gold 8505 has one of the first and four of the second.
    • TJUNCTION: the highest temperature Intel allows at the chip itself. For the 8505 it is 100 °C.
    • PWM: pulse-width modulation; a signal wire that tells a fan how fast to spin.
    • Round-robin database (RRD): a fixed-size store that keeps recent data at fine resolution and older data as coarser averages, overwriting the oldest.
    • Median / 95th percentile: the median is the middle reading (or the average of the two middle readings); 95 per cent of readings are at or below the 95th percentile.
    • API: the router’s programming interface; the same data the web pages show, returned as JSON.
    • Tunables: kernel settings that OPNsense applies at boot, listed under System → Settings → Tunables.

    Paste अब भी अपने डिब्बे में है

    15 अक्टूबर 2026 को मेरी मेज़ पर एक ही समस्या के दो इलाज रखे थे: ARCTIC MX-7 thermal paste की 4 g की ट्यूब और 120 mm का एक Noctua fan। समस्या मेरा router था: एक fanless mini PC, जो बंद plywood कैबिनेट में OPNsense चलाता है। एक दिन पहले उसका CPU 91 °C तक पहुँच गया था।

    ऑनलाइन जो सलाह मिली, वह यही थी कि case खोलो और paste बदल दो। मैंने पहले fan लगाया, क्योंकि उसके लिए screwdriver नहीं चाहिए था। लगाने से पहले मैंने तय कर लिया कि कौन-सा नतीजा मुझे वापस paste की ओर भेजेगा।

    उसकी ज़रूरत नहीं पड़ी। Router शुरू से अपना तापमान खुद दर्ज कर रहा था। 16 सितंबर से 15 अक्टूबर की शाम तक किसी भी घंटे का औसत 60 °C से नीचे नहीं गया। Fan लगने के बाद के चार दिनों में किसी भी घंटे का औसत 49 °C से ऊपर नहीं गया। Paste अब भी अपने डिब्बे में है।

    यह काम मैंने Anthropic के AI मॉडल Claude के साथ किया, जो मेरे अपने browser session के ज़रिए मेरा router पढ़ सकता था। Parts मैंने चुने, fan मैंने लगाया और नियम मैंने तय किया। तापमान के रिकॉर्ड Claude ने निकाले और हिसाब उसी ने लगाया। 28 अक्टूबर को इस पोस्ट के लिए उसने router का hourly data दोबारा पढ़ा।

    Box और कैबिनेट

    यह router छह port वाला fanless mini PC है, जो “Shenzhen Weibu” नाम से बिकता है। अंदर Intel Pentium Gold 8505 है: एक performance core और चार efficient cores, छह threads, 15 W base power और turbo में 55 W तक, Intel के specification पेज के अनुसार। इसमें 20 GB RAM और छह Intel I226-V 2.5 GbE ports हैं, और यह OPNsense 26.7 चलाता है। इसका case ही heatsink है। ऊपर का हिस्सा fins का एक ब्लॉक है।

    यह दूसरे network उपकरणों के साथ एक बंद plywood कैबिनेट में रखा है। कैबिनेट के साइड पैनल में झिरियों वाली एक ग्रिल ही गर्म हवा के निकलने का तय रास्ता है।

    Fan लगने से पहले router, USB वाले सिरे से: काला case, जिसका ऊपरी हिस्सा fins का ब्लॉक है, और बगल में कैबिनेट के साइड पैनल की झिरियों वाली ग्रिल

    क्या 91 °C ख़तरनाक था? Intel के आँकड़ों के हिसाब से नहीं। उसी पेज पर chip का अधिकतम junction तापमान (TJUNCTION) 100 °C दिया है, और उस सीमा पर processor ख़राब होने के बजाय अपनी रफ़्तार घटा लेता है। एक बात और: 91 °C सिर्फ़ उन readings में सबसे ऊँचा था जो router ने लीं; router sensor को मिनट में एक बार पढ़ता है, इसलिए बीच के peaks दर्ज नहीं हुए। फिर भी यह गर्मी नया router देखने की एक वजह बन गई थी। Hourly औसत दिन-रात 70 °C के आसपास रहता था, और SSD, memory और network chips उसी गर्म case में हैं। गर्मी आम तौर पर electronics की उम्र घटाती है, हालाँकि इस box पर मैंने न यह नापा, न SSD का तापमान।

    Fan पहले क्यों

    गर्म mini PC के लिए repaste आम सलाह है, और काफ़ी मुमकिन है कि उससे फ़ायदा होता। पर उसके लिए यह सब करना पड़ता:

    • पहले configuration का backup;
    • 99 प्रतिशत isopropyl alcohol और रेशे न छोड़ने वाले wipes;
    • 45 से 60 मिनट तक network बंद;
    • एक sealed case खोलना, जिसके screws और thermal pads मैंने कभी नहीं देखे थे।

    Fins पर रखे fan के लिए इनमें से कुछ नहीं चाहिए था, और उसे एक सेकंड में हटाया जा सकता था। उसके अपने नुक़सान भी हैं। वह वही छीन लेता है जिसके लिए fanless box लिया जाता है: न शोर, न खिंचकर आती धूल, न घिसने वाला कोई हिस्सा।

    इसलिए लगाने से पहले मैंने नियम तय किया: repaste तभी, जब fan लगे होने पर भी रात की readings 80 या उससे ऊपर पहुँचें।

    Fan

    मैंने Noctua NF-F12 5V PWM चुना। Noctua के specification के अनुसार यह 120 mm, 5 V, अधिकतम 1,500 rpm, सामान्यतः 0.65 W और पूरी रफ़्तार पर 22.4 dB(A) का है, और डिब्बे में USB power cable आती है। मेरा fan router के अपने ही एक USB port में लगा है। USB से चलाने पर fan को रफ़्तार का कोई signal नहीं मिलता, और Noctua की अपनी guide कहती है कि बिना signal के PWM fan पूरी रफ़्तार पर चलता है। Noctua इस पर “5V PWM version, not for use in PCs” लिखता है, यानी यह 5V PWM संस्करण है, PC में इस्तेमाल के लिए नहीं: PC का 12 V fan header इसके लिए ग़लत supply है।

    मेरे router पर 120 mm का fan ऊपरी सतह का ज़्यादातर हिस्सा ढक लेता है। Router के ऊपरी हिस्से के लगभग बराबर आकार का fan चुनें। Noctua छोटे आकारों में भी 5 V संस्करण बेचता है, जैसे 80 mm का NF-A8 5V PWM। कोई सस्ता 5 V USB fan भी हवा चलाएगा; मैंने ऐसा कोई fan आज़माया नहीं।

    मैंने इसे 15 अक्टूबर को लगभग 17:30 पर लगाया। यह ऊपर के fins पर सपाट रखा है, screws से कसा नहीं है, और हवा नीचे fins में फेंकता है। एक फ़ोटो पढ़ते हुए Claude ने पहले हवा की दिशा उल्टी बताई; मैंने frame पर बना तीर देखा। किसी भी दिशा में हवा चले, मदद मिलनी चाहिए, पर मैं जानना चाहता था कि मैं किस दिशा को नाप रहा हूँ।

    Router के fins वाले ऊपरी हिस्से पर सपाट रखा Noctua fan, ऊपर से देखने पर Network ports वाले सिरे से router: ports में cables लगे हैं और ऊपर fan रखा है

    Router ने क्या दर्ज किया

    OPNsense CPU तापमान मिनट में एक बार पढ़ता है और hourly औसत हफ़्तों तक रखता है। अपने router का तापमान कैसे पढ़ें, यह आगे है।

    16 सितंबर 2026 से fan लगने के चार दिन बाद तक router के CPU तापमान के hourly औसत का line chart। 9 अक्टूबर तक यह लगभग 65 से 74 °C के बीच रहता है, 10 अक्टूबर की configuration की सफ़ाई के दौरान 77 °C तक जाता है, फिर लगभग 60 से 71 °C के बीच टिकता है, और 15 अक्टूबर को 17:30 पर fan लगने के बाद वाले घंटे में लगभग 46 °C पर गिरकर वहीं रहता है।

    cpu0 के hourly औसत, router के hourly archive से:

    अवधि घंटे औसत सबसे ठंडा घंटा सबसे गर्म घंटा
    16 सितंबर – 9 अक्टूबर 567 69.7 °C 65.3 °C 73.7 °C
    11 अक्टूबर – 15 अक्टूबर, fan लगने तक 114 66.2 °C 60.5 °C 70.9 °C
    15 अक्टूबर, fan के बाद (चार दिन) 100 46.4 °C 42.6 °C 48.6 °C

    10 अक्टूबर मैंने छोड़ दिया है; उस दिन की configuration की सफ़ाई का ज़िक्र नीचे है। ठीक पहले के दिनों की तुलना में fan ने औसत लगभग 20 °C घटाया। पहले और बाद के दायरे एक-दूसरे को छूते नहीं: fan से पहले का सबसे ठंडा घंटा, बाद के सबसे गर्म घंटे से 12 °C ज़्यादा गर्म था।

    मैंने जो नियम तय किया था, वह रात की readings के बारे में था। 15 अक्टूबर को मैंने per-minute रिकॉर्ड से 03:00–10:00 का समय पढ़ा, और 16 अक्टूबर को वही समय फिर पढ़ा:

    cpu0, 03:00–10:00 15 अक्टूबर, बिना fan 16 अक्टूबर, fan के साथ
    औसत 65.6 °C 46.7 °C
    अधिकतम 90.3 °C 73.6 °C
    80 °C या उससे ऊपर की readings 19 0

    कोई reading 80 या उससे ऊपर नहीं पहुँची। नियम के मुताबिक़ case बंद ही रहना था।

    मेरा नियम अकेली readings पर टिका था, और अकेली readings उछलती हैं। हर reading एक पल की होती है: 28 अक्टूबर को लगातार मिनटों में 35.3, 68.2, 69.0 और 35.7 °C दर्ज हुए। घंटों का औसत बेहतर कसौटी होता। Hourly औसत के हिसाब से अंतर और भी बड़ा है: fan के बाद कोई घंटा 48.6 °C से ऊपर नहीं गया।

    गहराई से: 15 अक्टूबर के per-minute समय-खंड

    15 अक्टूबर को per-minute रिकॉर्ड से पढ़ा गया।

    समय, 15 अक्टूबर 2026 Readings औसत Median 95th percentile अधिकतम 80 °C या ऊपर
    03:00–10:00, बिना fan 420 65.6 °C 69.0 °C 79.8 °C 90.3 °C 19
    12:00–17:20, बिना fan 320 65.5 °C 68.7 °C 80.1 °C 90.7 °C 16
    17:31–19:12, fan के साथ 101 46.0 °C 48.7 °C 60.5 °C 69.6 °C 0
    19:20–19:37, firmware update और reboot के बाद 17 54.1 °C 57.1 °C 70.8 °C 70.8 °C 0

    आख़िरी पंक्ति ज़्यादा है, क्योंकि router अभी-अभी firmware update के बाद reboot हुआ था और लगभग 27 लाख blocklist entries लोड कर रहा था। यह आराम की स्थिति का आँकड़ा नहीं है।

    यह क्या दिखाता है और क्या नहीं

    यह दिखाता है कि यहाँ एक fan काफ़ी था। इससे यह साबित नहीं होता कि repaste से भी फ़ायदा न होता; मैंने उसे कभी आज़माया नहीं। Fan कैबिनेट से गर्मी बाहर नहीं निकालता। वह कैबिनेट की हवा को router के fins के बीच से धकेलता है। बंद कैबिनेट ने शुरुआती स्थिति को और बिगाड़ा था, इसलिए यहाँ का फ़ायदा शायद खुली हवा में होने वाले फ़ायदे से ज़्यादा है।

    • मैंने कमरे का तापमान नहीं नापा। गिरावट एक घंटे के भीतर आई, और कोई कमरा एक घंटे में 20 °C ठंडा नहीं होता। साथ ही, router पर दिन-रात के चक्र का असर कम पड़ता है: 16 सितंबर से 9 अक्टूबर तक दिन के हर घंटे का औसत 69.2 और 70.3 °C के बीच रहा, यानी लगभग 1 °C का उतार-चढ़ाव।
    • उसी शाम firmware बदला। Router पर 15 अक्टूबर को 19:12 पर firmware update हुआ। गिरावट पहले आई: fan लगने और update के बीच के 101 मिनटों का औसत 46.0 °C था।
    • Configuration की सफ़ाई पाँच दिन पहले हुई थी। 10 अक्टूबर को मैंने एक WireGuard VPN client हटाया, बिना इस्तेमाल पड़ा एक proxy stack (Squid, ClamAV, Redis और उनके साथी) और उसे traffic भेजने वाले NAT rules हटाए, अपनी DNS blocklists छाँटीं, और एक USB network adapter निकाल दिया। Hourly औसत 16 सितंबर से 9 अक्टूबर तक 69.7 °C था और 11 अक्टूबर से fan लगने तक 66.2 °C। यह गिरावट तीन-चार दिनों में क़दम-दर-क़दम आई, और मैं उन बदलावों के असर को मौसम से अलग नहीं कर सकता। इसी वजह से ऊपर की तुलना में सिर्फ़ fan से ठीक पहले के दिन लिए गए हैं।
    • कोई power settings नहीं बदलीं। Router का configuration history 13 अक्टूबर से शुरू होता है (30 revisions) और तब से power settings, thermal settings या tunables में कोई बदलाव नहीं दिखाता।
    • मैंने load को नियंत्रित नहीं किया। ये घर के network के आम दिन हैं।
    • यह सिर्फ़ एक router है, एक ही कैबिनेट में।
    एक अनुमान जो मैंने साबित नहीं किया: dashboard

    13 अक्टूबर को, लगभग 20 घंटे के uptime पर, मैंने process के हिसाब से CPU time की तुलना की। DNS resolver Unbound ने 16 सेकंड लिए थे, यानी एक core का लगभग 0.02 प्रतिशत, जबकि वह network के devices से रोज़ आने वाले लगभग 10,000 अनचाहे lookups का जवाब दे रहा था। Web interface और API चलाने वाले PHP processes ने 5 मिनट 9 सेकंड लिए थे, लगभग 20 गुना, और उस snapshot में वे PHP workers नहीं गिने गए जो तब तक बंद हो चुके थे।

    फिर भी, 20 घंटों में 5 मिनट एक core का लगभग 0.4 प्रतिशत है। अगर खुले dashboard ने, जिसके widgets हर कुछ सेकंड में refresh होते हैं, तापमान बढ़ाया, तो छोटे-छोटे झटकों में बढ़ाया। उस हफ़्ते दिखे कुछ 78 °C वाले spikes के पीछे मुझे इन्हीं झटकों का शक था। मैंने इसकी जाँच नहीं की।

    अपने router को पढ़ना

    OPNsense अपने health रिकॉर्ड Reporting → Health में ग्राफ़ के रूप में दिखाता है। CPU तापमान का ग्राफ़ देखने के लिए:

    1. Browser में router का web interface खोलें: address bar में वह पता लिखें जिससे आप router का प्रबंधन करते हैं, Enter दबाएँ, और log in करें। अगर आपको पता न मालूम हो, तो जिसने router लगाया था उससे पूछ लें। Router अपना ही security certificate इस्तेमाल करता है, इसलिए browser चेतावनी दे सकता है कि connection private नहीं है; आपके अपने router के पते के लिए यह अपेक्षित है। Advanced पर click करें, फिर उस link पर जो पते पर आगे बढ़ाता है (Chrome में Proceed, Firefox में Accept the Risk and Continue)।
    2. Menu में Reporting → Health खोलें। पेज कुछ सेकंड में लोड होता है और कुछ नहीं बदलता। यह अपनी reports को विषय के हिसाब से सूचीबद्ध करता है।
    3. पेज की reports की सूची में CPU तापमान की report ढूँढें। अगर कोई न हो, तो System → Settings → Miscellaneous → Thermal Sensors खोलें; मेरे यहाँ यह “Intel Core CPU on-die thermal sensor (coretemp)” पर सेट है। इस setting को बदलने से router बदल जाता है: पहले पुराना मान लिख लें, Save* दबाएँ, और कुछ मिनट रुकें जब तक router अपनी readings न ले ले। इसे पलटने के लिए पुराना मान फिर चुनें; इस setting को वापस none पर करने के लिए reboot चाहिए।

    यही data router के API से भी मिलता है, GET /api/diagnostics/systemhealth/get_system_health/cputemp-system/0 पर। आख़िर का अंक एक archive चुनता है: /0 में हर मिनट का एक मान है, और बड़े अंकों वाले archives में मान लंबे अंतराल पर होते हैं, यानी कम बारीक। हर archive कितनी देर का है, यह इस पर निर्भर है कि router का तापमान database कब बना था:

    Archive मेरा router (पुराने OPNsense से बना database) नया OPNsense 26.x install
    /0 1 मिनट, 1,000 slots: 16 घंटे 40 मिनट 1 मिनट, 1,200 slots: 20 घंटे
    /1 5 मिनट, 1,000 slots: लगभग 3½ दिन 5 मिनट, 720 slots: 60 घंटे
    /2 1 घंटा, 1,000 slots: लगभग 6 हफ़्ते 1 घंटा, 1,860 slots: लगभग 11 हफ़्ते
    /3 12 घंटे, 3,000 slots: लगभग 4 साल 1 दिन, 2,284 slots: लगभग 6 साल

    OPNsense upgrade के बाद भी मौजूदा database को बनाए रखता है, इसलिए पुराना router पुराना layout ही रखता है। आख़िरी कॉलम 26.7 के source code से है; मैंने कोई नया install नहीं देखा।

    इससे दो बातें निकलती हैं। पिछली रात का per-minute रिकॉर्ड आज सुबह पढ़ें; शाम तक वे मिनट जा चुके होते हैं और सिर्फ़ लंबे अंतराल के औसत बचते हैं। और hourly archive इतना लंबा है कि बिना योजना के भी पहले-और-बाद की तुलना हो जाती है। Fan लगाते समय मेरे archive में एक महीने का “पहले” दर्ज हो चुका था।

    गहराई से: archives में क्या रहता है, और hourly आँकड़े spikes क्यों छिपा लेते हैं

    API सिर्फ़ औसत देता है। OPNsense की fetchData.py केवल उन round-robin archives को process करती है जिनका consolidation function AVERAGE है, और हर archive का एक “set” बनाती है। Router हर मिनट sensor की एक तात्कालिक reading रखता है; हर hourly मान उन readings का औसत है। 91 °C की एक अकेली reading उसे मुश्किल से हिलाती है।

    जिन slots में कोई reading नहीं है, वे ख़ाली मानों के रूप में लौटते हैं। यही script ख़ाली slots को सिर्फ़ series की शुरुआत में हटा देती है। इसलिए जब archive के सबसे पुराने slots ख़ाली हों, जैसे नए database में, तो slots की गिनती archive की लंबाई को कम करके दिखाती है। नीचे का snippet readings और ख़ाली slots अलग-अलग बताता है।

    गहराई से: अपने router का सार निकालने के लिए एक console snippet (PC के लिए)

    Health ग्राफ़ उतार-चढ़ाव का रूप दिखाता है। यह snippet आँकड़े छापता है: एक archive के लिए औसत, median, 95th percentile और अधिकतम, और कितनी readings 80 °C तक पहुँचीं। यह router के अपने health API को एक read request (एक GET) भेजता है और कुछ नहीं बदलता।

    शुरू करने से पहले

    • आपको Chrome या Firefox वाला PC चाहिए, और router के web interface का ऐसा login जो Reporting → Health खोल सके।
    • आप browser के developer console में, router के अपने पेज पर टाइप करते हैं। कुछ install नहीं करना पड़ता।
    • इसमें दो से तीन मिनट लगते हैं।
    • यह router या PC पर कुछ नहीं बदलता, इसलिए वापस करने को कुछ नहीं है। काम पूरा होने पर console बंद कर दें।
    • नीचे के डिब्बों में Copy पूरे डिब्बे को copy करता है। टूटी रेखाओं वाला डिब्बा वह दिखाता है जो आपको दिखना चाहिए; उसे आप टाइप नहीं करते।

    चरण

    1. Chrome या Firefox में router का web interface खोलें: address bar में वह पता लिखें जिससे आप router का प्रबंधन करते हैं, Enter दबाएँ, और log in करें। आपको OPNsense का dashboard दिखना चाहिए। अगर login पेज न दिखे, तो पता जाँचें और देखें कि PC घर के network पर है। अगर browser चेतावनी दे कि connection private नहीं है, तो ऊपर graph के चरणों के चरण 1 में दिया note देखें।
    2. किसी भी OPNsense पेज पर रहते हुए browser console खोलें: Windows और Linux पर Chrome में Ctrl+Shift+J या Firefox में Ctrl+Shift+K; Mac पर Cmd+Option+J या Cmd+Option+K। पेज के बगल में या नीचे एक panel खुलता है, जिसमें टाइप करने के लिए एक पंक्ति होती है। अगर वह किसी दूसरे tab पर खुले, तो Console tab पर click करें।
    3. नीचे के डिब्बे में Copy दबाएँ। यह पूरा snippet copy कर लेता है।

      // Paste into the browser console on any OPNsense page while logged in.
      // Read-only: one GET to the router's own health API. Changes nothing.
      (async () => {
        const LEVEL = 0; // archive: 0 is the finest (one value a minute); higher numbers are coarser. How many exist depends on the router.
        const url = '/api/diagnostics/systemhealth/get_system_health/cputemp-system/' + LEVEL;
        let d;
        try {
          const r = await fetch(url);
          if (r.status === 401) { console.log('HTTP 401: not logged in. Log in to the OPNsense web interface in this browser, then paste again.'); return; }
          if (r.status === 403) { console.log('HTTP 403: logged in, but this user may not read Reporting > Health. Use an account with that privilege.'); return; }
          if (!r.ok) { console.log('HTTP ' + r.status + ' from ' + url); return; }
          d = await r.json();
        } catch (e) {
          console.log('No JSON came back (' + e.message + '). Run this on an OPNsense page while logged in.'); return;
        }
        const series = d && d.set && d.set.data && d.set.data[0];
        if (!series || !Array.isArray(series.values)) { console.log('No temperature series at LEVEL ' + LEVEL + '. A higher LEVEL may not exist on this router; at LEVEL 0, check that Reporting > Health shows a CPU temperature graph.'); return; }
        const pts = series.values.filter(p => p[1] !== null && !isNaN(p[1]));
        const empty = series.values.length - pts.length;
        if (pts.length === 0) { console.log('The series ' + series.key + ' has no readings at this level.'); return; }
        const v = pts.map(p => p[1]).sort((a, b) => a - b);
        const n = v.length;
        const median = n % 2 ? v[(n - 1) / 2] : (v[n / 2 - 1] + v[n / 2]) / 2;
        const p95 = v[Math.min(n - 1, Math.ceil(0.95 * n) - 1)]; // nearest-rank
        const when = t => new Date(t).toLocaleString(); // your browser's time zone; each time marks the end of its interval
        console.log('Series ' + series.key + ', one value every ' + d.set.step_size + ' s');
        console.log('From ' + when(pts[0][0]) + ' to ' + when(pts[n - 1][0]) + ': ' + n + ' readings, ' + empty + ' empty slots');
        console.log('Average ' + (v.reduce((a, b) => a + b, 0) / n).toFixed(1) + ' °C, median ' + median.toFixed(1) +
          ', 95th percentile ' + p95.toFixed(1) + ', maximum ' + v[n - 1].toFixed(1));
        console.log('Readings at 80 °C or above: ' + v.filter(x => x >= 80).length);
      })();
    4. Console की पंक्ति पर click करें, Ctrl+V (Mac पर Cmd+V) से paste करें और Enter दबाएँ। Browsers console में paste करना रोक सकते हैं, क्योंकि logged-in पेज में किसी अजनबी का code paste करवाना एक जानी-पहचानी चाल है। अनुमति देने से पहले snippet पढ़ लें। अगर browser “allow pasting” टाइप करने को कहे, तो उसके संदेश के अनुसार करें, फिर दोबारा paste करें।

    5. एक-दो सेकंड में चार पंक्तियाँ दिखनी चाहिए (“Promise” से शुरू होने वाली पंक्ति को छोड़ दें): series का नाम, readings और ख़ाली slots की संख्या के साथ समय की अवधि, सार के आँकड़े, और 80 °C या उससे ऊपर की readings की गिनती। समय आपके browser के time zone में होते हैं, और हर समय अपने अंतराल का अंत बताता है। 28 अक्टूबर 2026 को मेरे router पर इसने यह छापा (मैंने समय छोड़ दिए हैं; उनका रूप आपके browser की settings पर निर्भर करता है):

      Series cpu0temp, one value every 60 s
      From <start time> to <end time>: 1000 readings, 0 empty slots
      Average 43.9 °C, median 47.7, 95th percentile 57.8, maximum 72.5
      Readings at 80 °C or above: 0
    6. “HTTP 401” का मतलब है कि browser OPNsense में logged in नहीं है: log in करें और चरण 4 दोहराएँ। “HTTP 403” का मतलब है कि आप ऐसे user से logged in हैं जिसे Reporting → Health की अनुमति नहीं है।

    7. Hourly archive पढ़ने के लिए snippet को पहले किसी plain text editor में paste करें (Windows पर Notepad, Mac पर plain text पर सेट TextEdit), const LEVEL = 0; को const LEVEL = 2; करें, वहाँ से पूरा copy करें, और चरण 4 और 5 दोहराएँ।
    8. औसत की तुलना उसी archive के Reporting → Health ग्राफ़ के level से करें। दोनों मेल खाने चाहिए।
    9. काम पूरा होने पर panel को उसके ऊपर दाईं ओर के × से बंद करें। Router पर कुछ नहीं बदला गया।

    फ़ैसला

    Case बंद रहेगा और paste अपने डिब्बे में।

    जो बचा है वह छोटा है। Fan को अपनी जगह पर पक्का करें, और उसे ऊपर उठाएँ: 10 से 15 mm के rubber feet उसे जगह पर रखेंगे और उसके hub के नीचे के fins तक हवा पहुँचने देंगे, जिन्हें सपाट पड़ा fan हवा से वंचित रखता है। Heatsinks के ऊपर लगे fans के लिए यह आम तरीका है; मैंने इसे यहाँ नापा नहीं। साइड की ग्रिल खुली रखें। पूरा कैबिनेट एक अलग समस्या है: fan router को ठंडा तो करता है, पर सिर्फ़ कैबिनेट की हवा के तापमान के क़रीब तक; और कैबिनेट की हवा कमरे की हवा से गर्म है। उस पर मैंने अलग से काम किया और शायद उस पर लिखूँ।

    Fan से पहले यह गर्मी नया router देखने की एक वजह थी। अब नहीं है।

    गर्म अलमारी में fanless box रखने वाले से मैं क्या कहूँगा

    1. पहले वह पढ़ें जो router पहले से दर्ज करता है, कुछ भी खोलने से पहले। OPNsense पर यह Reporting → Health है, या ऊपर वाला API।
    2. देखें कि आपके router पर हर archive कितनी देर का है। यह इस पर निर्भर है कि उसका database कब बना था।
    3. कुछ भी बदलने से पहले तय करें कि कौन-सा नतीजा आपको अगले कदम पर भेजेगा।
    4. अकेली readings पर नहीं, औसत पर फ़ैसला करें। लगातार मिनटों की readings में 30 °C का अंतर हो सकता है।
    5. पहले सस्ता और वापस लिया जा सकने वाला उपाय आज़माएँ, और उसकी क़ीमत भी तौलें: fan उस box में शोर और धूल लाता है जो इन दोनों से बचने के लिए लिया गया था।
    शब्दावली
    • Fanless (passive) cooling: case ही heatsink है; गर्मी बिना fan के, चालन और हवा के प्राकृतिक बहाव से निकलती है।
    • Thermal paste / repaste: CPU और heatsink के बीच का वह पदार्थ जो सूक्ष्म खाली जगहें भरता है। Repaste का मतलब पुराना पदार्थ साफ़ करके नया लगाना।
    • P-core / E-core: एक ही chip में Intel के performance और efficient cores। Pentium Gold 8505 में पहले वाला एक और दूसरे वाले चार हैं।
    • TJUNCTION: ख़ुद chip के भीतर Intel द्वारा अनुमत सबसे ऊँचा तापमान। 8505 के लिए यह 100 °C है।
    • PWM: pulse-width modulation; एक signal तार जो fan को बताता है कि कितनी तेज़ घूमे।
    • Round-robin database (RRD): तय आकार का भंडार, जो हाल का data बारीक रूप में और पुराना data लंबे अंतराल के औसत के रूप में रखता है, और सबसे पुराने को मिटाकर लिखता है।
    • Median / 95th percentile: median बीच की reading है (या दो बीच वाली readings का औसत); 95 प्रतिशत readings 95th percentile के बराबर या उससे नीचे होती हैं।
    • API: router का programming interface; वही data जो web पेज दिखाते हैं, JSON के रूप में।
    • Tunables: kernel settings जिन्हें OPNsense boot के समय लागू करता है; ये System → Settings → Tunables में सूचीबद्ध हैं।

    Paste ఇంకా దాని పెట్టెలోనే ఉంది

    15 అక్టోబర్ 2026న నా డెస్క్ మీద ఒకే సమస్యకు రెండు పరిష్కారాలు ఉన్నాయి: 4 g ARCTIC MX-7 thermal paste ట్యూబ్ ఒకటి, 120 mm Noctua fan ఒకటి. సమస్య నా router. అది మూసి ఉన్న ప్లైవుడ్ క్యాబినెట్‌లో OPNsense నడుపుతున్న ఒక fanless mini PC. అంతకు ముందు రోజు దాని CPU 91 °C ను తాకింది.

    ఆన్‌లైన్‌లో నాకు దొరికిన సలహా కేస్ తెరిచి paste మార్చమని. స్క్రూడ్రైవర్ అవసరం లేదు కాబట్టి నేను ముందు fan పెట్టాను. పెట్టే ముందే, ఏ ఫలితం వస్తే paste దగ్గరకు తిరిగి వెళ్ళాలో నిర్ణయించుకున్నాను.

    ఆ అవసరం రాలేదు. Router మొదటి నుంచీ తన ఉష్ణోగ్రతను తానే నమోదు చేసుకుంటూ ఉంది. 16 సెప్టెంబర్ నుంచి 15 అక్టోబర్ సాయంత్రం వరకు, ఏ గంట సగటూ 60 °C కంటే తక్కువ లేదు. Fan పెట్టిన తర్వాతి నాలుగు రోజుల్లో, ఏ గంట సగటూ 49 °C దాటలేదు. Paste ఇంకా దాని పెట్టెలోనే ఉంది.

    ఈ పని నేను Anthropic తయారుచేసిన AI మోడల్ Claude తో కలిసి చేశాను. అది నా సొంత బ్రౌజర్ సెషన్ ద్వారా నా router ను చదవగలిగింది. పార్టులు నేను ఎంచుకున్నాను, fan నేను పెట్టాను, నియమం నేను పెట్టాను. Claude ఉష్ణోగ్రత రికార్డులు తీసి లెక్కలు చేసింది. 28 అక్టోబర్‌న ఈ పోస్ట్ కోసం router గంటవారీ డేటాను మళ్ళీ చదివి చెప్పింది.

    బాక్స్, క్యాబినెట్

    ఈ router ఆరు పోర్టులు ఉన్న ఒక fanless mini PC. దీన్ని “Shenzhen Weibu” పేరుతో అమ్ముతారు. లోపల Intel Pentium Gold 8505 ఉంది. Intel స్పెసిఫికేషన్ పేజీ ప్రకారం దానిలో ఒక పెర్ఫార్మెన్స్ కోర్, నాలుగు ఎఫిషియెంట్ కోర్లు, ఆరు థ్రెడ్లు ఉన్నాయి; బేస్ పవర్ 15 W, టర్బోలో 55 W వరకు. దీనికి 20 GB RAM, ఆరు Intel I226-V 2.5 GbE పోర్టులు ఉన్నాయి. ఇది OPNsense 26.7 నడుపుతుంది. కేసే heatsink. దాని పైభాగం fins ఉన్న ఒక బ్లాక్.

    ఇది ఇతర నెట్‌వర్క్ పరికరాలతో కలిసి మూసి ఉన్న ఒక ప్లైవుడ్ క్యాబినెట్‌లో ఉంటుంది. క్యాబినెట్ పక్క ప్యానెల్‌లోని చీలికల గ్రిల్ ఒక్కటే వేడి గాలి బయటకు పోవడానికి అనుకున్న దారి.

    Fan పెట్టక ముందు router, USB వైపు నుంచి: పైభాగం fins బ్లాక్‌గా ఉన్న నల్లటి కేస్, పక్కనే క్యాబినెట్ పక్క ప్యానెల్‌లోని చీలికల గ్రిల్

    91 °C ప్రమాదకరమా? Intel అంకెల ప్రకారం కాదు. అదే పేజీ చిప్ గరిష్ఠ junction ఉష్ణోగ్రత (TJUNCTION) 100 °C అని చెబుతుంది. ఆ పరిమితికి చేరిన ప్రాసెసర్ పాడవడానికి బదులు తన వేగాన్ని తానే తగ్గించుకుంటుంది. పైగా 91 °C అనేది నమోదైన రీడింగుల్లో అత్యధికం మాత్రమే; router సెన్సార్‌ను నిమిషానికి ఒకసారి చదువుతుంది, కాబట్టి రెండు రీడింగుల మధ్య వచ్చిన గరిష్ఠాలు నమోదు కాలేదు. అయినా, ఈ వేడి కొత్త router చూడడానికి ఒక కారణంగా మారింది. గంటవారీ సగటు పగలూ రాత్రీ 70 °C దగ్గరే ఉంది, SSD, మెమరీ, నెట్‌వర్క్ చిప్‌లు అదే వేడి కేస్‌లో ఉంటాయి. సాధారణంగా వేడి ఎలక్ట్రానిక్స్ ఆయుష్షును తగ్గిస్తుంది, కానీ ఆ ప్రభావాన్ని గానీ SSD ఉష్ణోగ్రతను గానీ ఈ బాక్స్ మీద నేను కొలవలేదు.

    Fan ఎందుకు ముందు

    వేడెక్కే mini PC కి repaste అనేది మామూలుగా ఇచ్చే సలహా, అది సహాయపడి ఉండవచ్చు కూడా. కానీ దానికి ఇవి కూడా అవసరమయ్యేవి:

    • ముందుగా ఒక కాన్ఫిగరేషన్ బ్యాకప్;
    • 99 శాతం ఐసోప్రొపైల్ ఆల్కహాల్, పోగులు వదలని వైప్స్;
    • నెట్‌వర్క్ 45 నుంచి 60 నిమిషాలు ఆఫ్‌లైన్‌లో ఉండడం;
    • నేను ఎప్పుడూ చూడని స్క్రూలు, thermal pads ఉన్న సీల్ చేసిన కేస్‌ను తెరవడం.

    Fins మీద పడుకోబెట్టిన fan కి అవేవీ అవసరం లేదు, దాన్ని ఒక్క క్షణంలో తీసేయొచ్చు కూడా. దానికీ దాని నష్టాలు ఉన్నాయి. Fanless బాక్స్ దేనికోసమో దాన్నే ఇది వదులుకుంటుంది: శబ్దం లేకపోవడం, దుమ్ము లోపలికి రాకపోవడం, అరిగిపోయే కదిలే భాగం లేకపోవడం.

    అందుకే పెట్టే ముందే నియమం పెట్టుకున్నాను: fan ఉన్నా రాత్రి రీడింగులు ఇంకా 80ల్లోకి వెళ్తేనే repaste.

    Fan

    నేను Noctua NF-F12 5V PWM ఎంచుకున్నాను. Noctua స్పెసిఫికేషన్ ప్రకారం ఇది 120 mm, 5 V, 1,500 rpm వరకు, సాధారణంగా 0.65 W, పూర్తి వేగంలో 22.4 dB(A); బాక్స్‌లో ఒక USB పవర్ కేబుల్ ఉంటుంది. నా fan router లోని ఒక USB పోర్టుకు కనెక్ట్ అయి ఉంది. USB నుంచి పవర్ ఇస్తే fan కి వేగాన్ని చెప్పే సిగ్నల్ ఏదీ అందదు. సిగ్నల్ లేని PWM fan పూర్తి వేగంతో తిరుగుతుందని Noctua సొంత గైడ్ చెబుతుంది. Noctua దీని మీద “5V PWM version, not for use in PCs” అని గుర్తు పెడుతుంది, అంటే ఇది 5V PWM వెర్షన్, PC లలో వాడడానికి కాదు: PC లోని 12 V fan header దీనికి తగిన సప్లై కాదు.

    నా router మీద 120 mm fan పైభాగంలో ఎక్కువ భాగాన్ని కప్పుతుంది. Router పైభాగం పరిమాణానికి దగ్గరగా ఉండే fan ను ఎంచుకోండి. Noctua చిన్న పరిమాణాల్లోనూ 5 V వెర్షన్లు అమ్ముతుంది, ఉదాహరణకు 80 mm NF-A8 5V PWM. చౌకైన 5 V USB fan కూడా గాలిని కదిలిస్తుంది; నేను అలాంటిది ప్రయత్నించలేదు.

    15 అక్టోబర్‌న సుమారు 17:30కి దీన్ని పెట్టాను. ఇది పై fins మీద స్క్రూలు లేకుండా సమతలంగా పడుకుని ఉంది, వాటిలోకి కిందికి గాలి ఊదుతుంది. ఫోటో చూసి చదివినప్పుడు Claude మొదట గాలి దిశను తారుమారుగా చెప్పింది; ఫ్రేమ్‌లో అచ్చుపోసిన బాణాన్ని నేను చెక్ చేశాను. ఏ దిశ అయినా సహాయపడాలి, కానీ నేను కొలుస్తున్నది ఏ దిశనో తెలుసుకోవాలనుకున్నాను.

    router fins ఉన్న పైభాగం మీద సమతలంగా పడుకున్న Noctua fan, పై నుంచి చూసినప్పుడు నెట్‌వర్క్ పోర్టుల వైపు నుంచి router, పోర్టులకు కేబుల్స్ ఉన్నాయి, పైన fan ఉంది

    Router ఏమి నమోదు చేసింది

    OPNsense నిమిషానికి ఒకసారి CPU ఉష్ణోగ్రతను చదువుతుంది, గంటవారీ సగటులను వారాల తరబడి ఉంచుతుంది. మీ router ది ఎలా చదవాలో కింద ఉంది.

    16 సెప్టెంబర్ 2026 నుంచి fan పెట్టిన నాలుగు రోజుల తర్వాత వరకు router గంటవారీ సగటు CPU ఉష్ణోగ్రత లైన్ చార్ట్. 9 అక్టోబర్ వరకు ఇది సుమారు 65 నుంచి 74 °C మధ్య ఉంటుంది, 10 అక్టోబర్ క్లీన్-అప్ సమయంలో 77 °C గరిష్ఠానికి చేరుతుంది, తర్వాత సుమారు 60 నుంచి 71 °C మధ్య స్థిరపడుతుంది, 15 అక్టోబర్ 17:30కి fan పెట్టిన తర్వాతి గంటలో సుమారు 46 °C కి పడిపోయి అక్కడే ఉంటుంది.

    Router గంటవారీ archive నుంచి, cpu0 గంటవారీ సగటులు:

    కాలం గంటలు సగటు అతి తక్కువ గంట సగటు అతి ఎక్కువ గంట సగటు
    16 సెప్టెంబర్ – 9 అక్టోబర్ 567 69.7 °C 65.3 °C 73.7 °C
    11 అక్టోబర్ – 15 అక్టోబర్, fan పెట్టే వరకు 114 66.2 °C 60.5 °C 70.9 °C
    15 అక్టోబర్, fan పెట్టిన తర్వాత (నాలుగు రోజులు) 100 46.4 °C 42.6 °C 48.6 °C

    10 అక్టోబర్‌ను వదిలేశాను; కింద వివరించిన కాన్ఫిగరేషన్ క్లీన్-అప్ జరిగిన రోజు అది. Fan కి వెంటనే ముందున్న రోజులతో పోలిస్తే, fan సగటు నుంచి సుమారు 20 °C తగ్గించింది. ముందు, తర్వాత పరిధులు ఒకదానితో ఒకటి కలవవు: fan కి ముందు అత్యంత చల్లని గంట, fan తర్వాత అత్యంత వేడి గంట కంటే 12 °C ఎక్కువ వేడిగా ఉంది.

    నేను పెట్టిన నియమం రాత్రి రీడింగుల గురించి. 15 అక్టోబర్‌న నిమిషవారీ రికార్డు నుంచి 03:00–10:00 విండోను చదివాను, 16 అక్టోబర్‌న అదే విండోను మళ్ళీ చదివాను:

    cpu0, 03:00–10:00 15 అక్టోబర్, fan లేకుండా 16 అక్టోబర్, fan తో
    సగటు 65.6 °C 46.7 °C
    గరిష్ఠం 90.3 °C 73.6 °C
    80 °C లేదా అంతకు పైన ఉన్న రీడింగులు 19 0

    ఏ రీడింగూ 80ల్లోకి చేరలేదు. నియమం ప్రకారం కేస్ మూసే ఉంచాలి.

    నా నియమం ఒక్కొక్క రీడింగును వాడింది, ఒక్కొక్క రీడింగు ఎగుడుదిగుడుగా ఉంటుంది. ప్రతి రీడింగూ ఒక క్షణం విలువ మాత్రమే: 28 అక్టోబర్‌న వరుస నిమిషాల్లో 35.3, 68.2, 69.0, 35.7 °C వచ్చాయి. కొన్ని గంటల సగటు అయితే మెరుగైన పరీక్ష అయ్యేది. గంటవారీ సగటుల ప్రకారం తేడా ఇంకా ఎక్కువ: fan తర్వాత ఏ గంట సగటూ 48.6 °C దాటలేదు.

    లోతైన వివరణ: 15 అక్టోబర్ నిమిషవారీ విండోలు

    15 అక్టోబర్‌న నిమిషవారీ రికార్డు నుంచి చదివినవి.

    విండో, 15 అక్టోబర్ 2026 రీడింగులు సగటు మీడియన్ 95వ పర్సెంటైల్ గరిష్ఠం 80 °C లేదా పైన
    03:00–10:00, fan లేకుండా 420 65.6 °C 69.0 °C 79.8 °C 90.3 °C 19
    12:00–17:20, fan లేకుండా 320 65.5 °C 68.7 °C 80.1 °C 90.7 °C 16
    17:31–19:12, fan తో 101 46.0 °C 48.7 °C 60.5 °C 69.6 °C 0
    19:20–19:37, firmware అప్‌డేట్, రీబూట్ తర్వాత 17 54.1 °C 57.1 °C 70.8 °C 70.8 °C 0

    చివరి వరుస ఎక్కువగా ఉంది, ఎందుకంటే router అప్పుడే firmware update తర్వాత రీబూట్ అయి, ఆ సమయంలో సుమారు 2.7 మిలియన్ blocklist ఎంట్రీలను లోడ్ చేస్తూ ఉంది. అది విశ్రాంతి స్థితిలోని అంకె కాదు.

    ఇది ఏమి చూపిస్తుంది, ఏమి చూపించదు

    ఇక్కడ fan సరిపోయిందని ఇది చూపిస్తుంది. Repaste కూడా సహాయపడేది కాదని ఇది చూపించదు; నేను repaste ప్రయత్నించలేదు. Fan క్యాబినెట్ నుంచి వేడిని బయటకు తీయదు. అది క్యాబినెట్ గాలిని router fins గుండా బలవంతంగా పంపుతుంది. మూసిన క్యాబినెట్ వల్ల మొదలుపెట్టిన స్థితి మరింత చెడ్డగా ఉండింది, కాబట్టి ఇక్కడ వచ్చిన మెరుగుదల బహిరంగ గాలిలో వచ్చేదానికంటే బహుశా ఎక్కువ.

    • గది ఉష్ణోగ్రతను నేను కొలవలేదు. తగ్గుదల ఒక్క గంటలోనే వచ్చింది, ఒక గది ఒక గంటలో 20 °C చల్లబడదు. Router రోజువారీ పగలు-రాత్రి చక్రానికి కూడా కొద్దిగానే స్పందిస్తుంది: 16 సెప్టెంబర్ నుంచి 9 అక్టోబర్ వరకు, రోజులోని ప్రతి గంట సగటు 69.2, 70.3 °C మధ్యే ఉంది, అంటే సుమారు 1 °C హెచ్చుతగ్గు.
    • అదే సాయంత్రం firmware మారింది. 15 అక్టోబర్ 19:12కి router firmware అప్‌డేట్ అయింది. తగ్గుదల ముందే వచ్చింది: fan పెట్టడానికీ అప్‌డేట్‌కీ మధ్య ఉన్న 101 నిమిషాల సగటు 46.0 °C.
    • ఐదు రోజుల ముందు ఒక కాన్ఫిగరేషన్ క్లీన్-అప్ జరిగింది. 10 అక్టోబర్‌న నేను ఒక WireGuard VPN క్లయింట్‌ను, వాడని ఒక ప్రాక్సీ స్టాక్‌ను (Squid, ClamAV, Redis, వాటితో పాటు ఉండేవి), దానికి ట్రాఫిక్ పంపే NAT రూల్స్‌ను తీసేశాను; నా DNS blocklists ను కుదించాను; ఒక USB నెట్‌వర్క్ అడాప్టర్ ప్లగ్ తీసేశాను. గంటవారీ సగటు 16 సెప్టెంబర్ నుంచి 9 అక్టోబర్ వరకు 69.7 °C, 11 అక్టోబర్ నుంచి fan వరకు 66.2 °C. ఆ తగ్గుదల మూడు నాలుగు రోజుల్లో దశలవారీగా వచ్చింది; ఆ మార్పుల ప్రభావాన్ని వాతావరణం ప్రభావం నుంచి నేను వేరు చేయలేను. అందుకే పైన ఉన్న పోలిక fan కి వెంటనే ముందున్న రోజులను మాత్రమే వాడుతుంది.
    • పవర్ సెట్టింగులు ఏవీ మారలేదు. Router కాన్ఫిగరేషన్ చరిత్ర 13 అక్టోబర్ నుంచి ఉంది (30 రివిజన్లు). ఆ కాలంలో పవర్ సెట్టింగులు, thermal సెట్టింగులు, tunables లో ఏ మార్పూ అది చూపించదు.
    • లోడ్‌ను నేను నియంత్రించలేదు. ఇవి ఇంటి నెట్‌వర్క్ మీద మామూలు రోజులు.
    • ఇది ఒక క్యాబినెట్‌లోని ఒక router మాత్రమే.
    నేను నిరూపించని ఒక అనుమానం: dashboard

    13 అక్టోబర్‌న, సుమారు 20 గంటల అప్‌టైమ్ తర్వాత, ప్రాసెస్ వారీగా CPU సమయాన్ని పోల్చాను. DNS రిసాల్వర్ అయిన Unbound 16 సెకన్లు వాడింది, అంటే ఒక కోర్‌లో సుమారు 0.02 శాతం; ఆ సమయంలో అది నెట్‌వర్క్‌లోని పరికరాల నుంచి వచ్చే రోజుకు సుమారు 10,000 అనవసరమైన లుకప్‌లకు సమాధానం ఇస్తోంది. వెబ్ ఇంటర్‌ఫేస్‌ను, API ని నడిపే PHP ప్రాసెస్‌లు 5 నిమిషాల 9 సెకన్లు వాడాయి, సుమారు 20 రెట్లు ఎక్కువ; అప్పటికే ముగిసిపోయిన PHP workers ను ఆ స్నాప్‌షాట్ లెక్కలోకి తీసుకోలేదు.

    అయినా, 20 గంటల్లో 5 నిమిషాలు అంటే ఒక కోర్‌లో సుమారు 0.4 శాతం. కొన్ని సెకన్లకు ఒకసారి రిఫ్రెష్ అయ్యే విడ్జెట్‌లు ఉన్న dashboard తెరిచి ఉండడం ఉష్ణోగ్రతను పెంచి ఉంటే, అది చిన్న బర్స్ట్‌లలోనే. ఆ వారం నేను చూసిన కొన్ని 78 °C స్పైక్‌ల వెనుక ఆ బర్స్ట్‌లు ఉన్నాయని అనుమానించాను. దాన్ని నేను పరీక్షించలేదు.

    మీ సొంత router ను చదవడం

    OPNsense తన health రికార్డులను Reporting → Health కింద గ్రాఫ్‌లుగా చూపిస్తుంది. CPU ఉష్ణోగ్రత గ్రాఫ్‌ను చూడడానికి:

    1. బ్రౌజర్‌లో router వెబ్ ఇంటర్‌ఫేస్ తెరవండి: router ను నిర్వహించడానికి మీరు వాడే చిరునామాను అడ్రస్ బార్‌లో టైప్ చేసి, Enter నొక్కి, లాగిన్ అవ్వండి. చిరునామా మీకు తెలియకపోతే, router ను సెటప్ చేసిన వారిని అడగండి. router తన సొంత సెక్యూరిటీ సర్టిఫికెట్‌ను వాడుతుంది, కాబట్టి కనెక్షన్ ప్రైవేట్ కాదని బ్రౌజర్ హెచ్చరించవచ్చు; మీ router చిరునామాకు అది సాధారణమే. Advanced క్లిక్ చేయండి, తర్వాత ఆ చిరునామాకు కొనసాగించే లింక్‌ను క్లిక్ చేయండి (Chrome లో Proceed, Firefox లో Accept the Risk and Continue).
    2. మెనూలో Reporting → Health తెరవండి. పేజీ కొన్ని సెకన్లలో లోడ్ అవుతుంది, ఏదీ మార్చదు. అది తన రిపోర్ట్‌లను అంశాల వారీగా జాబితా చేస్తుంది.
    3. CPU ఉష్ణోగ్రత రిపోర్ట్‌ను పేజీలోని రిపోర్ట్‌ల జాబితాలో కనుగొనండి. అది లేకపోతే, System → Settings → Miscellaneous → Thermal Sensors తెరవండి; నాది “Intel Core CPU on-die thermal sensor (coretemp)” కు సెట్ అయి ఉంది. ఆ సెట్టింగ్ మార్చడం router ను మారుస్తుంది: ముందు పాత విలువను రాసి పెట్టుకోండి, Save* నొక్కండి, router రీడింగులు తీసుకునే వరకు కొన్ని నిమిషాలు వేచి ఉండండి. దాన్ని వెనక్కి తీసుకోవడానికి, పాత విలువను మళ్ళీ ఎంచుకోండి; ఈ సెట్టింగ్‌ను తిరిగి none కు పెట్టడానికి reboot అవసరం.

    అదే డేటా router API నుంచి GET /api/diagnostics/systemhealth/get_system_health/cputemp-system/0 వద్ద వస్తుంది. చివరి అంకె ఒక archive ను ఎంచుకుంటుంది: /0 అంటే నిమిషానికి ఒక విలువ, అంతకంటే పెద్ద అంకెల archives మరింత స్థూలంగా ఉంటాయి. ఒక్కొక్కటి ఎంత కాలం ఉంటుందనేది router ఉష్ణోగ్రత డేటాబేస్ ఎప్పుడు సృష్టించారనే దాని మీద ఆధారపడుతుంది:

    Archive నా router (పాత OPNsense నుంచి వచ్చిన డేటాబేస్) కొత్త OPNsense 26.x ఇన్‌స్టాల్
    /0 1 నిమిషం, 1,000 స్లాట్లు: 16 గంటల 40 నిమిషాలు 1 నిమిషం, 1,200 స్లాట్లు: 20 గంటలు
    /1 5 నిమిషాలు, 1,000 స్లాట్లు: సుమారు 3½ రోజులు 5 నిమిషాలు, 720 స్లాట్లు: 60 గంటలు
    /2 1 గంట, 1,000 స్లాట్లు: సుమారు 6 వారాలు 1 గంట, 1,860 స్లాట్లు: సుమారు 11 వారాలు
    /3 12 గంటలు, 3,000 స్లాట్లు: సుమారు 4 సంవత్సరాలు 1 రోజు, 2,284 స్లాట్లు: సుమారు 6 సంవత్సరాలు

    అప్‌గ్రేడ్‌ల సమయంలో OPNsense ఉన్న డేటాబేస్‌ను అలాగే ఉంచుతుంది, కాబట్టి పాత router పాత అమరికనే కొనసాగిస్తుంది. చివరి కాలమ్ 26.7 సోర్స్ కోడ్ నుంచి తీసుకున్నది; కొత్త ఇన్‌స్టాల్‌ను నేను చూడలేదు.

    దీని నుంచి రెండు విషయాలు తెలుస్తాయి. నిన్న రాత్రి నిమిషవారీ రికార్డును ఈ ఉదయమే చదవండి; సాయంత్రానికి ఆ నిమిషాలు పోతాయి, స్థూల సగటులు మాత్రమే మిగులుతాయి. ఇంకా, గంటల archive ఎంత పొడవుగా ఉంటుందంటే, మీరు ప్లాన్ చేయని ముందు-తర్వాత పోలికకు కూడా అది సరిపోతుంది. నేను fan పెట్టేనాటికే నా router లో ఒక నెల “ముందు” డేటా ఉంది.

    లోతైన వివరణ: archives లో ఏముంటుంది, గంటవారీ అంకెలు స్పైక్‌లను ఎందుకు దాచేస్తాయి

    API సగటులను మాత్రమే ఇస్తుంది. OPNsense లోని fetchData.py consolidation function AVERAGE గా ఉన్న round-robin archives ను మాత్రమే ప్రాసెస్ చేస్తుంది, ప్రతి archive కి ఒక “set” తయారుచేస్తుంది. Router ప్రతి నిమిషం సెన్సార్ నుంచి ఆ క్షణపు రీడింగ్ ఒకటి నిల్వ చేస్తుంది; ప్రతి గంటవారీ విలువ ఆ రీడింగుల సగటు. 91 °C అనే ఒక్క రీడింగ్ దాన్ని దాదాపు కదిలించదు.

    రీడింగ్ లేని స్లాట్లు ఖాళీ విలువలుగా వస్తాయి. అదే స్క్రిప్ట్ ఖాళీ స్లాట్లను ఒక సిరీస్ మొదట్లో మాత్రమే తొలగిస్తుంది. కాబట్టి archive లోని అన్నిటికంటే పాత స్లాట్లు ఖాళీగా ఉన్నప్పుడు, అంటే కొత్త డేటాబేస్‌లో, స్లాట్ల లెక్క archive పొడవును తక్కువగా చూపిస్తుంది. కింది snippet రీడింగులను, ఖాళీ స్లాట్లను వేరువేరుగా చూపిస్తుంది.

    లోతైన వివరణ: మీ router సారాంశం చూపించే ఒక console snippet (PC కోసం)

    Health గ్రాఫ్ ఆకారాన్ని చూపిస్తుంది. ఇది అంకెలను ప్రింట్ చేస్తుంది: ఒక archive కి సగటు, మీడియన్, 95వ పర్సెంటైల్, గరిష్ఠం, 80 °C కి చేరిన రీడింగులు ఎన్ని. ఇది router సొంత health API కి ఒక చదివే అభ్యర్థనను (ఒక GET) పంపుతుంది, ఏమీ మార్చదు.

    ప్రారంభించే ముందు

    • మీకు Chrome లేదా Firefox ఉన్న ఒక PC, Reporting → Health తెరవగల router వెబ్ ఇంటర్‌ఫేస్ లాగిన్ కావాలి.
    • మీరు బ్రౌజర్ డెవలపర్ console లో, router సొంత పేజీలో టైప్ చేస్తారు. ఏదీ ఇన్‌స్టాల్ చేయరు.
    • దీనికి రెండు మూడు నిమిషాలు పడుతుంది.
    • ఇది router లో గానీ PC లో గానీ ఏమీ మార్చదు, కాబట్టి వెనక్కి తీసుకోవాల్సింది ఏమీ లేదు. పూర్తయ్యాక console ను మూసివేయండి.
    • కింది పెట్టెల్లో Copy పెట్టె మొత్తాన్ని కాపీ చేస్తుంది. గీతల అంచు ఉన్న పెట్టె మీకు కనిపించవలసినది చూపిస్తుంది; దాన్ని మీరు టైప్ చేయరు.

    దశలు

    1. Chrome లేదా Firefox లో router వెబ్ ఇంటర్‌ఫేస్ తెరవండి: router ను నిర్వహించడానికి మీరు వాడే చిరునామాను అడ్రస్ బార్‌లో టైప్ చేసి, Enter నొక్కి, లాగిన్ అవ్వండి. మీకు OPNsense dashboard కనిపించాలి. లాగిన్ పేజీ రాకపోతే, చిరునామాను, PC హోమ్ నెట్‌వర్క్‌లో ఉందో లేదో చూడండి. బ్రౌజర్ కనెక్షన్ ప్రైవేట్ కాదని హెచ్చరిస్తే, పైన గ్రాఫ్ దశల్లోని 1వ దశలోని గమనికను చూడండి.
    2. ఏదైనా OPNsense పేజీలోనే ఉండి బ్రౌజర్ console తెరవండి: Windows, Linux లో Chrome అయితే Ctrl+Shift+J, Firefox అయితే Ctrl+Shift+K; Mac లో Cmd+Option+J లేదా Cmd+Option+K. పేజీ పక్కన లేదా కింద ఒక ప్యానెల్ తెరుచుకుంటుంది, టైప్ చేయడానికి ఒక లైన్‌తో. అది వేరే ట్యాబ్‌లో తెరుచుకుంటే, Console ట్యాబ్‌ను క్లిక్ చేయండి.
    3. కింది పెట్టెలో Copy క్లిక్ చేయండి. అది snippet మొత్తాన్ని కాపీ చేస్తుంది.

      // Paste into the browser console on any OPNsense page while logged in.
      // Read-only: one GET to the router's own health API. Changes nothing.
      (async () => {
        const LEVEL = 0; // archive: 0 is the finest (one value a minute); higher numbers are coarser. How many exist depends on the router.
        const url = '/api/diagnostics/systemhealth/get_system_health/cputemp-system/' + LEVEL;
        let d;
        try {
          const r = await fetch(url);
          if (r.status === 401) { console.log('HTTP 401: not logged in. Log in to the OPNsense web interface in this browser, then paste again.'); return; }
          if (r.status === 403) { console.log('HTTP 403: logged in, but this user may not read Reporting > Health. Use an account with that privilege.'); return; }
          if (!r.ok) { console.log('HTTP ' + r.status + ' from ' + url); return; }
          d = await r.json();
        } catch (e) {
          console.log('No JSON came back (' + e.message + '). Run this on an OPNsense page while logged in.'); return;
        }
        const series = d && d.set && d.set.data && d.set.data[0];
        if (!series || !Array.isArray(series.values)) { console.log('No temperature series at LEVEL ' + LEVEL + '. A higher LEVEL may not exist on this router; at LEVEL 0, check that Reporting > Health shows a CPU temperature graph.'); return; }
        const pts = series.values.filter(p => p[1] !== null && !isNaN(p[1]));
        const empty = series.values.length - pts.length;
        if (pts.length === 0) { console.log('The series ' + series.key + ' has no readings at this level.'); return; }
        const v = pts.map(p => p[1]).sort((a, b) => a - b);
        const n = v.length;
        const median = n % 2 ? v[(n - 1) / 2] : (v[n / 2 - 1] + v[n / 2]) / 2;
        const p95 = v[Math.min(n - 1, Math.ceil(0.95 * n) - 1)]; // nearest-rank
        const when = t => new Date(t).toLocaleString(); // your browser's time zone; each time marks the end of its interval
        console.log('Series ' + series.key + ', one value every ' + d.set.step_size + ' s');
        console.log('From ' + when(pts[0][0]) + ' to ' + when(pts[n - 1][0]) + ': ' + n + ' readings, ' + empty + ' empty slots');
        console.log('Average ' + (v.reduce((a, b) => a + b, 0) / n).toFixed(1) + ' °C, median ' + median.toFixed(1) +
          ', 95th percentile ' + p95.toFixed(1) + ', maximum ' + v[n - 1].toFixed(1));
        console.log('Readings at 80 °C or above: ' + v.filter(x => x >= 80).length);
      })();
    4. console లోని లైన్‌ను క్లిక్ చేసి, Ctrl+V తో (Mac లో Cmd+V) పేస్ట్ చేసి Enter నొక్కండి. బ్రౌజర్లు console లో పేస్ట్ చేయడాన్ని ఆపవచ్చు, ఎందుకంటే లాగిన్ అయిన పేజీలో తెలియని వ్యక్తి కోడ్‌ను పేస్ట్ చేయించడం ఒక తెలిసిన మోసం. అనుమతించే ముందు snippet ను చదవండి. బ్రౌజర్ “allow pasting” అని టైప్ చేయమని అడిగితే, దాని సందేశం చెప్పినట్టు చేసి, మళ్ళీ పేస్ట్ చేయండి.

    5. ఒకటి రెండు సెకన్లలో మీకు నాలుగు లైన్లు కనిపించాలి (“Promise” తో మొదలయ్యే లైన్‌ను పట్టించుకోకండి): సిరీస్ పేరు, రీడింగులు ఎన్ని, ఖాళీ స్లాట్లు ఎన్ని అనే వివరాలతో సమయ పరిధి, సారాంశ అంకెలు, 80 °C లేదా అంతకంటే ఎక్కువ ఉన్న రీడింగుల లెక్క. సమయాలు మీ బ్రౌజర్ టైమ్ జోన్‌లో ఉంటాయి; ప్రతి సమయం దాని వ్యవధి ముగిసిన క్షణాన్ని సూచిస్తుంది. నా router లో, 28 అక్టోబర్ 2026న, ఇది ఇలా ప్రింట్ చేసింది (సమయాలను నేను వదిలేశాను; వాటి ఫార్మాట్ మీ బ్రౌజర్ సెట్టింగ్‌లను బట్టి ఉంటుంది):

      Series cpu0temp, one value every 60 s
      From <start time> to <end time>: 1000 readings, 0 empty slots
      Average 43.9 °C, median 47.7, 95th percentile 57.8, maximum 72.5
      Readings at 80 °C or above: 0
    6. “HTTP 401” అంటే బ్రౌజర్ OPNsense లో లాగిన్ అయి లేదు: లాగిన్ అయి 4వ దశను మళ్ళీ చేయండి. “HTTP 403” అంటే Reporting → Health చూసే అనుమతి లేని యూజర్‌గా మీరు లాగిన్ అయ్యారు.

    7. గంటవారీ archive చదవడానికి, snippet ను ముందు ఒక సాధారణ టెక్స్ట్ ఎడిటర్‌లో పేస్ట్ చేయండి (Windows లో Notepad, Mac లో plain text కు సెట్ చేసిన TextEdit), const LEVEL = 0; ను const LEVEL = 2; కు మార్చండి, అక్కడి నుంచి మొత్తాన్ని కాపీ చేసి, 4, 5 దశలను మళ్ళీ చేయండి.
    8. ఆ సగటును అదే archive కు సంబంధించిన Reporting → Health గ్రాఫ్ స్థాయితో పోల్చండి. రెండూ సరిపోలాలి.
    9. పూర్తయ్యాక, ప్యానెల్‌ను దాని కుడి పైన ఉన్న × తో మూసివేయండి. router లో ఏదీ మార్చబడలేదు.

    తీర్పు

    కేస్ మూసే ఉంటుంది, paste దాని పెట్టెలోనే ఉంటుంది.

    మిగిలింది చిన్న పని. Fan ను బిగించండి, పైకి లేపండి: 10 నుంచి 15 mm రబ్బర్ కాళ్ళు దాన్ని స్థానంలో పట్టి ఉంచగలవు, దాని hub కింద ఉన్న fins కు గాలి చేరనివ్వగలవు; సమతలంగా పడుకున్న fan ఆ fins కు గాలి సరిగా అందనివ్వదు. Heatsinks మీద పెట్టే fans కు ఇది సాధారణ పద్ధతి; ఇక్కడ నేను దీన్ని కొలవలేదు. పక్క గ్రిల్‌కు అడ్డు లేకుండా చూడండి. క్యాబినెట్ మొత్తం వేరే సమస్య: fan router ను క్యాబినెట్ గాలి ఉష్ణోగ్రతకు దగ్గరగా మాత్రమే చల్లబరచగలదు, ఆ గాలి గది కంటే వేడిగా ఉంటుంది. దాన్ని నేను వేరుగా పరిశీలించాను, దాని గురించి తర్వాత రాస్తానేమో.

    Fan కి ముందు, ఈ వేడి కొత్త router చూడడానికి ఒక కారణంగా ఉండేది. ఇప్పుడు కాదు.

    వేడి అల్మరాలో fanless బాక్స్ ఉన్నవారికి నేను చెప్పేది

    1. Router ఇప్పటికే ఏమి నమోదు చేస్తుందో చదవండి, ఏదైనా తెరిచే ముందు. OPNsense లో అది Reporting → Health, లేదా పైన చెప్పిన API.
    2. మీ router లో ప్రతి archive ఎంత కాలం ఉంటుందో చెక్ చేసుకోండి. అది దాని డేటాబేస్ ఎప్పుడు సృష్టించారనే దాని మీద ఆధారపడుతుంది.
    3. ఏ ఫలితం వస్తే తర్వాతి దశకు వెళ్ళాలో నిర్ణయించుకోండి, ఏదైనా మార్చే ముందే.
    4. ఒక్కొక్క రీడింగును కాదు, సగటులను బట్టి తేల్చండి. వరుస నిమిషాల రీడింగుల మధ్య 30 °C తేడా ఉండవచ్చు.
    5. చౌకైన, వెనక్కి తీసుకోగల పరిష్కారాన్ని ముందు ప్రయత్నించండి, దాని నష్టాన్నీ బేరీజు వేయండి: శబ్దం, దుమ్ము లేకుండా ఉండాలని కొన్న బాక్స్‌కు fan ఆ రెండింటినీ తెస్తుంది.
    పదకోశం
    • Fanless (passive) cooling: కేసే heatsink; fan లేకుండా, ఉష్ణ వహనం, సహజ గాలి ప్రవాహం ద్వారా వేడి బయటకు పోతుంది.
    • Thermal paste / repaste: CPU కీ heatsink కీ మధ్య ఉండి, సూక్ష్మమైన ఖాళీలను నింపే పదార్థం. Repaste అంటే పాత పదార్థాన్ని శుభ్రంగా తుడిచి కొత్తది పూయడం.
    • P-core / E-core: ఒకే చిప్‌లో ఉండే Intel పెర్ఫార్మెన్స్ కోర్లు, ఎఫిషియెంట్ కోర్లు. Pentium Gold 8505 లో మొదటి రకం ఒకటి, రెండో రకం నాలుగు ఉన్నాయి.
    • TJUNCTION: చిప్‌లోనే Intel అనుమతించే అత్యధిక ఉష్ణోగ్రత. 8505 కి అది 100 °C.
    • PWM: pulse-width modulation; fan ఎంత వేగంగా తిరగాలో చెప్పే ఒక సిగ్నల్ వైర్.
    • Round-robin database (RRD): స్థిర పరిమాణం ఉన్న ఒక నిల్వ. ఇటీవలి డేటాను సూక్ష్మ వివరంగా, పాత డేటాను స్థూల సగటులుగా ఉంచుతుంది, అన్నిటికంటే పాత డేటాను తుడిచి దాని మీద రాస్తుంది.
    • మీడియన్ / 95వ పర్సెంటైల్: మీడియన్ అంటే మధ్యలో ఉండే రీడింగ్ (లేదా మధ్యలో ఉండే రెండు రీడింగుల సగటు); 95 శాతం రీడింగులు 95వ పర్సెంటైల్ వద్ద గానీ దాని కంటే కింద గానీ ఉంటాయి.
    • API: router ప్రోగ్రామింగ్ ఇంటర్‌ఫేస్; వెబ్ పేజీలు చూపించే డేటానే JSON గా ఇస్తుంది.
    • Tunables: OPNsense బూట్ సమయంలో వర్తింపజేసే kernel సెట్టింగులు; ఇవి System → Settings → Tunables కింద కనిపిస్తాయి.

    Thermal paste ยังอยู่ในกล่อง

    เมื่อวันที่ 15 ตุลาคม 2026 ผมมีทางแก้สองทางสำหรับปัญหาเดียววางอยู่บนโต๊ะ: thermal paste ARCTIC MX-7 หนึ่งหลอดขนาด 4 g และ fan Noctua ขนาด 120 mm ปัญหาคือ router ของผม ซึ่งเป็น mini PC แบบ fanless ที่รัน OPNsense อยู่ในตู้ไม้อัดแบบปิด วันก่อนหน้านั้น CPU ของมันขึ้นไปแตะ 91 °C

    คำแนะนำที่ผมเจอในอินเทอร์เน็ตคือให้เปิดเคสแล้วเปลี่ยน paste ใหม่ ผมติด fan ก่อน เพราะไม่ต้องใช้ไขควง ก่อนติด ผมตัดสินใจไว้ว่าผลแบบไหนจะทำให้ผมต้องกลับไปใช้ paste

    ผมไม่เคยต้องใช้มัน router บันทึกอุณหภูมิของตัวเองไว้ตลอดอยู่แล้ว ระหว่างวันที่ 16 กันยายนถึงช่วงเย็นของวันที่ 15 ตุลาคม ไม่มีชั่วโมงไหนที่ค่าเฉลี่ยต่ำกว่า 60 °C ในสี่วันหลังติด fan ไม่มีชั่วโมงไหนที่ค่าเฉลี่ยสูงกว่า 49 °C ตอนนี้ paste ยังอยู่ในกล่อง

    ผมทำงานนี้ร่วมกับ Claude ซึ่งเป็นโมเดล AI ของ Anthropic โดย Claude อ่านข้อมูลจาก router ผ่าน browser session ของผมเองได้ ผมเป็นคนเลือกชิ้นส่วน ติด fan และตั้งเกณฑ์ Claude ดึงบันทึกอุณหภูมิและคำนวณตัวเลข และเมื่อวันที่ 28 ตุลาคม ก็ดึงข้อมูลรายชั่วโมงของ router มาอีกครั้งสำหรับโพสต์นี้

    ตัวเครื่องและตู้

    router ตัวนี้เป็น mini PC แบบ fanless หกพอร์ต ขายภายใต้ชื่อ “Shenzhen Weibu” ข้างในเป็น Intel Pentium Gold 8505: performance core หนึ่งคอร์และ efficient core สี่คอร์ หก thread กำลังไฟพื้นฐาน 15 W และสูงสุด 55 W ในโหมด turbo ตามหน้าสเปกของ Intel มี RAM 20 GB และพอร์ต Intel I226-V 2.5 GbE หกพอร์ต รัน OPNsense 26.7 ตัวเคสคือ heatsink ด้านบนทั้งแผ่นเป็น fins

    มันอยู่ในตู้ไม้อัดแบบปิดร่วมกับอุปกรณ์เครือข่ายอื่น ตะแกรงแบบช่องบนแผงข้างตู้เป็นทางระบายลมร้อนทางเดียวที่ตั้งใจทำไว้

    router ก่อนติด fan มองจากด้านที่มีพอร์ต USB: ตัวเคสสีดำที่ด้านบนเป็นแผง fins อยู่ข้างตะแกรงแบบช่องบนแผงข้างของตู้

    91 °C อันตรายไหม? ตามตัวเลขของ Intel ไม่อันตราย หน้าเดียวกันระบุอุณหภูมิ junction สูงสุดของชิป (TJUNCTION) ไว้ที่ 100 °C และโปรเซสเซอร์ที่แตะขีดนั้นจะลดความเร็วตัวเองลง ไม่ใช่พัง อีกอย่าง 91 °C เป็นแค่ค่าสูงสุดในบรรดาค่าที่อ่านตามรอบ router อ่าน sensor นาทีละครั้ง ค่าที่พุ่งขึ้นระหว่างนั้นจึงไม่ถูกบันทึก ถึงอย่างนั้น ความร้อนก็กลายเป็นเหตุผลให้ผมมองหา router ตัวใหม่ ค่าเฉลี่ยรายชั่วโมงอยู่ราว 70 °C ทั้งกลางวันและกลางคืน และ SSD หน่วยความจำ และชิปเครือข่าย อยู่ในเคสร้อนอันเดียวกัน โดยทั่วไปความร้อนทำให้อุปกรณ์อิเล็กทรอนิกส์อายุสั้นลง แต่ผมไม่ได้วัดทั้งเรื่องนั้นและอุณหภูมิของ SSD บนเครื่องนี้

    ทำไมเลือก fan ก่อน

    การ repaste เป็นคำแนะนำปกติสำหรับ mini PC ที่ร้อน และก็อาจช่วยได้จริง แต่ถ้าทำ ก็จะต้อง:

    • สำรอง configuration ไว้ก่อน
    • แอลกอฮอล์ไอโซโพรพิล 99 เปอร์เซ็นต์ และผ้าเช็ดที่ไม่ทิ้งขุย
    • 45 ถึง 60 นาทีที่เครือข่ายออฟไลน์
    • เปิดเคสที่ปิดผนึกไว้ ซึ่งผมไม่เคยเห็นสกรูและ thermal pad ข้างในมาก่อน

    fan ที่วางบน fins ไม่ต้องใช้อะไรในรายการนั้นเลย และถอดออกได้ในวินาทีเดียว แต่มันก็มีต้นทุนของมันเอง มันทำให้เสียสิ่งที่เป็นเหตุผลของการมีเครื่อง fanless ไป: ไม่มีเสียง ไม่ดูดฝุ่นเข้า ไม่มีชิ้นส่วนเคลื่อนไหวที่สึกหรอ

    ผมจึงตั้งเกณฑ์ไว้ก่อนติด: จะ repaste ก็ต่อเมื่อค่าที่อ่านได้ช่วงกลางคืนยังขึ้นไปถึงระดับ 80 กว่า °C ทั้งที่ติด fan แล้ว

    ตัว fan

    ผมเลือก Noctua NF-F12 5V PWM สเปก ของ Noctua ระบุขนาด 120 mm ไฟ 5 V ความเร็วสูงสุด 1,500 rpm กินไฟปกติ 0.65 W และดัง 22.4 dB(A) ที่ความเร็วสูงสุด มีสาย USB สำหรับจ่ายไฟมาในกล่อง ตัวของผมเสียบอยู่กับพอร์ต USB ช่องหนึ่งของ router เอง เมื่อจ่ายไฟจาก USB fan จะไม่ได้รับสัญญาณความเร็ว และคู่มือของ Noctua เอง บอกว่า fan แบบ PWM ที่ไม่มีสัญญาณจะหมุนที่ความเร็วสูงสุด Noctua ระบุว่ารุ่นนี้เป็น “5V PWM version, not for use in PCs” ซึ่งหมายความว่า เป็นรุ่น 5V PWM ไม่ได้มีไว้ใช้กับ PC: fan header 12 V ของ PC เป็นแหล่งจ่ายไฟที่ผิดสำหรับมัน

    บน router ของผม fan ขนาด 120 mm คลุมด้านบนส่วนใหญ่ เลือก fan ที่มีขนาดใกล้เคียงกับด้านบนของ router Noctua ยังขายรุ่น 5 V ขนาดเล็กกว่านี้ด้วย เช่น NF-A8 5V PWM ขนาด 80 mm fan USB 5 V ที่ราคาถูกกว่าก็น่าจะเป่าลมได้เช่นกัน แต่ผมยังไม่เคยลอง

    ผมติดตั้งมันราว 17:30 ของวันที่ 15 ตุลาคม มันวางราบอยู่บน fins ด้านบน ไม่ได้ขันสกรูยึด และเป่าลมลงไปใน fins ตอนอ่านจากรูปถ่าย Claude เข้าใจทิศทางลมกลับด้านในตอนแรก ผมจึงดูลูกศรที่ขึ้นรูปไว้บนกรอบ แบบไหนก็น่าจะช่วยได้ แต่ผมอยากรู้ว่ากำลังวัดแบบไหนอยู่

    fan Noctua วางราบบน fins ด้านบนของ router มองจากด้านบน router มองจากด้านพอร์ตเครือข่าย มีสายเสียบอยู่ และมี fan วางอยู่ด้านบน

    สิ่งที่ router บันทึกไว้

    OPNsense อ่านอุณหภูมิ CPU นาทีละครั้ง และเก็บค่าเฉลี่ยรายชั่วโมงไว้หลายสัปดาห์ วิธีอ่านข้อมูลของ router คุณเองอยู่ด้านล่าง

    กราฟเส้นของอุณหภูมิ CPU เฉลี่ยรายชั่วโมงของ router ตั้งแต่ 16 กันยายน 2026 ถึงสี่วันหลังติด fan เส้นอยู่ระหว่างราว 65 ถึง 74 °C จนถึง 9 ตุลาคม ขึ้นสูงสุดที่ 77 °C ระหว่างการเก็บกวาด configuration เมื่อ 10 ตุลาคม จากนั้นทรงตัวระหว่างราว 60 ถึง 71 °C และลดลงเหลือราว 46 °C ในชั่วโมงหลังติด fan เวลา 17:30 ของวันที่ 15 ตุลาคม แล้วอยู่ที่ระดับนั้น

    ค่าเฉลี่ยรายชั่วโมงของ cpu0 จาก archive รายชั่วโมงของ router:

    ช่วงเวลา จำนวนชั่วโมง ค่าเฉลี่ย ชั่วโมงที่ต่ำสุด ชั่วโมงที่สูงสุด
    16 กันยายน – 9 ตุลาคม 567 69.7 °C 65.3 °C 73.7 °C
    11 ตุลาคม – 15 ตุลาคม ก่อนติด fan 114 66.2 °C 60.5 °C 70.9 °C
    15 ตุลาคม หลังติด fan (สี่วัน) 100 46.4 °C 42.6 °C 48.6 °C

    ผมไม่นับวันที่ 10 ตุลาคม ซึ่งเป็นวันเก็บกวาด configuration ที่เล่าไว้ด้านล่าง เมื่อเทียบกับไม่กี่วันก่อนติด fan ตัว fan ลดค่าเฉลี่ยลงราว 20 °C ช่วงค่าก่อนและหลังไม่ซ้อนทับกัน: ชั่วโมงที่เย็นที่สุดก่อนติด fan ยังร้อนกว่าชั่วโมงที่ร้อนที่สุดหลังติด fan อยู่ 12 °C

    เกณฑ์ที่ผมตั้งไว้ดูจากค่าที่อ่านได้ช่วงกลางคืน วันที่ 15 ตุลาคม ผมอ่านช่วง 03:00–10:00 จากข้อมูลรายนาที และวันที่ 16 ตุลาคม ผมอ่านช่วงเดียวกันอีกครั้ง:

    cpu0, 03:00–10:00 15 ตุลาคม ไม่มี fan 16 ตุลาคม มี fan
    ค่าเฉลี่ย 65.6 °C 46.7 °C
    ค่าสูงสุด 90.3 °C 73.6 °C
    จำนวนค่าที่ 80 °C ขึ้นไป 19 0

    ไม่มีค่าไหนขึ้นไปถึงระดับ 80 กว่า เกณฑ์บอกว่าให้ปิดเคสไว้ตามเดิม

    เกณฑ์ของผมใช้ค่าเดี่ยว และค่าเดี่ยวกระโดดไปมา แต่ละค่าคือค่า ณ ขณะเดียว: วันที่ 28 ตุลาคม นาทีที่ต่อกันอ่านได้ 35.3, 68.2, 69.0 และ 35.7 °C ถ้าใช้ค่าเฉลี่ยหลายชั่วโมงจะเป็นการทดสอบที่ดีกว่า เมื่อดูจากค่าเฉลี่ยรายชั่วโมง ความต่างยิ่งมากขึ้นอีก: หลังติด fan ไม่มีชั่วโมงไหนสูงกว่า 48.6 °C

    เจาะลึก: ช่วงเวลารายนาทีของวันที่ 15 ตุลาคม

    อ่านจากข้อมูลรายนาทีเมื่อวันที่ 15 ตุลาคม

    ช่วงเวลา วันที่ 15 ตุลาคม 2026 จำนวนค่า ค่าเฉลี่ย ค่ามัธยฐาน เปอร์เซ็นไทล์ที่ 95 ค่าสูงสุด จำนวนค่าที่ 80 °C ขึ้นไป
    03:00–10:00 ไม่มี fan 420 65.6 °C 69.0 °C 79.8 °C 90.3 °C 19
    12:00–17:20 ไม่มี fan 320 65.5 °C 68.7 °C 80.1 °C 90.7 °C 16
    17:31–19:12 มี fan 101 46.0 °C 48.7 °C 60.5 °C 69.6 °C 0
    19:20–19:37 หลังอัปเดต firmware และ reboot 17 54.1 °C 57.1 °C 70.8 °C 70.8 °C 0

    แถวสุดท้ายสูงกว่าเพราะ router เพิ่ง reboot หลังอัปเดต firmware และกำลังโหลดรายการ blocklist ราว 2.7 ล้านรายการ ไม่ใช่ตัวเลขตอนที่เครื่องอยู่ตัวแล้ว

    สิ่งที่ผลนี้แสดง และไม่ได้แสดง

    ผลนี้แสดงว่า fan เพียงพอสำหรับกรณีนี้ แต่ไม่ได้แสดงว่าการ repaste จะไม่ช่วยด้วย เพราะผมไม่เคยลอง fan ไม่ได้นำความร้อนออกจากตู้ มันบังคับให้อากาศในตู้ไหลผ่าน fins ของ router ตู้ที่ปิดทำให้จุดเริ่มต้นแย่กว่าปกติ ผลที่ได้ตรงนี้จึงน่าจะมากกว่าตอนที่ router ตั้งอยู่ในที่โล่ง

    • ผมไม่ได้วัดอุณหภูมิห้อง อุณหภูมิลดลงภายในหนึ่งชั่วโมง และห้องไม่เย็นลง 20 °C ในชั่วโมงเดียว นอกจากนี้ router ยังตอบสนองต่อรอบกลางวันกลางคืนเพียงเล็กน้อย: ตั้งแต่ 16 กันยายนถึง 9 ตุลาคม ค่าเฉลี่ยของแต่ละชั่วโมงในรอบวันอยู่ระหว่าง 69.2 ถึง 70.3 °C ต่างกันราว 1 °C
    • firmware เปลี่ยนในเย็นวันเดียวกัน router อัปเดต firmware เวลา 19:12 ของวันที่ 15 ตุลาคม อุณหภูมิลดลงก่อน: 101 นาทีระหว่างติด fan กับการอัปเดตมีค่าเฉลี่ย 46.0 °C
    • มีการเก็บกวาด configuration ห้าวันก่อนหน้านั้น วันที่ 10 ตุลาคม ผมลบ WireGuard VPN client, proxy stack ที่ไม่ได้ใช้ (Squid, ClamAV, Redis และส่วนประกอบที่มาด้วยกัน) และ NAT rule ที่ส่งทราฟฟิกเข้าไปหามัน ลดขนาด DNS blocklist และถอด USB network adapter ออก ค่าเฉลี่ยรายชั่วโมงอยู่ที่ 69.7 °C ตั้งแต่ 16 กันยายนถึง 9 ตุลาคม และ 66.2 °C ตั้งแต่ 11 ตุลาคมจนถึงตอนติด fan การลดลงนั้นเกิดเป็นขั้นๆ ในสามถึงสี่วัน และผมแยกผลของการเปลี่ยนแปลงเหล่านั้นออกจากผลของสภาพอากาศไม่ได้ นี่คือเหตุผลที่การเปรียบเทียบด้านบนใช้เฉพาะไม่กี่วันก่อนติด fan
    • การตั้งค่าพลังงานไม่ได้เปลี่ยน ประวัติ configuration ของ router ย้อนไปถึงวันที่ 13 ตุลาคม (30 revision) และไม่มีการเปลี่ยนการตั้งค่าพลังงาน การตั้งค่าความร้อน หรือ tunables ในช่วงนั้น
    • ผมไม่ได้ควบคุมโหลด นี่คือวันปกติของเครือข่ายในบ้าน
    • นี่คือ router ตัวเดียวในตู้ใบเดียว
    ข้อสันนิษฐานที่ผมไม่ได้พิสูจน์: dashboard

    วันที่ 13 ตุลาคม ตอน uptime ราว 20 ชั่วโมง ผมเปรียบเทียบ CPU time ของแต่ละ process Unbound ซึ่งเป็น DNS resolver ใช้ไป 16 วินาที ราว 0.02 เปอร์เซ็นต์ของหนึ่งคอร์ ระหว่างที่ตอบ lookup ที่ไม่ต้องการราว 10,000 ครั้งต่อวันจากอุปกรณ์ในเครือข่าย ส่วน process ของ PHP ที่ให้บริการ web interface และ API ใช้ไป 5 นาที 9 วินาที ซึ่งเป็นราว 20 เท่าของ Unbound และ snapshot นั้นไม่ได้นับ PHP worker ที่จบการทำงานไปแล้ว

    ถึงอย่างนั้น 5 นาทีใน 20 ชั่วโมงก็เป็นราว 0.4 เปอร์เซ็นต์ของหนึ่งคอร์ ถ้า dashboard ที่เปิดค้างไว้ ซึ่ง widget ของมันรีเฟรชทุกไม่กี่วินาที ทำให้อุณหภูมิสูงขึ้น ก็เกิดเป็นช่วงสั้นๆ ที่โหลดพุ่ง ผมสงสัยว่าช่วงโหลดพุ่งเหล่านั้นอยู่เบื้องหลังค่าพุ่ง 78 °C บางครั้งที่ผมเห็นในสัปดาห์นั้น ผมไม่ได้ทดสอบ

    อ่านข้อมูลจาก router ของคุณเอง

    OPNsense แสดงบันทึกสถานะของระบบเป็นกราฟที่ Reporting → Health วิธีดูกราฟอุณหภูมิ CPU:

    1. เปิด web interface ของ router ใน browser: พิมพ์ที่อยู่ที่คุณใช้จัดการ router ลงในแถบที่อยู่ กด Enter แล้ว log in ถ้าคุณไม่ทราบที่อยู่ ให้ถามคนที่ตั้งค่า router ให้คุณ ตัว router ใช้ใบรับรองความปลอดภัยของตัวเอง browser จึงอาจเตือนว่าการเชื่อมต่อไม่เป็นส่วนตัว สำหรับที่อยู่ของ router ของคุณเอง นั่นเป็นเรื่องที่คาดไว้ได้ คลิก Advanced แล้วคลิกลิงก์ที่ไปต่อยังที่อยู่นั้น (Proceed ใน Chrome, Accept the Risk and Continue ใน Firefox)
    2. ในเมนู เปิด Reporting → Health หน้านี้โหลดภายในไม่กี่วินาทีและไม่เปลี่ยนแปลงอะไร หน้านี้แสดงรายการ report แยกตามหัวข้อ
    3. หา report อุณหภูมิ CPU ในรายการ report ของหน้านั้น ถ้าไม่มี ให้เปิด System → Settings → Miscellaneous → Thermal Sensors ของผมตั้งไว้เป็น “Intel Core CPU on-die thermal sensor (coretemp)” การเปลี่ยนค่านี้เป็นการเปลี่ยน router: จดค่าเดิมไว้ก่อน กด Save* แล้วรอไม่กี่นาทีระหว่างที่ router อ่านค่า ถ้าจะยกเลิก ให้เลือกค่าเดิมอีกครั้ง ถ้าตั้งกลับเป็น none ต้อง reboot

    ข้อมูลชุดเดียวกันดึงได้จาก API ของ router ที่ GET /api/diagnostics/systemhealth/get_system_health/cputemp-system/0 ตัวเลขท้ายสุดใช้เลือก archive: /0 คือค่าหนึ่งค่าต่อนาที และตัวเลขที่สูงขึ้นจะหยาบขึ้น แต่ละ archive เก็บได้นานแค่ไหนขึ้นกับว่าฐานข้อมูลอุณหภูมิของ router ถูกสร้างเมื่อไร:

    Archive router ของผม (ฐานข้อมูลจาก OPNsense รุ่นเก่า) OPNsense 26.x ที่ติดตั้งใหม่
    /0 1 นาที, 1,000 ช่อง: 16 ชั่วโมง 40 นาที 1 นาที, 1,200 ช่อง: 20 ชั่วโมง
    /1 5 นาที, 1,000 ช่อง: ราว 3½ วัน 5 นาที, 720 ช่อง: 60 ชั่วโมง
    /2 1 ชั่วโมง, 1,000 ช่อง: ราว 6 สัปดาห์ 1 ชั่วโมง, 1,860 ช่อง: ราว 11 สัปดาห์
    /3 12 ชั่วโมง, 3,000 ช่อง: ราว 4 ปี 1 วัน, 2,284 ช่อง: ราว 6 ปี

    OPNsense เก็บฐานข้อมูลเดิมไว้ตลอดการอัปเกรด ดังนั้น router ที่ติดตั้งมาตั้งแต่ OPNsense รุ่นเก่าจึงยังใช้รูปแบบเดิม คอลัมน์สุดท้ายมาจาก source code ของ 26.7 ผมยังไม่เคยเห็นเครื่องที่ติดตั้งใหม่

    จากตรงนี้ได้สองเรื่อง ให้อ่านข้อมูลรายนาทีของเมื่อคืนภายในเช้านี้ พอถึงตอนเย็น ข้อมูลนาทีเหล่านั้นหายไปแล้ว เหลือแต่ค่าเฉลี่ยที่หยาบกว่า และ archive รายชั่วโมงก็ยาวพอสำหรับการเทียบก่อนและหลังที่คุณไม่ได้วางแผนไว้ ของผมมีข้อมูล “ก่อน” อยู่แล้วหนึ่งเดือนตอนที่ผมติด fan

    เจาะลึก: archive เก็บอะไรไว้ และทำไมตัวเลขรายชั่วโมงจึงซ่อนค่าที่พุ่งขึ้นชั่วครู่

    API ส่งให้แค่ค่าเฉลี่ย fetchData.py ของ OPNsense ประมวลผลเฉพาะ round-robin archive ที่มี consolidation function เป็น AVERAGE และสร้าง “set” หนึ่งชุดต่อหนึ่ง archive router เก็บค่าที่อ่านจาก sensor ณ ขณะหนึ่งไว้นาทีละหนึ่งค่า ค่ารายชั่วโมงแต่ละค่าคือค่าเฉลี่ยของค่าที่อ่านได้เหล่านั้น ค่าที่อ่านได้ 91 °C เพียงค่าเดียวแทบไม่ทำให้ค่านี้ขยับ

    ช่องที่ไม่มีค่า จะส่งกลับมาเป็นค่าว่าง สคริปต์เดียวกันตัดช่องที่ไม่มีค่าออกเฉพาะที่จุดเริ่มต้นของ series ดังนั้นจำนวนช่องจะน้อยกว่าความยาวของ archive เมื่อช่องที่เก่าที่สุดว่าง เช่นในฐานข้อมูลที่เพิ่งสร้าง snippet ด้านล่างรายงานจำนวนค่าที่อ่านได้และจำนวนช่องที่ไม่มีค่าแยกกัน

    เจาะลึก: console snippet สำหรับสรุปข้อมูล router ของคุณเอง (สำหรับ PC)

    กราฟ Health แสดงรูปร่างของข้อมูล snippet นี้พิมพ์ตัวเลขออกมา: ค่าเฉลี่ย ค่ามัธยฐาน เปอร์เซ็นไทล์ที่ 95 และค่าสูงสุด และจำนวนค่าที่อ่านได้ที่ถึง 80 °C ของ archive หนึ่ง snippet นี้ส่งคำขออ่านหนึ่งครั้ง (GET) ไปที่ health API ของ router เอง และไม่เปลี่ยนแปลงอะไร

    ก่อนเริ่ม

    • คุณต้องมี PC ที่มี Chrome หรือ Firefox และ login เข้า web interface ของ router ที่เปิด Reporting → Health ได้
    • คุณพิมพ์ใน developer console ของ browser บนหน้าของ router เอง คุณไม่ต้องติดตั้งอะไร
    • ใช้เวลาสองถึงสามนาที
    • ไม่เปลี่ยนแปลงอะไรบน router หรือ PC จึงไม่มีอะไรต้องย้อนกลับ ปิด console เมื่อทำเสร็จ
    • ในกล่องด้านล่าง ปุ่ม Copy จะคัดลอกทั้งกล่อง กล่องเส้นประแสดงสิ่งที่คุณควรเห็น คุณไม่ต้องพิมพ์มัน

    ขั้นตอน

    1. เปิด web interface ของ router ใน Chrome หรือ Firefox: พิมพ์ที่อยู่ที่คุณใช้จัดการ router ลงในแถบที่อยู่ กด Enter แล้ว log in คุณควรเห็น dashboard ของ OPNsense ถ้าไม่มีหน้า login ขึ้นมา ให้ตรวจที่อยู่ และตรวจว่า PC อยู่ในเครือข่ายภายในบ้าน ถ้า browser เตือนว่าการเชื่อมต่อไม่เป็นส่วนตัว ดูหมายเหตุในข้อ 1 ของขั้นตอนดูกราฟด้านบน
    2. อยู่ในหน้าใดก็ได้ของ OPNsense แล้วเปิด console ของ browser: กด Ctrl+Shift+J ใน Chrome หรือ Ctrl+Shift+K ใน Firefox บน Windows และ Linux หรือกด Cmd+Option+J หรือ Cmd+Option+K บน Mac แผงจะเปิดขึ้นข้างหรือใต้หน้าเว็บ พร้อมบรรทัดสำหรับพิมพ์ ถ้ามันเปิดที่แท็บอื่น ให้คลิกแท็บ Console
    3. คลิก Copy ในกล่องด้านล่าง มันคัดลอก snippet ทั้งหมด

      // Paste into the browser console on any OPNsense page while logged in.
      // Read-only: one GET to the router's own health API. Changes nothing.
      (async () => {
        const LEVEL = 0; // archive: 0 is the finest (one value a minute); higher numbers are coarser. How many exist depends on the router.
        const url = '/api/diagnostics/systemhealth/get_system_health/cputemp-system/' + LEVEL;
        let d;
        try {
          const r = await fetch(url);
          if (r.status === 401) { console.log('HTTP 401: not logged in. Log in to the OPNsense web interface in this browser, then paste again.'); return; }
          if (r.status === 403) { console.log('HTTP 403: logged in, but this user may not read Reporting > Health. Use an account with that privilege.'); return; }
          if (!r.ok) { console.log('HTTP ' + r.status + ' from ' + url); return; }
          d = await r.json();
        } catch (e) {
          console.log('No JSON came back (' + e.message + '). Run this on an OPNsense page while logged in.'); return;
        }
        const series = d && d.set && d.set.data && d.set.data[0];
        if (!series || !Array.isArray(series.values)) { console.log('No temperature series at LEVEL ' + LEVEL + '. A higher LEVEL may not exist on this router; at LEVEL 0, check that Reporting > Health shows a CPU temperature graph.'); return; }
        const pts = series.values.filter(p => p[1] !== null && !isNaN(p[1]));
        const empty = series.values.length - pts.length;
        if (pts.length === 0) { console.log('The series ' + series.key + ' has no readings at this level.'); return; }
        const v = pts.map(p => p[1]).sort((a, b) => a - b);
        const n = v.length;
        const median = n % 2 ? v[(n - 1) / 2] : (v[n / 2 - 1] + v[n / 2]) / 2;
        const p95 = v[Math.min(n - 1, Math.ceil(0.95 * n) - 1)]; // nearest-rank
        const when = t => new Date(t).toLocaleString(); // your browser's time zone; each time marks the end of its interval
        console.log('Series ' + series.key + ', one value every ' + d.set.step_size + ' s');
        console.log('From ' + when(pts[0][0]) + ' to ' + when(pts[n - 1][0]) + ': ' + n + ' readings, ' + empty + ' empty slots');
        console.log('Average ' + (v.reduce((a, b) => a + b, 0) / n).toFixed(1) + ' °C, median ' + median.toFixed(1) +
          ', 95th percentile ' + p95.toFixed(1) + ', maximum ' + v[n - 1].toFixed(1));
        console.log('Readings at 80 °C or above: ' + v.filter(x => x >= 80).length);
      })();
    4. คลิกที่บรรทัดใน console วางด้วย Ctrl+V (Cmd+V บน Mac) แล้วกด Enter browser อาจบล็อกการวางลงใน console เพราะการวางโค้ดของคนแปลกหน้าลงในหน้าที่ log in อยู่เป็นกลลวงที่รู้จักกัน อ่าน snippet ก่อนจะอนุญาต ถ้า browser ขอให้พิมพ์ “allow pasting” ให้ทำตามข้อความนั้น แล้ววางอีกครั้ง

    5. ภายในหนึ่งหรือสองวินาที คุณควรเห็นสี่บรรทัด (ไม่ต้องสนใจบรรทัดที่ขึ้นต้นด้วย “Promise”): ชื่อ series ช่วงเวลาพร้อมจำนวนค่าที่อ่านได้และจำนวนช่องที่ไม่มีค่า ตัวเลขสรุป และจำนวนค่าที่อ่านได้ที่ 80 °C ขึ้นไป เวลาที่แสดงเป็นเขตเวลาของ browser ของคุณ และแต่ละเวลาคือจุดสิ้นสุดของช่วงนั้น บน router ของผม เมื่อวันที่ 28 ตุลาคม 2026 มันพิมพ์ออกมาว่า (ผมตัดเวลาออก รูปแบบของเวลาเป็นไปตามการตั้งค่าของ browser ของคุณ):

      Series cpu0temp, one value every 60 s
      From <start time> to <end time>: 1000 readings, 0 empty slots
      Average 43.9 °C, median 47.7, 95th percentile 57.8, maximum 72.5
      Readings at 80 °C or above: 0
    6. “HTTP 401” แปลว่า browser ยังไม่ได้ log in เข้า OPNsense: ให้ log in แล้วทำข้อ 4 ซ้ำ “HTTP 403” แปลว่าคุณ log in ด้วย user ที่ไม่มีสิทธิ์เข้า Reporting → Health

    7. หากต้องการอ่าน archive รายชั่วโมง ให้วาง snippet ลงใน text editor ธรรมดาก่อน (Notepad บน Windows, TextEdit ที่ตั้งเป็น plain text บน Mac) เปลี่ยน const LEVEL = 0; เป็น const LEVEL = 2; คัดลอกทั้งหมดจากตรงนั้น แล้วทำข้อ 4 และ 5 ซ้ำ
    8. เทียบค่าเฉลี่ยกับระดับของเส้นกราฟ Reporting → Health ของ archive เดียวกัน ทั้งสองควรตรงกัน
    9. เมื่อทำเสร็จ ให้ปิดแผงด้วย × ที่มุมขวาบน router ไม่ถูกเปลี่ยนแปลงอะไร

    คำตัดสิน

    เคสยังปิดอยู่ และ paste ก็ยังอยู่ในกล่อง

    สิ่งที่เหลือเป็นงานเล็ก ยึด fan และยกมันขึ้น: ขายางสูง 10 ถึง 15 mm จะยึด fan ไว้กับที่ และให้ลมไปถึง fins ที่อยู่ใต้ดุมของมัน ซึ่ง fan ที่วางราบทำให้ขาดลม นั่นเป็นวิธีปฏิบัติทั่วไปสำหรับ fan ที่วางเหนือ heatsink ผมยังไม่ได้วัดผลกับเครื่องนี้ ดูแลไม่ให้มีอะไรบังตะแกรงข้างตู้ ตัวตู้ทั้งตู้เป็นอีกปัญหาหนึ่ง: fan ทำให้ router เย็นลงได้แค่เข้าใกล้อุณหภูมิของอากาศในตู้ ซึ่งอุ่นกว่าห้อง ผมไล่คิดเรื่องนั้นแยกต่างหาก และอาจเขียนเล่าทีหลัง

    ก่อนติด fan ความร้อนเป็นเหตุผลให้ผมมองหา router ตัวใหม่ ตอนนี้ไม่ใช่แล้ว

    สิ่งที่ผมจะบอกคนที่มีเครื่อง fanless อยู่ในตู้ที่อุ่น

    1. อ่านสิ่งที่ router บันทึกไว้อยู่แล้ว ก่อนจะเปิดอะไร บน OPNsense คือ Reporting → Health หรือ API ด้านบน
    2. ตรวจว่าแต่ละ archive บน router ของคุณเก็บข้อมูลได้นานแค่ไหน ขึ้นกับว่าฐานข้อมูลของมันถูกสร้างเมื่อไร
    3. ตัดสินใจไว้ก่อนว่าผลแบบไหนจะพาคุณไปขั้นต่อไป ก่อนจะเปลี่ยนอะไร
    4. ตัดสินจากค่าเฉลี่ย ไม่ใช่ค่าเดี่ยว ค่ารายนาทีที่ต่อกันอาจต่างกันได้ 30 °C
    5. ลองวิธีที่ต้นทุนต่ำและย้อนกลับได้ก่อน และชั่งดูว่ามันมีต้นทุนอะไร: fan นำเสียงและฝุ่นมาสู่เครื่องที่ซื้อมาเพื่อไม่ให้มีทั้งสองอย่าง
    อภิธานศัพท์
    • การระบายความร้อนแบบ fanless (passive): ตัวเคสคือ heatsink ความร้อนออกไปทางการนำความร้อนและการไหลเวียนของอากาศตามธรรมชาติ โดยไม่มี fan
    • Thermal paste / repaste: สารที่อยู่ระหว่าง CPU กับ heatsink ซึ่งเติมช่องว่างระดับจุลภาค การ repaste คือการเช็ดสารเก่าออกแล้วทาสารใหม่
    • P-core / E-core: performance core และ efficient core ของ Intel ในชิปตัวเดียว Pentium Gold 8505 มีแบบแรกหนึ่งคอร์และแบบหลังสี่คอร์
    • TJUNCTION: อุณหภูมิสูงสุดที่ Intel อนุญาตที่ตัวชิป สำหรับ 8505 คือ 100 °C
    • PWM: pulse-width modulation สายสัญญาณที่บอก fan ว่าต้องหมุนเร็วแค่ไหน
    • Round-robin database (RRD): ที่เก็บข้อมูลขนาดคงที่ ซึ่งเก็บข้อมูลล่าสุดแบบละเอียด และเก็บข้อมูลเก่าเป็นค่าเฉลี่ยที่หยาบกว่า โดยเขียนทับข้อมูลที่เก่าที่สุด
    • ค่ามัธยฐาน / เปอร์เซ็นไทล์ที่ 95: ค่ามัธยฐานคือค่าที่อยู่ตรงกลาง (หรือค่าเฉลี่ยของสองค่าที่อยู่ตรงกลาง) ค่าที่อ่านได้ 95 เปอร์เซ็นต์อยู่ที่หรือต่ำกว่าเปอร์เซ็นไทล์ที่ 95
    • API: ส่วนเชื่อมต่อของ router ที่ให้โปรแกรมอื่นเรียกใช้ได้ ให้ข้อมูลชุดเดียวกับที่หน้าเว็บแสดง ในรูป JSON
    • Tunables: การตั้งค่า kernel ที่ OPNsense ใช้ตอน boot อยู่ในรายการที่ System → Settings → Tunables
  • A parse error, a stalled upgrade, and fifteen years of silence

    A parse error, a stalled upgrade, and fifteen years of silence

    I knew this site was broken. I did not know for how long, or why, and for years I did not look. It sat at techblog.viveksanghi.com returning nothing, and every year that passed made it a slightly larger thing to open.

    When I finally opened it, the server turned out to have been keeping a precise record of what happened.

    I did the work over one evening with Claude, which matters to how this reads. I made the decisions and ran every command on my own server; the diagnosis, the scripts and several confident wrong turns came from the model. The wrong turns are in here too, because they were the useful part. Tech is a hobby for me. Law is what earns my living, and a fifteen-year-old broken WordPress had long since stopped being a thing I could justify an evening on. Having something that would grind through log files and SQL dumps without getting bored changed that arithmetic.

    What the server was saying

    The first question was whether anything was alive at all. The domain resolved to my host’s IP, same as my other sites, so DNS was fine. HTTPS failed on a certificate error. Over plain HTTP I got a 301 to the www hostname, then a 500 Internal Server Error with an empty response body.

    An empty 500 is a particular kind of unhelpful. No error on the page, no stack trace, nothing to search for. It means PHP died before producing output, with display_errors off, which on a production host it should be.

    The useful clue came from the access log rather than the error log:

    2026-09-02 21:24:28   200   /favicon.ico

    A 200. Static files were being served. That one line rules out most of what an empty 500 can mean. Apache was healthy, the virtual host was configured, the document root pointed at the right folder. Only PHP was dying.

    Which meant anything on the site that was not PHP could still be read. So we asked for the file every WordPress install ships and nobody ever deletes:

    curl http://techblog.viveksanghi.com/readme.html
    Version 3.1.2
    Semantic Personal Publishing Platform

    WordPress 3.1.2, released April 2011.

    The one-line cause

    The error log had been recording the same entry for years:

    [techblog.viveksanghi.com] [warn] mod_fcgid: stderr: PHP Parse error:
    syntax error, unexpected token "new" in
    /home/<user>/techblog.viveksanghi.com/wp-settings.php on line 219

    Line 219 of WordPress 3.1.2 reads:

    $wp_the_query =& new WP_Query();

    That =& is assignment by reference to a newly created object. It was correct in PHP 4, where objects were copied on assignment and the reference avoided the copy. PHP 5 made objects handle-based and the construction became pointless. It was deprecated in PHP 5.3 and removed in PHP 7.0.

    Removed, not deprecated. In PHP 7 and later this is not a warning or a runtime error. It is a parse error. PHP refuses to compile the file, so nothing in it executes, no error handler runs, no output is produced, and Apache has nothing to return but a bare 500.

    The site did not break from anything I did. It broke when my host moved past PHP 5, and it has been serving 500s to search engines and bots ever since.

    Could it be patched? The construction appears 252 times across WordPress core. PHP stops at the first one, but fixing that line only exposes the next. This is not a bug you repair. It is a language incompatibility, and the only answer is a newer WordPress.

    The timestamp in the root directory

    Sitting in the web root was a file called .maintenance, containing one line:

    <?php $upgrading = 1309848013; ?>

    WordPress writes that file when it begins a core update and deletes it when the update finishes. This one was never deleted.

    That Unix timestamp is 05/07/2011, 06:40 UTC.

    WordPress 3.2 was released on 04/07/2011. Alongside .maintenance were two directories in wp-content called wordpress-3.tmp and wordpress-31.tmp, the staging folders the updater uses while unpacking.

    So: the day after 3.2 came out, I clicked update. It stalled. It left the lock file, the temp directories, and a site still running 3.1.2.

    The lock file did no harm. WordPress ignores a .maintenance older than ten minutes, a sensible piece of defensive design and the reason the site kept serving afterwards. But it dates the incident to the minute.

    What the logs cannot tell you is what the site looked like when it stopped.

    It was running Grid Focus, a theme I had modified by hand over several years until not much of the original remained, with a stack of plugins I had chosen one at a time. The update took it down. I troubleshot for a while. Then life happened, and I lost interest the way you do when a thing stops being fun and starts being a chore.

    So I let it sit. Somewhere between 2020 and 2022 I paid a freelancer on Fiverr to bring it back, and for a while it worked. That did not last either.

    Both theme folders were still on the server when I finally went looking. grid_focus_public and gridfocus-v1.5.1b, sitting among fifty other themes I had collected and forgotten, exactly where I left them in 2011.

    Five years of nobody noticing

    The site did not go down in 2011. It went stale in 2011 and died some years later when PHP moved on. The first half is provable.

    An old wp-dbmanager install had been taking weekly database backups and leaving them in wp-content. There were 134 of them, 2.7 GB in total, running from 29/05/2011 to 31/07/2016.

    Comparing the oldest against the newest, by table:

    techblog_..._20110612.sql   posts: 274,916 bytes   comments: 370,174 bytes
    techblog_..._20160731.sql   posts: 274,916 bytes   comments: 370,174 bytes

    Byte for byte identical. Not a single post or comment changed between June 2011 and July 2016. The blog stopped in 2011 and the backups kept copying the same corpse every Sunday until they stopped too.

    But the dumps grew from 1.4 MB to 37 MB over those years. Something was expanding. Breaking the 2016 file down by table:

    12,549,505  wp_usermeta
       370,174  wp_comments
       342,650  wp_options
       274,916  wp_posts
        79,785  wp_postmeta

    Twelve and a half megabytes of user metadata against 275 KB of actual writing, reaching about 35 MB by the final backups. Open registration on an unpatched WordPress 3.1.2, and five years of bots signing up. The comments stayed clean, which I put down to Akismet and the captcha plugin, though I cannot prove that from the data. Nothing at all was guarding the registration form.

    Ninety per cent of my database was junk accounts.

    Deciding not to repair

    Reviving the 3.1.2 install was never really available. There is no supported upgrade path across fifteen years, and the parse error fires before WordPress prints a byte, so I could not reach an admin screen to start one.

    Rebuilding felt right for a less technical reason. The install carried 44 plugins and 51 themes. Among the plugins were disable-wordpress-core-update and disable-wordpress-plugin-updates, which explains a good deal about why it was still on 3.1.2. Copies of wordpress-28.zip through wordpress-284.zip sat in wp-content, publicly readable. There was a forum directory, empty, and two bbPress integration plugins pointing at it.

    A WordPress 3.1.2 install had been exposed to the open internet for roughly eight years before PHP killed it, and that version has a long published list of vulnerabilities. There is an irony worth sitting with: the parse error that took the site down has probably been protecting it since about 2019.

    So: current WordPress, content carried across, nothing else.

    Getting the content out

    The live database was reachable but not trustworthy, and I had 134 dumps provably unchanged since 2011. We took the last one and parsed it directly rather than restoring it anywhere.

    Two things came out of that which looking at the site would never have shown.

    The comments were duplicated. The table held 840. After normalising whitespace and stripping tags, only 606 were distinct. 234 were exact duplicates of another comment on the same post by the same author, each pair differing only in whether the
    tags had survived:

    id=7    2006-09-06 16:54   'Thanks for viewing my Blog. Well... I must say...'
    id=505  2006-09-06 11:24   'Thanks for viewing my Blog. Well... I must say...'

    The second copies sit in a contiguous block of IDs above 500. The database name pointed to Blogger, and the install had a blogger-blogspot-redirect plugin. A Blogger import run twice in 2006, once preserving HTML and once stripping it. Twenty years, and I never noticed, because on the page a duplicate comment just looks like somebody posting twice.

    The spam was not where anyone expected. Given the state of the usermeta table, the assumption was that comments would be full of pharma and casino links. A pattern search for the usual vocabulary returned zero matches. The volume by year decays the way real traffic does, 571 in 2006, 208 in 2007, then single and double digits as the blog went quiet, rather than flooding the way a farmed table does.

    The first attempt to find spam scored comments by link density. On a blog about Blogger and WordPress hacks that is a terrible signal, and it flagged 43 comments, most of them my own replies containing four or five links to code examples. Claude had produced that heuristic, run it, looked at the output and thrown it away unprompted, which was the right call and not one I would have caught if it had not shown me the list.

    The second pass went by author name and destination domain and found the real thing: thirteen keyword-anchor link drops, the kind where the author name is the product. “Mens Suit” linking to a suit retailer. “Website Design Atlanta”, three times. “beats for sale”. “laptop battery”. Short, on-topic enough, easy to approve by accident in 2010.

    That left 593 comments, all genuine, threading intact.

    There was also a post dated 26/12/2020 in a database dumped in 2016. A draft whose post_date carried a mistyped year, its post_modified correctly reading 27/12/2010. It had been sitting ten years in the future for a decade.

    What the rehearsal caught

    Rather than trust the import, we rehearsed it: MariaDB and WP-CLI in a throwaway container, the same WordPress version, a replica of the uploads folder, the real import file.

    Every expected number came back right except one. Attachments came out as zero instead of eighteen.

    The WordPress importer does not simply create attachment records. For each attachment it downloads the file from the URL in wp:attachment_url. In the container that URL was unreachable, so every attachment failed silently.

    On a real server it is worse than a clean failure. The URL points at the site being restored, over HTTPS, at a moment when the certificate has not been issued. And if the download does succeed, it writes a second copy of every file beside the ones already sitting in wp-content/uploads.

    The fix is to tell it not to:

    wp import export.xml --authors=create --skip=attachment

    and then register the files already on disk, in place:

    find wp-content/uploads -type f \( -iname '*.jpg' -o -iname '*.gif' \) \
      | grep -vE -- '-[0-9]+x[0-9]+\.[A-Za-z]+$' \
      | while read -r f; do wp media import "$f" --skip-copy; done

    The grep -v matters. Of 56 files in the uploads folder, 36 were WordPress’s own generated thumbnails. Without that filter every -150x150 crop becomes its own media library entry.

    Nobody would have found this by reading the script. It appeared only by running the whole thing end to end against a real database.

    Four ways the deploy script was wrong

    This is the part I would not have predicted before the evening started. The script that rebuilt the site was written for me to paste into an SSH session, and it had to be fixed four times before it ran clean. Every failure was caught by the script’s own preflight, before anything on my server was touched.

    getent does not exist on my host’s shell. The DNS check used it. The script would have aborted in preflight with a confusing error. Replaced with a PHP lookup, since PHP is guaranteed present there.

    pipefail and head do not mix. The script ran wp --info | head -3. head closes the pipe after three lines, wp gets SIGPIPE and exits 141, and set -o pipefail with set -e turns that into a silent abort. The three lines of output on my screen were the last thing the script printed before killing itself, and the failure looked like nothing at all.

    A $ in a password. My admin password was randomly generated and contained a dollar sign. Inside double quotes bash reads a $ followed by a digit or a name as a parameter; this one did not exist, and set -u correctly aborted. The config block now uses single quotes.

    --raw wrote an undefined constant. This one actually reached my server. The script ran wp config set WP_AUTO_UPDATE_CORE minor --raw, which writes define('WP_AUTO_UPDATE_CORE', minor); without quotes. In PHP 8 an undefined constant is a fatal error, so WordPress could not load at all, and the script reported it as “cannot reach the database” — which was wrong and sent me looking in the wrong place.

    There was a fifth, structural, caught before I ran anything: the original script tested the database connection after renaming my site directory. If the database had been unreachable, it would have moved my entire site aside and then died. That ordering was reversed so every destructive step sits behind a check that has already passed.

    I record these because the honest version of “an AI helped me fix my site” includes the four times it handed me something broken. What made it work was not that the output was right first time. It was that each failure was cheap, legible, and caught before it cost anything.

    The redirect loop I caused myself

    With WordPress installed and content imported, the site returned a redirect loop. techblog.viveksanghi.com redirected to www.techblog.viveksanghi.com, which redirected straight back, forever.

    We assumed the host was misconfigured. I opened a support ticket saying so. One command showed we were half wrong:

    curl -sI http://techblog.viveksanghi.com/readme.html      → 301
    curl -sI http://www.techblog.viveksanghi.com/readme.html  → 200 OK

    A static file that exists on disk gets redirected at the bare hostname and served at www. That first redirect happens above .htaccess, in the host’s virtual host configuration, and nothing on my side could override it. That half was the host’s, and they removed it inside a couple of hours when asked properly.

    The second redirect was mine. Static files at www served fine and only WordPress-handled paths bounced. That is redirect_canonical doing its job, because siteurl and home were set to the bare hostname while the server was serving www. Each half behaved correctly. Together they were an infinite loop.

    Testing a static file rather than the homepage is what separated them. On the homepage both redirects are in play and the trace tells you nothing about which layer owns which. I cancelled the first ticket and filed a more accurate one.

    What I would tell someone with a site in this state

    Test a static file first. Whether readme.html serves tells you in one request whether the web server is broken or only PHP is. Almost everything that followed came out of that one 200.

    The error log is the whole answer, and it is not in the panel. The hosting control panel showed access logs and traffic graphs for days. The actual parse error, repeating identically for years, was in a file on disk.

    Check whether your content changed before you value your backups. 134 weekly backups sound like excellent hygiene. Comparing the first against the last showed 134 copies of the same 2011 content, with only the spam growing. Backup count measures nothing.

    Rehearse the restore. A throwaway database and a full dry run took under an hour and caught a defect that would have cost the entire media library, silently, with a success message.

    Suspect your own configuration before your host’s. I was three quarters of the way to blaming my host for a redirect loop I had created myself.

    If you are working with a model, make it show you its output, not just its conclusions. Every one of the four script defects and the bad spam heuristic surfaced because something got printed and looked wrong. None of them surfaced from reading the code.

    The site is back. Seventy-five posts, 17/04/2006 to 25/05/2011, and 593 comments, on WordPress 7.1 with a clean database and no plugins carried across.

    Sixty-eight images in the older posts still point at photos1.blogger.com and the bp1 to bp3 hosts, which Google retired years ago. Those have been broken far longer than the site was, and there is nothing left to restore them from. I am inclined to leave them, with a note. A blog that ran from 2006 should be allowed to show its age somewhere.

  • Blogging on custom domains using Blogger and WordPress with and without self hosting

    ‘lo,

    In this article I will explain how you can:

    1. Blog on a custom domain (eg. www.<yourname>.com) while not having to buy any hosting space on the web (Will cover both Blogger and WordPress)

    2. Blog on a custom domain while also having custom hosting (Will cover only wordpress and explain how to migrate blogger blogs to custom/self-hosted wordpress)

    I understand that many readers may question the need for this article when there are plenty or articles on the web. However I will try to make it very simple and easy to follow with judicious use of screenshots to make life simple.

    Before proceeding, let’s note that one can always start of a free blog on popular blogging platforms like Google’s Blogger or WordPress. The URL of a blog on these free services will be like:

    <example>.blogspot.com

    <example>.wordpress.com

    If you are new to blogging, I recommend that you first try out hosting via these free platforms and see if you are able to maintain a good posting frequency. Once seasoned, go ahead and buy web hosting etc and host the blog by yourself.

    Blog on a custom domain (eg. www.<yourname>.com) while not having to buy any hosting space on the web (Will cover both Blogger and WordPress)

    If you have a blog on Blogger or WordPress.com, you might be pleased to know that both these platforms allow you to buy a custom domain name and make that the URL address of your blog.

    Blogger

    blogger1

    1. To view the custom domain settings facility in your blogger account, just go to the settings -> publishing area as shown in the image above (expand image to read the instructions or just follow the on screen instructions in your account. It’s very easy!)

    Click to expand image (opens in a new tab/window)

    2. If you choose to buy a domain from Google, use this page as shown in the image above (read the price and the time period for which you are paying very carefully). As of now Google is using godaddy.com as partner for the domain name registrations and is also providing Google Apps on the domain. Which probably means you can have an email address like <yourname>@<yourdomain>.com .

    3. However, if you have already bought a domain elsewhere, then click on the “Switch to advanced settings” link. You will be present with a page which looks like this:

    Click to expand image (Opens in a new tab/window)

    4. Click on the link “setup instructions” and read it very carefully before you proceed with this step. You will have to create a CNAME (Canonical Name) record. This will make your domain point to Google’s servers such that when someone visits your domain, the request is forwarded to Google servers and they can fetch the appropriate blog (i.e. your blogspot blog) and display it to the visitor.

    Blogger help provides specific instructions on setting up CNAME for certain domain providers. If you do not plan to buy your domain from Google and then I recommend buying it from one of the service providers listed on that page.

    This step can be troublesome and you may feel free to contact me if you need any assistance. However note that I may be slow in responding and the real fun is in trying it out on your own 🙂

    5. Once everything is done, enter the word verification and save your settings. Give it some time and then your blog will start working on your custom domain URL. Your old blogspot address will automatically redirect to your new custom domain.

    As always, if you face problems, you may redirect your questions to me and I will direct you in the right direction 😛

    WordPress

    If you have not already purchased a domain, then just like Blogger, wordpress also allows you to purchase a domain + redirect your wordpress.com blog to it for USD 15.00 (on this date).

    You can also have your custom email by using Google apps on this newly purchased domain (learn more)

    Buy a domain from wordpress and use it for your wordpress.com blog

    Upgrades -> Domains

    1. Go to the “domains” section under “upgrades” on your wordpress.com dashboard (See the image).

    2. On the page that appears, enter the domain you wish to use for your blog and click on “Add Domain to Blog” button (See the image below). A page will appear asking you to buy 15 credits to complete this transaction (unless you already have credits in your account). Note that you must have a Paypal account to purchase credits (currently 1 credit = USD 1.00).

    wordpress2

    3. Then you have to make sure (refer to the image below) that your newly purchased domain is recognized as your blog URL on the “domains” page and your wordpress.com blog redirects to your custom domain (also called domain mapping).

    Click to expand image (Opens in a new tab/window)

    That’s it. You are ready.

    You might want to learn more about managing domains purchased through wordpress.

    Using your separately purchased domain for your wordpress.com blog

    1. Visit this link and setup your domain to be used in wordpress domain mapping process. All you have to do is add the nameservers shown there to your domain. Remove any existing nameservers from your domain.

    Click to expand image. Opens in a new window/tab.

    2. Once your domain is ready go to the “domains” section under upgrades, on your wordpress.com dashboard. Enter the domain name you wish to use as shown in the image above and click on the “Add Domain to Blog” button. If your nameservers are set correctly and have propagated, then WordPress will allow you to buy 10 credits to enable this domain mapping.

    3. Now go to step 3 in the previous section (above) and you will be ready

    If you ever have any problems regarding domain mapping, please do visit this link to seek help.

    Alternate way to buy WordPress credits

    Log into your wordpress.com account go to the gifts section under upgrades as shown in the image below:

    wordpress

    While this page will allow you to gift the credits to other wordpress users, you may simply use it to purchase credits for your wordpress.com account.

    I hope this article will make life simpler for everybody who is new to blogging platforms. Stay tuned for my next article where I will talk about having a blog on a custom domain with custom hosting.