taubyte-hosts-file-editor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Hosts File Editor

Hosts文件编辑器

When to use

使用场景

Use this skill when:
  • the user wants to open Dream resources by hostname in browser
  • local
    *.localtau
    domains need to resolve on the current machine
  • curl tests should avoid manual
    Host
    headers
在以下场景使用该技能:
  • 用户希望在浏览器中通过主机名打开Dream资源
  • 当前机器需要解析本地
    *.localtau
    域名
  • curl测试需避免手动设置
    Host
    请求头

Inputs

输入项

  • One or more FQDNs (for example
    abc123.default.localtau
    )
  • Target IP (default
    127.0.0.1
    for Dream local)
  • OS (
    windows
    ,
    linux
    , or
    macos
    )
  • 一个或多个FQDN(例如
    abc123.default.localtau
  • 目标IP(Dream本地环境默认值为
    127.0.0.1
  • 操作系统(
    windows
    linux
    macos

Hosts file paths

Hosts文件路径

  • Windows:
    C:\Windows\System32\drivers\etc\hosts
  • Linux/macOS:
    /etc/hosts
  • Windows:
    C:\Windows\System32\drivers\etc\hosts
  • Linux/macOS:
    /etc/hosts

Procedure

操作步骤

  1. Validate each FQDN before writing:
    • non-empty
    • no scheme/path/port
    • no duplicates
  2. Read current hosts file.
  3. Ensure a section marker exists:
    • # Taubyte Local Domains
  4. For each FQDN, ensure exactly one mapping line:
    • 127.0.0.1 <fqdn>
  5. If an entry exists with a different IP, update it to target IP.
  6. Preserve unrelated lines and comments.
  7. Write changes with elevated permissions.
  8. If elevation fails, provide exact manual steps and content to append.
  1. 写入前验证每个FQDN:
    • 非空
    • 不包含协议/路径/端口
    • 无重复项
  2. 读取当前hosts文件。
  3. 确保存在分段标记:
    • # Taubyte Local Domains
  4. 为每个FQDN确保仅有一条映射行:
    • 127.0.0.1 <fqdn>
  5. 如果存在IP不同的条目,将其更新为目标IP。
  6. 保留无关的行和注释。
  7. 使用提升的权限写入更改。
  8. 如果提权失败,提供精确的手动步骤和要追加的内容。

Automation policy

自动化策略

  • Always attempt automatic update first (idempotent write, no duplicates).
  • On Windows, try elevated write path first; if blocked, switch to manual fallback immediately with exact lines.
  • After update attempt (success or fallback), run verification curl checks so execution can continue.
  • 始终优先尝试自动更新(幂等写入,无重复项)。
  • 在Windows系统上,优先尝试提权写入路径;如果被阻止,立即切换到手动回退方案并提供精确的行内容。
  • 更新尝试后(无论成功还是回退),运行curl验证检查,以便执行流程可以继续。

Safety rules

安全规则

  • Never remove unrelated host mappings.
  • Never add URL prefixes such as
    http://
    or
    https://
    .
  • Never include ports/paths in hosts file lines.
  • Prefer idempotent updates (re-running should not duplicate entries).
  • 永远不要删除无关的hosts映射。
  • 永远不要添加
    http://
    https://
    等URL前缀。
  • 永远不要在hosts文件行中包含端口/路径。
  • 优先使用幂等更新(重复执行不应产生重复条目)。

Verification

验证步骤

Run at least one check after edits:
bash
curl "http://<fqdn>:<port>/"
Or verify direct routing without hosts dependency:
bash
curl --resolve "<fqdn>:<port>:127.0.0.1" "http://<fqdn>:<port>/"
If using browser, open:
text
http://<fqdn>:<port>/
编辑后至少运行一项检查:
bash
curl "http://<fqdn>:<port>/"
或者验证不依赖hosts的直接路由:
bash
curl --resolve "<fqdn>:<port>:127.0.0.1" "http://<fqdn>:<port>/"
如果使用浏览器,打开:
text
http://<fqdn>:<port>/

Windows manual fallback (if no elevation)

Windows手动回退方案(无法提权时)

  1. Open Notepad as Administrator.
  2. Open
    C:\Windows\System32\drivers\etc\hosts
    (All Files filter).
  3. Append:
    • # Taubyte Local Domains
    • 127.0.0.1 <fqdn>
    • (repeat one line per FQDN)
  4. Save.
  1. 以管理员身份打开记事本。
  2. 打开
    C:\Windows\System32\drivers\etc\hosts
    (选择“所有文件”筛选器)。
  3. 追加以下内容:
    • # Taubyte Local Domains
    • 127.0.0.1 <fqdn>
    • (每个FQDN对应一行)
  4. 保存文件。