【Ubuntu】防火墙ufw的使用
一、防火墙ufw的使用:
1.使用指南
xxxx@xx:~$ sudo ufw --help
Usage: ufw COMMAND
Commands:
enable enables the firewall
disable disables the firewall
default ARG set default policy
logging LEVEL set logging to LEVEL
allow ARGS add allow rule
deny ARGS add deny rule
reject ARGS add reject rule
limit ARGS add limit rule
delete RULE|NUM delete RULE
insert NUM RULE insert RULE at NUM
reload reload firewall
reset reset firewall
status show firewall status
status numbered show firewall status as numbered list of RULES
status verbose show verbose firewall status
show ARG show firewall report
version display version information
Application profile commands:
app list list application profiles
app info PROFILE show information on PROFILE
app update PROFILE update PROFILE
app default ARG set default application policy
2.基本用法
①启用ufw
sudo ufw enable
②禁用ufw
sudo ufw disable
③重启防火墙
sudo ufw reload
④添加防火墙规则
# ufw 默认是这样的
# ufw default allow|deny|reject DIRECTION #DIRECTION: incoming outgoing routed
sudo ufw default deny incoming #禁用所有连接服务器的入
sudo ufw default allow outgoing # 允许服务器上所有的出
sudo ufw allow from 10.0.xx.xx to any port 22
⑤查看防火墙状态码
sudo ufw status numbered
⑥删除防火墙规则
sudo ufw delete number #以状态码删除规则
sudo ufw delete allow 80/tcp #指定具体的规则删除
⑦切换防火墙日志级别
防火墙日志级别从low->full,日志开启后默认就是low级别,记录的日志量最少,内容包括和默认策略不匹配的包(带速率限制)以及匹配了规则的包,full是记录日志内容最多的级别。
sudo ufw logging on|off|LEVEL # level : low medium high full
3.应用集成
ufw支持通过配置文件的方式进行应用集成,配置文件位于/etc/ufw/applications.d,可以使用命令ufw app list列出当前已经集成的应用名称。可以在前面的路径下面添加自定义服务,然后使用ufw allow
[OpenSSH]
title=Secure shell server, an rshd replacement
description=OpenSSH is a free implementation of the Secure Shell protocol.
ports=22/tcp