ufw防火墙
本文最后更新于 103 天前,如有失效请评论区留言。

ufw

本文默认是root用户,如果不是可以sudo -i

查看是否有ufw (ubuntu系统自带)

which ufw

如何没有就安装一个

apt install ufw

查看防火墙状态

ufw status

image-20240206170418912

inactive说明未开启

开启防火墙

ufw enable

提示说可能会中断当前ssh 按y

image-20240206170441609

即可开启

ufw是默认禁止所有进站流量,运行所有出站流量的

所以开启后,首先记得把ssh端口开启

这里如果你的ssh端口不是22(默认是22,如果你自己修改过),就改为对应的端口

ufw allow 22/tcp comment 'SSH'

如果你的ip地址是固定的(绝大部分家庭宽带都是不固定的),或者你有一个固定的服务器,可以把指定的ip加入

这将运行这个ip的所有访问

ufw allow from xxx.xxx.xxx.xxx to any

运行https连接,80端口看你自己是否需要,我全站使用https所以就不开80了

ufw allow 443

禁用Ping命令,伪装成是一台不能使用的机器,减少ip扫描

sed -i 's/-A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT/-A ufw-before-input -p icmp --icmp-type destination-unreachable -j DROP/g;s/-A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT/-A ufw-before-input -p icmp --icmp-type time-exceeded -j DROP/g;s/-A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT/-A ufw-before-input -p icmp --icmp-type parameter-problem -j DROP/g;s/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/g' /etc/ufw/before.rules && ufw reload

原理就是把/etc/ufw/before.rules 文件下的 这个input icmp类型的 ACCEPT 改为 DROP

image-20240206201919236

同理把 DROP改为 ACCEPT 就是恢复

恢复Ping命令

sed -i 's/-A ufw-before-input -p icmp --icmp-type destination-unreachable -j DROP/-A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT/g;s/-A ufw-before-input -p icmp --icmp-type time-exceeded -j DROP/-A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT/g;s/-A ufw-before-input -p icmp --icmp-type parameter-problem -j DROP/-A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT/g;s/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/g' /etc/ufw/before.rules && ufw reload
版权声明:本文为BIMiracle原创,依据CC BY-SA 4.0许可证进行授权,转载请附上出处链接及本声明。
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇