# 安装 iptables
yum install iptables-services -y
# 开启 iptables
systemct start iptables
# 清楚所有规则,一定要执行,不然\(//∇//)\,你现在所有端口外部都没法访问,该死,我没执行这个,执行添加规则退出,ssh 就登陆不了了,(。 ˇ‸ˇ 。)
iptables -F
# 关闭端口开放,raw 为 table 名称,PREROUTING 为 “路由规则” 的前置拦截
iptables -t raw -I PREROUTING -p tcp --dport 端口 -j DROP
# 端口针对 ip 开放
iptables -t raw -I PREROUTING -s ip -p tcp --dport 端口 -j ACCEPT
iptables -t raw -I PREROUTING -s ip/16 -p tcp --dport 端口 -j ACCEPT
# 查看设置的规则
iptables -t raw -nvL
# 查看规则编号
iptables -t raw -L -n --line-number
# 删除添加的规则
iptables -t raw -D PREROUTING xx
# 开机自启动
systemctl enable iptables
开启 iptables设置端口访问权限
于 2022-08-27 12:11:29 首次发布