在网站运维过程中,服务器远程规则的配置直接影响着服务可用性与安全性,本文将通过六大核心模块,结合最新安全实践与主流服务器环境,为技术人员提供符合行业标准的操作指南。
规则配置前置检查
网络环境验证
traceroute [目标IP]
确认网络可达性telnet [IP] [端口]
或nc -zv [IP] [端口]
测试端口连通性系统权限确认
sudo -l
ssh-keygen -l -f ~/.ssh/id_rsa.pub
防火墙策略配置(以Firewalld为例)
# 永久开放特定端口 sudo firewall-cmd --permanent --add-port=8080/tcp # 设置IP白名单 sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" accept' # 配置后重载规则 sudo firewall-cmd --reload
Web服务器访问控制
▌Nginx配置示例:
location /admin { allow 203.0.113.5; deny all; proxy_pass http://backend; }
▌Apache配置要点:
<Directory "/var/www/secured"> Require ip 2001:db8::/32 Require host .example.com </Directory>
自动化规则更新方案
#!/bin/bash curl -s https://api.trusted-rules.com/v1/ips | xargs -I {} iptables -A INPUT -s {} -j ACCEPT
0 3 * * * /usr/local/bin/update_rules.sh >> /var/log/rule_update.log
安全防护增强措施
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 3 -j DROP
# SSH证书配置 Match Address 192.168.1.* PasswordAuthentication no AuthenticationMethods publickey
规则验证与监控
ss -antp | grep ESTAB tcpdump -i eth0 'tcp port 80 and (src host 192.168.1.100)'
maxretry=3
)操作注意事项
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak_$(date +%F)
iptables-persistent
或firewalld
确保规则持久化curl -I -X GET http://localhost/healthcheck nmap -p 22,80,443 [服务器IP]
参考标准
(本文配置示例已在CentOS 7.6/Ubuntu 20.04 LTS环境实测,适用于Nginx 1.18+/Apache 2.4+版本,实施前请根据实际环境调整参数)