V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
beijiaoff
V2EX  ›  宽带症候群

请问 ddns 能否报告一个内网 ip 地址上去。

  •  
  •   beijiaoff · 257 天前 · 2506 次点击
    这是一个创建于 257 天前的主题,其中的信息可能已经有所发展或是发生改变。

    场景是需要用域名代替一个局域网的动态 ip 。

    16 条回复    2022-09-28 22:10:56 +08:00
    xipuxiaoyehua
        1
    xipuxiaoyehua  
       257 天前 via iPhone
    局域网内为啥还需要动态 ip 哈哈哈哈
    icySoda
        2
    icySoda  
       257 天前 via iPhone
    cloudflare 可以
    royzheng
        3
    royzheng  
       257 天前
    可以
    Dkngit
        4
    Dkngit  
       257 天前
    自己写程序对接 DNS 服务商的 API ,提交 IP 更新
    AoEiuV020CN
        5
    AoEiuV020CN  
       257 天前
    能,但都局域网了,静态 ip 或者 dhcp 静态分配不是更香吗,
    olaloong
        6
    olaloong  
       257 天前
    当然能,我用的 dns.he.net 的服务,结合定时任务每 10 分钟报告一次网卡 ip ,脚本也简单

    ---

    $ddns_domain=""
    $ddns_key=""

    $wlan_ip=(Get-NetIPAddress -InterfaceAlias WLAN -AddressFamily IPv4).IPAddress

    $ddns_url="http://dyn.dns.he.net/nic/update?hostname=$ddns_domain&myip=$wlan_ip"

    $netAssembly = [Reflection.Assembly]::GetAssembly([System.Net.Configuration.SettingsSection])
    if ($netAssembly) {
    $bindingFlags = [Reflection.BindingFlags] "Static,GetProperty,NonPublic";
    $settingsType = $netAssembly.GetType("System.Net.Configuration.SettingsSectionInternal");
    $instance = $settingsType.InvokeMember("Section", $bindingFlags, $null, $null, @());
    if($instance) {
    $bindingFlags = "NonPublic","Instance";
    $useUnsafeHeaderParsingField = $settingsType.GetField("useUnsafeHeaderParsing", $bindingFlags);
    if($useUnsafeHeaderParsingField) {
    $useUnsafeHeaderParsingField.SetValue($instance, $true);
    };
    };
    };

    $pair = "$($ddns_domain):$($ddns_key)"
    $encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Pair))
    $headers = @{ Authorization = "Basic $encodedCredentials" }

    Invoke-WebRequest -Uri $ddns_url -Method Get -Headers $headers
    singerll
        7
    singerll  
       257 天前
    @xipuxiaoyehua @AoEiuV020CN 很多场景很难固定的,比如物联网卡组成的局域网就没办法固定每张 sim 卡的 ip 。
    xipuxiaoyehua
        8
    xipuxiaoyehua  
       257 天前
    @singerll dns 解析的时候地址填什么都无所谓的,dns 服务商都有更新解析记录的 api 接口,直接调用接口就可以了
    neroxps
        9
    neroxps  
       257 天前
    哈哈,很明显这种需求就是没有局域网权限。
    lixinrui000
        10
    lixinrui000  
       257 天前
    可以,在内网里面我就这样干,但是注意 dnsmasq 等 DNS 服务器要关闭过滤本地地址功能。
    LnTrx
        11
    LnTrx  
       257 天前
    DDNS 的本质就是通过 API 更新 DNS 记录。只要能获取到地址、构造 API 请求,自然就不成问题。
    wzdxy
        12
    wzdxy  
       256 天前
    既然是局域网用 openwrt 直接修改 dns 就行吧
    lsylsy2
        13
    lsylsy2  
       255 天前 via Android
    注意你家的 dns 服务器需要开启 rfc1918
    Marionic0723
        14
    Marionic0723  
       254 天前 via Android
    Openwrt 在设置里打开「允许非公网 IP 」即可
    datou
        15
    datou  
       254 天前
    局域网内直接用 hostname 访问不就行了?

    还折腾啥域名。。。
    lihaohenqiang
        16
    lihaohenqiang  
       252 天前 via iPhone
    城域网可以试试,别的没啥用
    关于   ·   帮助文档   ·   博客   ·   nftychat   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   913 人在线   最高记录 5634   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 19:11 · PVG 03:11 · LAX 12:11 · JFK 15:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.