UFW 简单防火墙安装、配置、禁 Ping

前言

UFW 是一个 Arch Linux、De­bian 或 Ubuntu 中管理防火墙规则的前端,可大大简化防火墙的配置过程。

安装 UFW

如还没有安装,可以使用 apt 命令来安装

apt-get update && apt-get install ufw

在使用前,你应该检查下 UFW 是否已经在运行。

ufw status

如果你发现状态是 inactive ,意思是没有被激活或不起作用。

启用 / 禁用

ufw enable  #启用

ufw disable  #禁用

使用与配置

列出当前 UFW 规则

ufw status verbose

添加规则

允许入站(allow)

默认情况,没有允许就是拒绝(入站),使用 ufw allow 来添加允许访问的端口或协议。

ufw allow ssh  #添加22端口

ufw allow http  #添加80端口

ufw allow https  #添加443端口

ufw allow 2333/tcp   #添加2333端口,仅TCP协议

ufw allow 6666/udp   #添加6666端口,仅UDP协议

ufw allow 8888:9999  #添加8888到9999之间的端口

拒绝访问(deny)

使用 ufw deny 来添加拒绝入站的端和协议,与添加允许的类似。

删除规则

先使用 ufw status 查看规则,再使用 ufw delete [规则] 来删除规则。

ufw delete allow 2333/tcp

如果你有很多条规则,使用 numbered 参数,可以在每条规则上加个序号数字。

然后使用 ufw delete 来删除规则。

root:~# ufw status numbered #列出规则,并加上序号
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 20,21,22,80,888,8888/tcp   ALLOW IN    Anywhere
[ 2] 39000:40000/tcp            ALLOW IN    Anywhere
[ 3] 8896/tcp                   ALLOW IN    Anywhere
[ 4] 8896/udp                   ALLOW IN    Anywhere
[ 5] 443/tcp                    ALLOW IN    Anywhere
[ 6] 20,21,22,80,888,8888/tcp (v6) ALLOW IN    Anywhere (v6)
[ 7] 39000:40000/tcp (v6)       ALLOW IN    Anywhere (v6)
[ 8] 8896/tcp (v6)              ALLOW IN    Anywhere (v6)
[ 9] 8896/udp (v6)              ALLOW IN    Anywhere (v6)
[10] 443/tcp (v6)               ALLOW IN    Anywhere (v6)

[email protected]:~# ufw delete 4 #删除上面的第4条规则

Deleting:
 allow 8896/udp
Proceed with operation (y|n)? y  #最后会询问你是否进行操作

以上都是一些简单常用的一些命令,想要深入了解,可以输入 man ufw 查看 ufw 用户手册。

禁 Ping
打开 UFW 配置文件

vim /etc/ufw/before.rules

修改配置
允许 ping

-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT

禁止 ping

-A ufw-before-input -p icmp --icmp-type echo-request -j DROP

让配置生效

ufw reload

文章来源于互联网:UFW 简单防火墙安装、配置、禁 Ping

已有 6 条评论
  1. Skapsprus

    Up to 24 months of therapy may be necessary to totally eradicate dryness; however, some patients do not fully respond even to this treatment regimen cialis prescription Dry eyes are a common side effect immediately following LASIK

    Skapsprus 回复
  2. Gerengeva

    PubMed 18771564 venta levitra

    Gerengeva 回复
  3. Gappibe

    propecia prescription Vit D regulates AMH levels in vitro, both directly through the AMH promoter 9 and indirectly by regulating the number of granulosa cells and AMH signaling in cultures of ovarian follicles 10

    Gappibe 回复
  4. Gappibe

    reddit where buy priligy Clinical decongestion by AF AFL status and clinical outcomes

    Gappibe 回复
  5. Skapsprus

    Patients with no preference were excluded viagra vs cialis

    Skapsprus 回复
  6. Gerengeva

    2015, 50 11, 1966 1976 cheap cialis generic online

    Gerengeva 回复
发表新评论