1.1环境准备
作用 | 系统 | IP | 主机名 |
---|---|---|---|
web 服务器 | redhat9.5 | 192.168.33.8 | web |
DNS 主服务器 | redhat9.5 | 192.168.33.18 | dns1 |
DNS 从服务器 | redhat9.5 | 192.168.33.28 | dns2 |
客户端 | redhat9.5 | 192.168.33.7 | client |
1.2修改主机名和IP地址
web服务器
[root@web-8 ~]# hostnamectl hostname web
[root@web-8 ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.33.8/24 ipv4.gateway 192.168.33.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@web-8 ~]# nmcli c up ens160
DNS1
[root@dns1-18 ~]# hostnamectl hostname dns1
[root@dns1-18 ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.33.18/24 ipv4.gateway 192.168.33.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@dns1-18 ~]# nmcli c up ens160
DNS2
[root@dns2-28 ~]# hostnamectl hostname dns2
[root@dns2-28 ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.33.28/24 ipv4.gateway 192.168.33.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@dns2-28 ~]# nmcli c up ens160
client
[root@dns-client ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.33.7/24 ipv4.gateway 192.168.33.2 ipv4.dns "192.168.33.18 192.168.33.28" connection.autoconnect yes
[root@dns-client ~]# nmcli c up ens160#ip恰好与题目client ip相同
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
[root@dns-client ~]#
[root@dns-client ~]#
[root@dns-client ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:b2:f4:4d brd ff:ff:ff:ff:ff:ff
altname enp3s0
inet 192.168.33.7/24 brd 192.168.33.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feb2:f44d/64 scope link noprefixroute
valid_lft forever preferred_lft forever
关闭几台服务器的 selinux:
[root@web ~]# setenforce 0
[root@dns1 ~]# setenforce 0
[root@dns2~]# setenforce 0
1.2配置web服务
1.2.1安装nginx
[root@web ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
[root@web ~]# dnf install nginx -y
Updating Subscription Management repositories.
Unable to read consumer identityThis system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.
BaseOS 2.6 MB/s | 2.7 kB 00:00
AppStream 2.9 MB/s | 3.2 kB 00:00
Package nginx-2:1.20.1-20.el9.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
1.2.2配置nginx首页
[root@web ~]# rpm -ql nginx
[root@web ~]# echo "welcome nginx" > /usr/share/nginx/html/index.html
[root@web ~]# systemctl enable --now nginx
[root@web ~]# firewall-cmd --permanent --add-service=http
Warning: ALREADY_ENABLED: http
success
[root@web ~]# firewall-cmd --reload
success
1.3配置DNS主服务
1.3.1安装dns软件
[root@dns1 ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
[root@dns1 ~]# dnf install bind -y
Updating Subscription Management repositories.
Unable to read consumer identityThis system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.
Last metadata expiration check: 1 day, 2:16:39 ago on Sun 16 Mar 2025 02:44:58 PM CST.
Package bind-32:9.16.23-24.el9_5.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
1.3.2修改主配置文件
[root@dns1 ~]# rpm -ql bind
[root@dns1 ~]# vim /etc/named.conf
[root@dns1 ~]# cat /etc/named.conf
options {
listen-on port 53 { 192.168.33.18; };
directory "/var/named";
allow-query { any; };
};
zone "haha.com" IN {
type master;
file "haha.com";
};
1.3.3配置区域数据文件
[root@dns1 ~]# vim /var/named/haha.com
[root@dns1 ~]# cat /var/named/haha.com
$TTL 1D
@ IN SOA @ admin.haha.com. (0 1D 2H 3W 2D)
IN NS ns1
IN NS ns2
ns1 IN A 192.168.33.18
ns2 IN A 192.168.33.28
www IN A 192.168.33.8
1.3.4检查配置语法
[root@dns1 ~]# named-checkconf
[root@dns1 ~]# named-checkzone haha.com /var/named/haha.com
zone haha.com/IN: loaded serial 0
OK
1.3.5测试DNS解析
[root@dns1 ~]# systemctl start named
[root@dns1 ~]# ps -ef | grep named
[root@dns1 ~]# dig -t NS haha.com @192.168.33.18
; <<>> DiG 9.16.23-RH <<>> -t NS haha.com @192.168.33.18
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64689
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 3;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 79ed8796f37753ac0100000067d7e7ca2cd104e727ccff15 (good)
;; QUESTION SECTION:
;haha.com. IN NS;; ANSWER SECTION:
haha.com. 86400 IN NS ns2.haha.com.
haha.com. 86400 IN NS ns1.haha.com.;; ADDITIONAL SECTION:
ns1.haha.com. 86400 IN A 192.168.33.18
ns2.haha.com. 86400 IN A 192.168.33.28;; Query time: 0 msec
;; SERVER: 192.168.33.18#53(192.168.33.18)
;; WHEN: Mon Mar 17 17:13:46 CST 2025
;; MSG SIZE rcvd: 133
1.3.6放行dns服务
[root@dns1 ~]# firewall-cmd --permanent --add-service=dns
Warning: ALREADY_ENABLED: dns
success
[root@dns1 ~]# firewall-cmd --reload
success
1.4配置DNS从服务
1.4.1安装dns软件
[root@dns2 ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
[root@dns2 ~]# dnf install bind -y
Updating Subscription Management repositories.
Unable to read consumer identityThis system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.
BaseOS 1.2 MB/s | 2.7 kB 00:00
AppStream 3.1 MB/s | 3.2 kB 00:00
Package bind-32:9.16.23-24.el9_5.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
1.4.2修改主配置文件
[root@dns2 ~]# vim /etc/named.conf
[root@dns2 ~]# cat /etc/named.conf
options {
listen-on port 53 { 192.168.33.28; };
directory "/var/named";
allow-query { any; };
};zone "haha.com" IN {
type slave;
masters {192.168.33.18 ;};
file "slaves/haha.com ";
};
1.4.3放行dns服务
[root@dns2 ~]# firewall-cmd --permanent --add-service=dns
Warning: ALREADY_ENABLED: dns
success
[root@dns2 ~]# firewall-cmd --reload
success
1.4.4启动dns服务
[root@dns2 ~]# systemctl start named
1.4.5测试dns解析
[root@dns2 ~]# dig -t NS haha.com @192.168.33.28
; <<>> DiG 9.16.23-RH <<>> -t NS haha.com @192.168.33.28
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39093
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 3;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 5c5ad754ea8ac7ce0100000067d7e9e24a147dbc8f042ccc (good)
;; QUESTION SECTION:
;haha.com. IN NS;; ANSWER SECTION:
haha.com. 86400 IN NS ns1.haha.com.
haha.com. 86400 IN NS ns2.haha.com.;; ADDITIONAL SECTION:
ns1.haha.com. 86400 IN A 192.168.33.135
ns2.haha.com. 86400 IN A 192.168.33.136;; Query time: 0 msec
;; SERVER: 192.168.33.28#53(192.168.33.28)
;; WHEN: Mon Mar 17 17:22:42 CST 2025
;; MSG SIZE rcvd: 133[root@dns2 ~]# dig -t A www.haha.com @192.168.33.28
; <<>> DiG 9.16.23-RH <<>> -t A www.haha.com @192.168.33.28
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48432
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 8d6dbd0ad5db90d90100000067d7ea0c48d4f16d6e872941 (good)
;; QUESTION SECTION:
;www.haha.com. IN A;; ANSWER SECTION:
www.haha.com. 86400 IN A 192.168.33.133;; Query time: 0 msec
;; SERVER: 192.168.33.28#53(192.168.33.28)
;; WHEN: Mon Mar 17 17:23:24 CST 2025
;; MSG SIZE rcvd: 85
实验完成!!!
2实验总结
2.1实验目的
本次实验旨在配置 web 服务、DNS 主从服务,并在客户端进行相应测试,以实现网络中 web 访问及域名解析功能,加深对网络服务配置原理和操作的理解。
2.2实验环境
web 服务器:IP 地址 192.168.33.8,主机名 web。
DNS 主服务器:IP 地址 192.168.33.18,主机名 dns1。
DNS 从服务器:IP 地址 192.168.33.28,主机名 dns2。
客户端:IP 地址 192.168.33.7,主机名 client。
2.3实验过程
环境准备:对各服务器和客户端进行主机名和 IP 地址的修改,并关闭了相关服务器的 selinux,为后续服务配置消除潜在的安全策略干扰。
web 服务配置:
安装 nginx 软件,通过相关命令成功获取并安装了 nginx 服务。
配置 nginx 首页,修改了 nginx 的配置文件,设置了自定义的首页内容,使其能够正常展示特定的网页信息。
DNS 主服务配置:
安装 dns 软件,确保了 DNS 服务所需的软件包正确安装。
修改主配置文件,对主配置文件中的相关参数进行了设置,包括监听地址、区域声明等。
配置区域数据文件,定义了域名与 IP 地址的映射关系,为域名解析提供数据支持。
检查配置语法,使用工具检查配置文件的语法正确性,避免因语法错误导致服务无法正常运行。
测试 DNS 解析,在客户端使用命令行工具进行域名解析测试,验证了主 DNS 服务器能够正确解析域名。
放行 dns 服务,配置防火墙规则,允许 DNS 服务的相关端口通过,确保网络中其他设备能够访问 DNS 服务。
- DNS 从服务配置:
安装 dns 软件,与主服务器类似,完成了从服务器上 DNS 软件的安装。
修改主配置文件,配置从服务器与主服务器的同步关系,使其能够从主服务器获取区域数据。
放行 dns 服务,配置防火墙规则,保障从服务器的 DNS 服务可被访问。
启动 dns 服务,成功启动从服务器的 DNS 服务,使其开始工作。
测试 dns 解析,在客户端再次进行测试,确认从服务器也能够正确解析域名,且与主服务器的解析结果一致。
2.4实验结果
web 服务配置成功,通过客户端浏览器访问 web 服务器的 IP 地址,能够正常显示配置的 nginx 首页内容。
DNS 主从服务配置成功,客户端能够通过主 DNS 服务器和从 DNS 服务器正确解析域名,实现了域名到 IP 地址的转换,保障了网络中基于域名的访问。
2.5实验问题及解决
在安装 nginx 时,由于网络不稳定,导致安装过程中断。解决方法是重新检查网络连接,确保网络稳定后,再次执行安装命令,最终成功安装。
在配置 DNS 主服务器的区域数据文件时,出现了语法错误,导致 DNS 服务无法正常启动。通过仔细检查配置文件,发现是记录格式错误,修改后服务恢复正常。
在配置 DNS 从服务器与主服务器同步时,一开始无法获取主服务器的区域数据。经过检查发现是防火墙规则设置不当,修改防火墙规则后,从服务器成功与主服务器同步。