XYCOVO CONSOLE KURISU · WEB 渗透 / AI 辅助攻防 ONLINE
#003 · 2025-08-01✓ PASS

企业网络综合实验

搭建完整企业网络服务体系:Nginx+YUM仓库+DNS+NTP+MySQL+NFS+Discuz论坛,包含防火墙配置。
linux综合实验网络服务网络安全AUTHOR: KURISU

模拟企业环境,在三台虚拟机上部署 7 种核心网络服务,涵盖 Web、DNS、NTP、数据库、文件共享和论坛系统。


一、项目拓扑

主机规划

主机名IP服务
servera172.25.250.101-105Nginx + YUM 仓库
servera172.25.250.102Chronyd NTP 服务
servera172.25.250.103MySQL 数据库
servera172.25.250.104NFS 文件系统
servera172.25.250.105BIND DNS 服务
serverb172.25.250.106Discuz 论坛
serverc172.25.250.107客户端

安全要求

所有服务器的 Firewalld 和 SELinux 必须保持开启状态!


二、Nginx + YUM 仓库服务

# 安装 Nginx
dnf install -y nginx

# 创建仓库目录
mkdir -p /var/www/html/yum/{AppStream,BaseOS}

# 挂载 ISO 并复制包
mount /dev/sr0 /mnt
cp -r /mnt/AppStream/* /var/www/html/yum/AppStream/
cp -r /mnt/BaseOS/* /var/www/html/yum/BaseOS/

# Nginx 配置
cat > /etc/nginx/conf.d/repo.conf << 'EOF'
server {
    listen 80;
    server_name content.exam.com;
    root /var/www/html;

    location /yum/ {
        autoindex on;
        autoindex_exact_size off;
    }
}
EOF

# SELinux 上下文
semanage fcontext -a -t httpd_sys_content_t "/var/www/html/yum(/.*)?"
restorecon -Rv /var/www/html/yum
chcon -R -t httpd_sys_content_t /var/www/html/yum

# 防火墙
firewall-cmd --add-service=http --permanent
firewall-cmd --reload

# 启动
systemctl enable --now nginx

客户端配置

cat > /etc/yum.repos.d/local.repo << 'EOF'
[AppStream]
name=Local AppStream
baseurl=http://content.exam.com/yum/AppStream
gpgcheck=0
enabled=1

[BaseOS]
name=Local BaseOS
baseurl=http://content.exam.com/yum/BaseOS
gpgcheck=0
enabled=1
EOF

dnf clean all && dnf repolist

三、NTP 时间服务

# 安装
dnf install -y chrony

# 配置(/etc/chrony.conf)
cat >> /etc/chrony.conf << 'EOF'
# 作为 NTP 服务器,层级 3
allow 172.25.250.0/24
local stratum 3
EOF

# 防火墙
firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload

systemctl enable --now chronyd

# 客户端同步
chronyc sources -v

四、MySQL 数据库

# 使用 YUM 仓库安装
dnf install -y mysql-server

# 启动
systemctl enable --now mysqld

# 安全初始化
mysql_secure_installation

# 创建数据库和用户
mysql -u root -p << SQL
ALTER USER 'root'@'localhost' IDENTIFIED BY 'redhat';
CREATE DATABASE bbs;
CREATE USER 'bbsuser'@'%' IDENTIFIED BY 'redhat';
GRANT ALL ON bbs.* TO 'bbsuser'@'%';
FLUSH PRIVILEGES;
SQL

# 防火墙
firewall-cmd --add-service=mysql --permanent
firewall-cmd --reload

五、NFS 文件共享

dnf install -y nfs-utils

# 创建共享目录
mkdir -p /bbs
chmod 777 /bbs

# 导出配置(/etc/exports)
echo "/bbs 172.25.250.106(rw,sync,no_root_squash)" >> /etc/exports

# 启动
systemctl enable --now nfs-server

# SELinux
setsebool -P nfs_export_all_rw on
setsebool -P nfs_export_all_ro on

# 防火墙
firewall-cmd --add-service=nfs --permanent
firewall-cmd --add-service=rpc-bind --permanent
firewall-cmd --add-service=mountd --permanent
firewall-cmd --reload

exportfs -r

# 客户端挂载(172.25.250.106 上)
mkdir -p /bbs
mount -t nfs 172.25.250.104:/bbs /bbs
echo "172.25.250.104:/bbs /bbs nfs defaults,_netdev 0 0" >> /etc/fstab

六、DNS 服务

dnf install -y bind bind-utils

# 正向解析文件 /var/named/forward.exam.com
$TTL 86400
@   IN SOA  dns.exam.com. admin.exam.com. (2025010101 3600 1800 604800 86400)
@   IN NS   dns.exam.com.
content IN A   172.25.250.101
ntp     IN A   172.25.250.102
mysql   IN A   172.25.250.103
nfs     IN A   172.25.250.104
dns     IN A   172.25.250.105
bbs     IN A   172.25.250.106
www     IN A   172.25.250.101

# 反向解析文件 /var/named/reverse.exam.com
# ... PTR 记录

# 测试
dig @172.25.250.105 bbs.exam.com

七、验证清单

# 1. YUM 仓库可用
dnf repolist

# 2. NTP 同步
chronyc sources -v

# 3. MySQL 连接
mysql -h 172.25.250.103 -u bbsuser -predhat -e "SHOW DATABASES;"

# 4. NFS 可用
showmount -e 172.25.250.104

# 5. DNS 解析
nslookup bbs.exam.com 172.25.250.105

# 6. 防火墙状态
firewall-cmd --list-all

# 7. SELinux 状态
getenforce

← #002 云服务器部署雷池 WAF + H…#004 RHCSA 学习笔记… →