Synology sets up public network IPv6 mode domain name resolution access

1.Environmental description

Internet access: Telecom optical modem + tplink router (sent by Telecom)
Synology: DSM 7.1.1-42962 Update 2
Domain name service provider: Tencent Cloud

2. Optical cat settings

2.1 Obtain the Super User Password of Guangmao

Dial Telecom 10000

2.2 Modify the optical modem to bridge mode

slightly

3.Router settings

3.1 Router dial-up Internet access

Log in to the TP-LINK router as an administrator (the general login page address is http://192.168.1.1);
enter: Routing Settings -> Internet Settings, select "Broadband Dial-up Internet Access" as the Internet access method, and fill in the previously recorded broadband account and Password and click the "Connect" button
Please add image description

3.2 Enable router IPv6 support

Click "IPv6" Settings - Select "Function" and "WAN Port Connection Type" as shown below - Check "Multiple IPv4 Dial-up Link" - Click "Link" - If the settings are correct, the black box will be displayed Related Information.
Please add image description
Note: Not all routers support IPv6. If the router does not support it, you need to replace it with a supported router.

4. Synology IPv6 settings

4.1 View Synology IPv6 address

"Control Panel" - "Network" - "Network Interface" - select "LAN 1 (online)", click "Edit" - "IPv6" - confirm: whether to obtain it "automatically".
Please add image description
Please add image description

4.2 Test connectivity

Open the cmd window and ping Synology's IPv6 address.
For example, the address format viewed on the Synology interface is: 240e:aaa:eee:1111::1000/128.
When pinging, remove "/128" and ping directly: 240e:aaa:eee :1111::1000
Please add image description
At this point, the following functions can be achieved:
1. Within the scope of the intranet, use the IPv6 address to access Synology;
2. Within the scope of the intranet, software such as "DS File" and "DS video" on the mobile phone can use IPv6 How to log in
Please add image description

5. Tencent Cloud domain name resolution

5.1 Apply for a domain name

Application steps omitted

5.2 Create API key

Log in: Tencent Cloud-Key Console
Record the ID and Token information.
Please add image description

5.3 Domain name resolution

Log in to: Tencent Cloud - Domain Name Console , click "Add Record"
Please add image description
and select "AAAA" as the record type. This format points to an IPv6 address:

Please add image description
Please add image description

1. The host record can be customized: Assume that the applied domain name is abc123.xyz, add www here, then the resolved address is: www.abc123.xyz
2. Enter the IPv6 address of Synology NAS.

![Please add image description](https://img-blog.csdnimg.cn/1968509fab884d338101500545b2f8a5.png
Click "Start Parsing" in the red box
Please add image description
. At this time, we should be able to access our domain name directly. NAS.

6 Synology DDNS settings-no settings required

"Control Panel" - "External Access" - "DDNS" - click "Add"
Please add image description
Special Note: IPv6 mode does not need to set this item in Synology. As you can see from the picture above, the DDNS interface in Synology External addresses only have IPv4 addresses, no IPv6 options. So the settings here are useless for ipv6 access.

7 Use a script to regularly synchronize the IPV6 address of the NAS to Tencent Cloud DNS

The content here refers to the article of blogger "FlySkyIce": "Using shell script to implement Tencent Cloud DNSPod to perform DDNS dynamic domain name resolution ipv6 address", I would like to express my deep gratitude!
Article address: https://blog.csdn.net/weixin_43978546/article/details/113222378

The full text of the script is as follows:

#!/usr/bin/bash    
dnspod_ddnsipv6_id="API_KEY_ID" #【API_id】将引号内容修改为获取的API的ID
dnspod_ddnsipv6_token="API_KEY_TOKEN" #【API_token】将引号内容修改为获取的API的token
dnspod_ddnsipv6_ttl="600" # 【ttl时间】解析记录在 DNS 服务器缓存的生存时间,默认600(s/秒)
dnspod_ddnsipv6_domain='替换自己所购买的域名' #【已注册域名】引号里改成自己注册的域名
dnspod_ddnsipv6_subdomain='替换为想要的名字' #【二级域名】将引号内容修改为自己想要的名字,需要符合域名规范,附常用的规范
local_net="eth0" # 【网络适配器】 默认为eth0,如果你的公网ipv6地址不在eth0上,需要修改为对应的网络适配器
# 常用的规范【二级域名】
# 【www】 常见主机记录,将域名解析为 www.test.com
# 【@】   直接解析主域名 test.com
# 【*】   泛解析,匹配其他所有域名 *.test.com

# 举例
# 在腾讯云注册域名,登陆DNSPOD,在【我的账号】的【账号中心】中,有【密钥管理】
# 点击创建密钥即可创建一个API
# 如果你在腾讯云注册域名叫【test.com】
# 那么【dnspod_ddnsipv6_domain】后面就填【test.com】
# 然后根据常用的规范/自己想要的名字在【dnspod_ddnsipv6_subdomain】填入自己需要的名字
# 现假设为【file】,那么在【dnspod_ddnsipv6_subdomain】填入:"file",你的访问地址为【file.test.com】
if [ "$dnspod_ddnsipv6_record" = "@" ]
then
  dnspod_ddnsipv6_name=$dnspod_ddnsipv6_domain
else
  dnspod_ddnsipv6_name=$dnspod_ddnsipv6_subdomain.$dnspod_ddnsipv6_domain
fi

die () {
    
    
    echo "Error: unable to find [public IPv6 address], please use the 'ip addr' command or query the network panel of the system to check the network card, and fill in the name of the network card with the IPv6 address in the 'local_net' position in the command file." >&2
    echo "IP地址提取错误: 在指定的网络适配器上[$local_net]找不到<公网IPv6地址>(不是fe80开头),请使用'ip addr'命令或在系统的网络面板查询有公网IP的网络适配器,然后在脚本的[local_net]中用填写网络适配器的名称。" >&2
    exit
}

ipv6_list=`ip addr show $local_net | grep "inet6.*global" | awk '{print $2}' | awk -F"/" '{print $1}'` || die

for ipv6 in ${ipv6_list[@]}
do
    if [[ "$ipv6" =~ ^fe80.* ]]
    then
        continue
    else
        echo select IP: $ipv6 >&1
        break
    fi
done

if [ "$ipv6" == "" ] || [[ "$ipv6" =~ ^fe80.* ]]
then
    die
fi

dns_server_info=`nslookup -query=AAAA $dnspod_ddnsipv6_name 2>&1`

dns_server_ipv6=`echo "$dns_server_info" | grep 'address ' | awk '{print $NF}'`
if [ "$dns_server_ipv6" = "" ]
then
    dns_server_ipv6=`echo "$dns_server_info" | grep 'Address: ' | awk '{print $NF}'`
fi
    
if [ "$?" -eq "0" ]
then
    echo "DNS server IP: $dns_server_ipv6" >&1

    if [ "$ipv6" = "$dns_server_ipv6" ]
    then
        echo "The address is the same as the DNS server." >&1
    fi
    unset dnspod_ddnsipv6_record_id
else
    dnspod_ddnsipv6_record_id="1"   
fi

send_request() {
    
    
    local type="$1"
    local data="login_token=$dnspod_ddnsipv6_id,$dnspod_ddnsipv6_token&domain=$dnspod_ddnsipv6_domain&sub_domain=$dnspod_ddnsipv6_subdomain$2"
    return_info=`curl -X POST "https://dnsapi.cn/$type" -d "$data" 2> /dev/null`
}

query_recordid() {
    
    
    send_request "Record.List" ""
}

update_record() {
    
    
    send_request "Record.Modify" "&record_type=AAAA&record_line=默认&ttl=$dnspod_ddnsipv6_ttl&value=$ipv6&record_id=$dnspod_ddnsipv6_record_id"
}

add_record() {
    
    
    send_request "Record.Create" "&record_type=AAAA&record_line=默认&ttl=$dnspod_ddnsipv6_ttl&value=$ipv6"
}

if [ "$dnspod_ddnsipv6_record_id" = "" ]
then
    echo "seem exists, try update." >&1
    query_recordid
    code=`echo $return_info  | awk -F \"code\":\" '{print $2}' | awk -F \",\"message\" '{print $1}'`
    echo "return code $code" >&1
    if [ "$code" = "1" ]
    then
        dnspod_ddnsipv6_record_id=`echo $return_info | awk -F \"records\":.{
     
     \"id\":\" '{print $2}' | awk -F \",\"ttl\" '{print $1}'`
        update_record
        echo "update sucessful" >&1
    else
        echo "error code return, domain not exists, try add." >&1
        add_record
        echo "add sucessful." >&1
    fi
else
    echo "domain not exists, try add."
    add_record
    echo "add sucessful" >&1
fi

7.1 How to use scripts

According to your actual situation, modify lines 2-7 of the script, name the file dnspod.sh, and then upload the script to the /volume2/homes/admin directory, or other directories through Synology "File Station".
Use the ssh tool to ssh to the Synology backend system, enter the directory where the script is located, and execute the following command:

sed -i 's/\r//g' dnspod.sh
bash dnspod.sh

Execution results:
Please add image description
Check whether there are any errors when executing the script.
If no error is reported, the script will immediately synchronize the current IPv6 address to the "record value" in the Tencent Cloud domain name resolution interface.
If the "record value" has not been modified, or a new record is added, it means that the script setting is wrong and the modification will be returned.
Please add image description
Verification script: You can manually modify the "record value" on the Tencent Cloud web page, the IPv6 address here, and then re-run the dnspod.sh script to confirm whether the address here is changed correctly.

Execute script regularly

Synology - Control Panel - Task Schedule - Click "New" - Scheduled Task - User-defined Script
Click "Schedule" in the pop-up window - Set the frequency of script execution
and click "Task Settings" - —User-defined script, copy into the following command:

bash /volume2/homes/admin/dnspod.sh

This article ends.

Guess you like

Origin blog.csdn.net/m0_37862262/article/details/128194439