You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Bash脚本生成有效的唯一本地地址(ULA)?

Local ULA Generator Scripts (RFC 4193 Compliant)

Hey there! I totally get the frustration with flaky online ULA generators—having a local, reliable script is way better. Below are two straightforward, offline scripts that follow the RFC 4193 specs to generate valid Unique Local Address prefixes (the most common use case is a /48 prefix for subnetting).

Bash Script

This uses openssl for cryptographically secure random number generation (most Unix-like systems have this pre-installed):

#!/bin/bash
# Generates a RFC 4193 compliant ULA /48 prefix

# Generate 5 random bytes (40 bits) for the global ID section
global_id=$(openssl rand -hex 5)

# Split the 10-character hex string into IPv6-friendly segments
part1=${global_id:0:2}
part2=${global_id:2:4}
part3=${global_id:6:4}

# Build the final ULA prefix
ula_prefix="fd${part1}:${part2}:${part3}::/48"

echo "Generated ULA Prefix: $ula_prefix"

How to use:

  1. Save this as generate-ula.sh
  2. Make it executable: chmod +x generate-ula.sh
  3. Run it: ./generate-ula.sh

Python Script

If you prefer Python (no external dependencies beyond the standard library):

import secrets
import string

def generate_ula_prefix():
    # Generate 10 random lowercase hex chars (40 bits for the global ID)
    global_id = ''.join(secrets.choice(string.hexdigits.lower()) for _ in range(10))
    # Split into segments for proper IPv6 formatting
    part1 = global_id[:2]
    part2 = global_id[2:6]
    part3 = global_id[6:10]
    # Construct the RFC-compliant ULA /48 prefix
    return f"fd{part1}:{part2}:{part3}::/48"

if __name__ == "__main__":
    print(f"Generated ULA Prefix: {generate_ula_prefix()}")

How to use:

  1. Save this as generate-ula.py
  2. Run it: python3 generate-ula.py

Key Notes

  • Both scripts generate a /48 prefix, which is the recommended size for home/office networks (you can create up to 65536 /64 subnets from it)
  • The global ID is generated with cryptographically secure randomness, so the chance of collision is extremely low (far lower than any practical concern)
  • If you need a full host address instead of a prefix, you can extend the result—for example: fdxx:xxxx:xxxx:0001::1/128 (replace 0001 with your subnet ID and ::1 with the host address)
  • These scripts run entirely offline, so you don't have to worry about online tool downtime or privacy risks

内容的提问来源于stack exchange,提问作者Benoit-Pierre DEMAINE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:09:21