在Debian系統上實現域名解析到子域名,主要有以下兩種方法:
example.com
),確保Debian服務器有公網IP。sub.example.com
)直接指向服務器IP。A記錄
,主機記錄填sub
,記錄值填服務器IP。blog.example.com
指向example.com
)。CNAME記錄
,主機記錄填blog
,記錄值填example.com
。sudo apt update && sudo apt install bind9 bind9utils bind9-doc
。/etc/bind/named.conf.local
,添加子域名區域配置:zone "sub.example.com" {
type master;
file "/etc/bind/db.sub.example.com";
};
/etc/bind/db.sub.example.com
,添加解析記錄:$TTL 604800
@ IN SOA ns1.example.com. admin.example.com. (
2025090101 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
sub IN A 192.168.1.10 # 子域名指向服務器IP
sudo systemctl restart bind9
,使用nslookup sub.example.com
驗證解析是否生效。