在Linux上安装域名服务器(DNS服务器)通常使用BIND(Berkeley Internet Name Domain)软件,以下是详细的安装和配置步骤:
1. 安装BIND
sudo apt update sudo apt install bind9 bind9utils bind9-doc
CentOS/RHEL/Fedora系统:
CentOS/RHEL sudo yum install bind bind-utils 或者使用dnf(新版本) sudo dnf install bind bind-utils Fedora sudo dnf install bind bind-utils
2. 基本配置
编辑主配置文件/etc/bind/named.conf
或/etc/named.conf
:
sudo nano /etc/bind/named.conf
添加以下内容:
options { directory "/var/cache/bind"; listen-on port 53 { any; }; listen-on-v6 port 53 { any; }; allow-query { any; }; recursion yes; forwarders { 8.8.8.8; 8.8.4.4; }; };
创建正向解析配置:
sudo nano /etc/bind/named.conf.local
添加:
zone "example.com" { type master; file "/etc/bind/db.example.com"; };
sudo nano /etc/bind/named.conf.local
添加:
zone "1.168.192.in-addr.arpa" { type master; file "/etc/bind/db.192.168.1"; };
3. 创建区域数据文件
sudo nano /etc/bind/db.example.com
$TTL 604800 @ IN SOA ns1.example.com. admin.example.com. ( 2024010101 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS ns1.example.com. @ IN A 192.168.1.10 ns1 IN A 192.168.1.10 www IN A 192.168.1.20 mail IN A 192.168.1.30 ftp IN CNAME www.example.com.
sudo nano /etc/bind/db.192.168.1
$TTL 604800 @ IN SOA ns1.example.com. admin.example.com. ( 2024010101 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS ns1.example.com. 10 IN PTR ns1.example.com. 20 IN PTR www.example.com. 30 IN PTR mail.example.com.
4. 权限和所有权设置
sudo chown bind:bind /etc/bind/db.
sudo chown named:named /var/named/db.
5. 启动和启用服务
sudo systemctl start bind9 sudo systemctl enable bind9
sudo systemctl start named sudo systemctl enable named
6. 防火墙配置
Ubuntu UFW sudo ufw allow 53 CentOS/RHEL firewalld sudo firewall-cmd --permanent --add-service=dns sudo firewall-cmd --reload 或者直接开放端口 sudo firewall-cmd --permanent --add-port=53/tcp sudo firewall-cmd --permanent --add-port=53/udp sudo firewall-cmd --reload
7. 测试DNS服务器
Ubuntu/Debian sudo named-checkconf sudo named-checkzone example.com /etc/bind/db.example.com CentOS/RHEL sudo named-checkconf sudo named-checkzone example.com /var/named/db.example.com
dig @localhost example.com dig @localhost www.example.com dig @localhost -x 192.168.1.20
nslookup example.com localhost nslookup www.example.com localhost
8. 配置客户端使用DNS服务器
编辑客户端系统的resolv.conf:
sudo nano /etc/resolv.conf
添加:
nameserver 192.168.1.10 search example.com
9. 安全配置建议
在options部分添加 allow-recursion { 192.168.1.0/24; localhost; };
version "unknown";
acl "trusted" { 192.168.1.0/24; localhost; }; options { allow-query { trusted; }; allow-recursion { trusted; }; };
故障排除
1、检查服务状态:
sudo systemctl status bind9 # 或 named
2、查看日志:
sudo tail -f /var/log/syslog # Ubuntu/Debian sudo tail -f /var/log/messages # CentOS/RHEL
3、重新加载配置:
sudo rndc reload # 或 sudo systemctl reload bind9
这样就完成了基本的DNS服务器安装和配置,根据你的具体需求,可能需要进一步调整配置参数。
文章摘自:https://idc.huochengrm.cn/fwq/18654.html
评论
侍思松
回复Linux安装域名服务器需要准备服务器硬件、操作系统环境、域名服务器软件(如bind或dnsmasq),配置网络参数,进行正向和反向解析记录设置,测试验证,确保服务器稳定运行。