ufw安装
# 安装
apt install ufw
# 检查ufw状态,默认为未激活
ufw status verbose配置前操作
# 重置所有规则
ufw reset
# 开启
ufw enable设置默认策略
ufw default allow/deny配置规则
# 打开端口(端口/协议),没有指定协议则默认全部
ufw allow 22/tcp
# 指定端口范围
ufw allow 7000:8000/tcp
# 指定ip地址访问
ufw allow from 1.1.1.1
# 允许指定ip可以访问指定端口
ufw allow from 1.1.1.1 to any port 22
# 允许指定ip可以访问指定端口的指定协议
ufw allow from 1.1.1.1 to any port 22 proto tcp
# 允许子网
ufw allow in eth2 to any port 3306
# 禁止ip连接
ufw deny from 23.24.25.0/24删除规则,注意添加的顺序,ufw会按顺序执行。比如在添加ufw deny from any后,后续添加的所有规则将不能生效
# 查看规则序号
ufw status numbered
ufw delete allow 规则
ufw delete 规则序号删除规则
# 查看规则序号
ufw status numbered
ufw delete allow 规则
ufw delete 规则序号ufw禁用/启用/重置
# 禁用
ufw disable
# 启用
ufw enable
# 重置
ufw reset