1.要求
需要 3 台 Linux 服务器,如下表所示。
主机名 | 系统 | IP | 作用 |
---|---|---|---|
web | redhat 9.5 | 192.168.72.8 | web 服务器 |
dns-server | redhat 9.5 | 192.168.72.18 | DNS 服务器 |
client | redhat 9.5 | 192.168.72.7 | 客户端 |
2.实现步骤
1.修改ip和主机名
web:
hostnamectl hostname web
nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.72.8/24 ipv4.gateway 192.168.72.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
nmcli c up ens160
dns-server:
hostnamectl hostname dns-server
nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.72.18/24 ipv4.gateway 192.168.72.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
nmcli c up ens160
client:
hostnamectl hostname client
nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.72.7/24 ipv4.gateway 192.168.72.2 ipv4.dns 192.168.72.18 connection.autoconnect yes
nmcli c up ens160
2.安装服务
配置仓库(所有虚拟机)
[BaseOS]
name=BaseOS
baseurl=/mnt/BaseOS
gpgcheck=0
[AppStream]
name=AppStream
baseurl=/mnt/AppStream
gpgcheck=0
挂载(所有虚拟机)
mount /dev/sr0 /mnt
web:
dnf install nginx -y
dns-server:
dnf install bind -y
关闭selinux(所有虚拟机)
setenforce 0
3.web端相关配置
编写欢迎页面
echo "welcome to nginx" > /usr/share/nginx/html/index.html
放行服务
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
启动nginx服务
systemctl enable nginx --now
4.dns相关配置
修改主配置文件
vim /etc/bind/naemd.conf
options {
listen-on port 53 {192.168.72.18; };
directory "/var/named";
};
zone "example.com" IN {
type master;
file "example.com";
};
编写区域配置文件
vim /var/named/example.com
$TTL 1D
@ IN SOA ns.example.com.
admin.example.com. (
0
1D
1H
1W
1D)
IN NS na.example.com.
ns IN A 192.168.72.18
www IN A 192.168.72.18
放行服务
firewall-cmd --permanent --add-service=dns
firewall-cmd --reload
开启dns相关服务
systemctl enable nsmed --now
测试域名解析
dig -t NS example.com @192.168.72.18
5.客户端测试
nmcli c show | grep DNS
curl www.example.com
curl 192.168.72.8