在Ubuntu虚拟机中配置DNS服务器可以通过以下几种方法实现,这里以使用systemd-resolved和bind9为例进行说明:
使用systemd-resolved配置DNS服务器(适用于Ubuntu 18.04及更高版本)
-
安装
systemd-resolved(如果尚未安装):sudo apt update sudo apt install systemd-resolved -
编辑
systemd-resolved配置文件:sudo nano /etc/systemd/resolved.conf -
取消注释并设置DNS服务器: 在
[Resolve]部分添加或修改DNS服务器地址,例如:DNS=8.8.8.8 8.8.4.4 -
重启
systemd-resolved服务以应用更改:sudo systemctl restart systemd-resolved -
验证DNS设置: 使用以下命令检查当前的DNS设置:
systemd-resolve --status
使用bind9配置DNS服务器
-
安装
bind9:sudo apt update sudo apt install bind9 bind9utils bind9-doc -
编辑
bind9的主配置文件:sudo nano /etc/bind/named.conf.options -
配置DNS服务器的全局选项,例如设置转发器:
options { directory "/var/cache/bind"; forwarders { 8.8.8.8; 8.8.4.4; }; dnssec-validation auto; auth-nxdomain no; # conform to RFC1035 listen-on-v6 { any; }; }; -
编辑
bind9的区域配置文件:sudo nano /etc/bind/named.conf.local -
添加区域配置:
zone "example.local" { type master; file "/etc/bind/db.example.local"; }; -
创建区域数据库文件:
sudo cp /etc/bind/db.local /etc/bind/db.example.local sudo nano /etc/bind/db.example.local -
添加区域记录:
$TTL 604800 @ IN SOA ns1.example.local. admin.example.local. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS ns1.example.local. ns1 IN A 192.168.1.10 www IN A 192.168.1.10 -
重启
bind9服务以应用更改:sudo systemctl restart bind9 -
验证DNS配置: 使用以下命令检查配置文件是否正确:
sudo named-checkconf sudo named-checkzone example.local /etc/bind/db.example.local -
测试DNS服务器: 使用
nslookup或dig命令测试:nslookup www.example.local dig @127.0.0.1 www.example.local
配置客户端使用DNS服务器
-
在Ubuntu客户端上配置DNS服务器: 编辑
/etc/systemd/resolved.conf文件,在[Resolve]部分添加你的DNS服务器IP:sudo nano /etc/systemd/resolved.conf添加以下内容:
DNS=192.168.1.100重启网络服务:
sudo systemctl restart systemd-resolved -
在其他客户端(如Android、Windows)配置DNS: 设置DNS地址为Ubuntu服务器的IP。
以上就是关于“虚拟机ubuntu如何配置DNS服务器”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm