1 UFW 的安装
sudo apt update
sudo apt install ufw
2 UFW 的常用操作
2.1 启用和禁用ufw
# 启用ufw
root@lige:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
# 禁用ufw
root@lige:~# ufw disable
Firewall stopped and disabled on system startup
2.2 检查 UFW 状态
# 查看 UFW 的当前状态及规则:
root@lige:~# ufw status
Status: inactive
# 使用 verbose 参数可以获得更详细的信息:
# 如果是关闭的,只输出inactive
root@lige:~# ufw status verbose
Status: inactive
# 如果是启用的,会输出详细规则
root@lige:~# ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22 ALLOW IN Anywhere
22 (v6) ALLOW IN Anywhere (v6)
2.3 设置默认策略
# 拒绝所有传入流量,允许所有传出流量
root@lige:~# ufw default deny incoming
root@lige:~# ufw default allow outgoing
2.4 配置规则
root@lige:~# ufw allow 80
Rule added
Rule added (v6)
root@lige:~# ufw allow ssh
Rule added
Rule added (v6)
root@lige:~# ufw allow from 10.10.10.200
Rule added
# 允许10.10.10.200访问服务器的22端口
root@lige:~# ufw allow from 10.10.10.200 to any port 22
# 允许 eth0 接口的 HTTP 流量:
root@lige:~# sudo ufw allow in on eth0 to any port 80
Rule added
Rule added (v6)
# 允许某个网段访问对应协议的某个端口
root@lige:~# ufw allow from 192.168.1.0/24 to any port 80 proto tcp
Rule added
# 拒绝 FTP端口
root@lige:~# ufw deny 21
Rule added
Rule added (v6)
查看规则状态:
root@lige:~# ufw status verbose
2.5 删除规则
root@lige:~# ufw delete allow ssh
Rule deleted
Rule deleted (v6)root@lige:~# ufw delete allow 80
2.6 限制连接
root@lige:~# ufw limit ssh
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




