NAME名称

  1. ufw - program for managing a netfilter firewall

网络过滤式防火墙管理程序。

DESCRIPTION描述

  1. This program is for managing a Linux firewall and aims to provide an easy to use interface for the user.

该Linux防火墙管理程序目标是提供简单的使用界面。

USAGE用法

  1. [--dry-run]选项,仅显示运行结果而不实际运行

启动\关闭\重启

  1. ufw [--dry-run] enable|disable|reload

默认策略 允许\拒绝\拒绝并提示 [进入\发出\路由 的数据]

  1. ufw [--dry-run] default allow|deny|reject [incoming|outgoing|routed]

日志 启动\关闭\级别

  1. ufw [--dry-run] logging on|off|LEVEL

重置

  1. ufw [--dry-run] reset

规则、状态 [详细\序号]

  1. ufw [--dry-run] status [verbose|numbered]

显示“报告”

  1. ufw [--dry-run] show REPORT

[删除][插入 第 行] 允许\拒绝\拒绝并提示\限制 [数据 进入\发出][记录\全记录] 端口[/协议]

  1. ufw [--dry-run] [delete] [insert NUM] allow|deny|reject|limit [in|out] [log|log-all] PORT[/PROTOCOL]

[规则][删除][插入 第 行] 允许\拒绝\拒绝并提示\限制 [数据 进入\发出[网络接口]][记录\全记录] [协议 ][来自[端口 ]][指向[端口**]

  1. ufw [--dry-run] [rule] [delete] [insert NUM] allow|deny|reject|limit [in|out [on INTERFACE]] [log|log-all] [proto PROTOCOL] [from ADDRESS [port PORT]] [to ADDRESS [port PORT]]

路由[删除][插入 第 行] 允许\拒绝\拒绝并提示\限制 [数据 进入\发出[网络接口]][记录\全记录] [协议 ][来自[端口 ]][指向[端口**]

  1. ufw [--dry-run] route [delete] [insert NUM] allow|deny|reject|limit [in|out on INTERFACE] [log|log-all] [proto PROTOCOL] [from ADDRESS [port PORT]] [to ADDRESS [port PORT]]

删除第*行规则

  1. ufw [--dry-run] delete NUM

应用名 列表\信息\默认策略\更新

  1. ufw [--dry-run] app list|info|default|update

OPTIONS选项

  1. --version
  2. show program's version number and exit
  3. 显示程序版本并退出
  1. -h, --help
  2. show help message and exit
  3. 显示帮助并退出
  1. --dry-run
  2. don't modify anything, just show the changes
  3. 不进行更改,仅显示更改内容
  1. enable
  2. reloads firewall and enables firewall on boot.
  3. 重启防火墙,设置为开机启动
  1. disable
  2. unloads firewall and disables firewall on boot
  3. 停止防火墙,禁止开机启动
  1. reload
  2. reloads firewall
  3. 重启防火墙
  1. default allow|deny|reject DIRECTION
  2. change the default policy for traffic going DIRECTION, where DIRECTION is
  3. one of incoming, outgoing or routed. Note that existing rules will have
  4. to be migrated manually when changing the default policy. See RULE SYNTAX
  5. for more on deny and reject.
  6. 改变传入\传\路由的默认策略。已存在的规则可能需要进行手动修改。关于deny|reject的区别参见 SYNTAX
  1. logging on|off|LEVEL
  2. toggle logging. Logged packets use the LOG_KERN syslog facility. Systems
  3. configured for rsyslog support may also log to /var/log/ufw.log. Specify
  4. ing a LEVEL turns logging on for the specified LEVEL. The default log
  5. level is 'low'. See LOGGING for details.
  6. 切换记录。日志记录使用的是LOG_KERN系统设备。系统日志保存于/var/log/ufw.logLEVEL指定不同的级别 ,默认级别是‘

低’。参见LOGGING

  1. reset
  2. Disables and resets firewall to installation defaults. Can also give the
  3. --force option to perform the reset without confirmation.
  4. 关闭并重置防火墙至默认安装状态。使用--force选项,无需等待确认。
  1. status
  2. show status of firewall and ufw managed rules. Use status verbose for
  3. extra information. In the status output, 'Anywhere' is synonymous with
  4. 'any' and '0.0.0.0/0'. Note that when using status, there is a subtle
  5. difference when reporting interfaces. For example, if the following rules
  6. are added:
  7. 显示防火墙状态及规则。使用status verbose显示额外信息。显示信息中'Anywhere'等同于 'any''0.0.0.0/0'

需要注意的是报告有些微妙的差异。例如,加入以下规则:

允许来自192.168.0.0-192.168.255.255的数据通过eth0网卡进入主机

  1. ufw allow in on eth0 from 192.168.0.0/16

允许指向10.0.0.0-10.255.255.255的数据通过eth1网卡从本机发出

  1. ufw allow out on eth1 to 10.0.0.0/8

允许来自192.168.0.0-192.168.255.255通过eth0网卡收入的数据且指向10.0.0.0-10.255.255.255通过eth1网卡发出的数据经本机路由

  1. ufw route allow in on eth0 out on eth1 to 10.0.0.0/8 from 192.168.0.0/16
  1. ufw status will output:
  2. 显示信息为:
  1. To Action From
  2. -- ------ ----
  3. Anywhere on eth0 ALLOW 192.168.0.0/16
  4. 10.0.0.0/8 ALLOW OUT Anywhere on eth1
  5. 10.0.0.0/8 on eth1 ALLOW FWD 192.168.0.0/16 on eth0
  6.  
  7. 指向 行为 来自
  8. ----- ------ ----
  9. 任意地址,网络接口eth0 允许 192.168.0.0/16
  10. 10.0.0.0/8 允许发出 任意地址,网络接口eth1
  11. 10.0.0.0/8域,网络接口eth1 允许路由 192.168.0.0/16域,网络接口eth0
  1. For the input and output rules, the interface is reported relative to the
  2. firewall system as an endpoint, whereas with route rules, the interface
  3. is reported relative to the direction packets flow through the firewall.
  4. 进入\发 规则,(来自\指向)是以防火墙系统为终点的;路由规则,(来自\指向)是相对于通过防火墙的流向。
  1. show REPORT
  2. display information about the running firewall. See REPORTS
  3. 显示运行中的防火墙信息。参见REPORTS
  1. allow ARGS
  2. add allow rule. See RULE SYNTAX
  3. 增加允许规则。参见 RULE SYNTAX
  1. deny ARGS
  2. add deny rule. See RULE SYNTAX
  3. 增加拒绝规则。参见 RULE SYNTAX
  1. reject ARGS
  2. add reject rule. See RULE SYNTAX
  3. 增加抵制规则。参见 RULE SYNTAX
  1. limit ARGS
  2. add limit rule. Currently only IPv4 is supported. See RULE SYNTAX
  3. 增加限制规则。目前仅适用于IPv4。参见 RULE SYNTAX
  1. delete RULE|NUM
  2. deletes the corresponding RULE
  3. 删除对应RULE
  1. insert NUM RULE
  2. insert the corresponding RULE as rule number NUM
  3. 以规则号NUM插入对应RULE

RULE SYNTAX规则语法

  1. Users can specify rules using either a simple syntax or a full syntax. The sim
  2. ple syntax only specifies the port and optionally the protocol to be allowed or
  3. denied on the host. For example:
  4. 用户可以使用简略或完全语法指定规则。简略语法仅指定端口、可选协议被主机允许\拒绝。例如:

允许使用53端口

  1. ufw allow 53
  1. This rule will allow tcp and udp port 53 to any address on this host. To specify
  2. a protocol, append '/protocol' to the port. For example:
  3. 规则意为,允许本机通过53端口使用tcp udp协议指向任意地址的信息(一个物理网卡可以包含1或多个IP地址)。指定协议,在端口后加 / 即可。例如:

允许使用通过tcp协议使用25端口

  1. ufw allow 25/tcp
  1. This will allow tcp port 25 to any address on this host. ufw will also check
  2. /etc/services for the port and protocol if specifying a service by name. Eg:
  3. 规则意为,允许本机通过25端口使用tcp协议指向任意地址(进入)的信息。如果指定服务名称,ufw会通过检查/etc/services文件获得端口、协议信息。例如:

允许smtp应用

  1. ufw allow smtp
  1. ufw supports both ingress and egress filtering and users may optionally specify
  2. a direction of either in or out for either incoming or outgoing traffic. If no
  3. direction is supplied, the rule applies to incoming traffic. Eg:
  4. ufw同时支持出、入过滤。用户可以使用in\out规定任意方向进出的数据。如果未指定方向,规则将应用于进入的数据。如:

允许http应用数据进入本机

  1. ufw allow in http

拒绝并告知:拒绝从本机发出smtp应用数据

  1. ufw reject out smtp
  1. Users can also use a fuller syntax, specifying the source and destination
  2. addresses and ports. This syntax is loosely based on OpenBSD's PF syntax. For
  3. example:
  4. 用户也可以使用完整语法,指明来源\目标,地址,端口。该语法是OpenBSD PF语法的简约版。例如:

拒绝指向任意地址使用80端口tcp协议的数据进入本机

  1. ufw deny proto tcp to any port 80
  1. This will deny all traffic to tcp port 80 on this host. Another example:
  2. 该规则:本机拒绝80端口使用tcp协议指向任意地址(进入)的信息。再如:

拒绝来自10.0.0.0/8域tcp协议指向192.168.0.1端口25的数据进入本机

  1. ufw deny proto tcp from 10.0.0.0/8 to 192.168.0.1 port 25
  1. This will deny all traffic from the RFC1918 Class A network to tcp port 25 with
  2. the address 192.168.0.1.
  3. 该规则将阻断(拒绝)所有来自RFC1918 A级网络(10.0.0.0-10.255.255.255)通过25端口使用tcp协议发送到192.168.0.1的信息。

拒绝来自 2001:db8::/32域指向任意地址端口25的数据进入本机

  1. ufw deny proto tcp from 2001:db8::/32 to any port 25
  1. This will deny all traffic from the IPv6 2001:db8::/32 to tcp port 25 on this
  2. host. IPv6 must be enabled in /etc/default/ufw for IPv6 firewalling to work.
  3. 该规则将拒绝本机接收所有来自IPv6 2001:db8::/32 通过25端口使用tcp(进入)的信息。/etc/default/ufw配置文件需开通IPv6功能。

允许来自任意地址使用tcp协议指向任意地址使用端口80、443、8080-8090的数据进入本机

  1. ufw allow proto tcp from any to any port 80,443,8080:8090
  1. The above will allow all traffic to tcp ports 80, 443 and 8080-8090 inclusive.
  2. When specifying multiple ports, the ports list must be numeric, cannot contain
  3. spaces and must be modified as a whole. Eg, in the above example you cannot
  4. later try to delete just the '443' port. You cannot specify more than 15 ports
  5. (ranges count as 2 ports, so the port count in the above example is 4).
  6. 该规则允许本机通过8044380808090端口使用tcp协议(进入)的信息。指定多个端口时,只能使用数字,且不能含空格。修改规则时需整条规则修改。在上面的例子中,你不能仅仅删除443端口。每次指定不能超过15个端口(端口区间视为2个端口,上面例子视为4个端口)
  1. Rules for traffic not destined for the host itself but instead for traffic that
  2. should be routed/forwarded through the firewall should specify the route keyword
  3. before the rule (routing rules differ significantly from PF syntax and instead
  4. take into account netfilter FORWARD chain conventions). For example:
  5. 规则中数据目标不是本机,是经本机防火墙路由\转发,规则前需加关键字route(路由规则与PF语法有明显的不同,替之以FORWARD链转换)。

允许经eth1进入,eth2发出的数据经本机路由

  1. ufw route allow in on eth1 out on eth2
  1. This will allow all traffic routed to eth2 and coming in on eth1 to traverse the
  2. firewall.
  3. 该规则允许数据由eth1网卡进入路由至eth2网卡发出。

允许经eth0进入eth1发出指向 12.34.45.67使用80端口tcp的数据经本机路由

  1. ufw route allow in on eth0 out on eth1 to 12.34.45.67 port 80 proto tcp
  1. This rule allows any packets coming in on eth0 to traverse the firewall out on
  2. eth1 to tcp port 80 on 12.34.45.67.
  3. 该规则允许数据经eth0网卡进入路由至eth1网卡通过80端口使用tcp协议发送至IP12.34.45.56
  1. In addition to routing rules and policy, you must also setup IP forwarding.
  2. This may be done by setting the following in /etc/ufw/sysctl.conf:
  3. 增加路由规则前必需设置IP转发。该配置文件/etc/ufw/sysctl.conf,配置内容应如下:
  1. net/ipv4/ip_forward=1
  2. net/ipv6/conf/default/forwarding=1
  3. net/ipv6/conf/all/forwarding=1
  1. then restarting the firewall:
  2. 再使用以下命令重启防火墙:
  1. ufw disable
  2. ufw enable
  1. Be aware that setting kernel tunables is operating system specific and ufw
  2. sysctl settings may be overridden. See the sysctl manual page for details.
  3. 请小心,该操作系统内核可调参数设置会覆盖ufw内核(sysctl)设置。参见sysctl手册。
  1. ufw supports connection rate limiting, which is useful for protecting against
  2. brute-force login attacks. When a limit rule is used, ufw will normally allow
  3. the connection but will deny connections if an IP address attempts to initiate 6
  4. or more connections within 30 seconds. See [http://www.debian-administra‐](http://www.debian-administra‐)
  5. tion.org/articles/187 for details. Typical usage is:
  6. ufw支持连接次数限制。可用于对抗暴力登录攻击。启用限制规则后,ufw允许连接,但30秒内连接次数高于6次时拒绝该IP访问。参见http://www.debian-administration.org/articles/187。典型用法如下:

限制ssh tcp协议连接本机次数

  1. ufw limit ssh/tcp
  1. Sometimes it is desirable to let the sender know when traffic is being denied,
  2. rather than simply ignoring it. In these cases, use reject instead of deny. For
  3. example:
  4. 有时需要让发送数据者知道数据被拒绝而不是失踪。在下面例子中,用户使用reject替换deny。例如:
  1. ufw reject auth
  1. By default, ufw will apply rules to all available interfaces. To limit this,
  2. specify DIRECTION on INTERFACE, where DIRECTION is one of in or out (interface
  3. aliases are not supported). For example, to allow all new incoming http connec
  4. tions on eth0, use:
  5. 默认情况下,ufw将规则应用于所有可用网络接口。也可把规则指定到特定的网络接口,包括网络接口数据进出方向(不支持网络接口别名)。例如允许数据通过eth0网卡使用http协议进入主机,写法如下:

允许通过eth0指向任意地址端口80协议tcp的数据进入本机

  1. ufw allow in on eth0 to any port 80 proto tcp
  1. To delete a rule, simply prefix the original rule with delete. For example, if
  2. the original rule was:
  3. 要删除一条规则,在原规则前加delete就可以了。例如:原规则是这样的
  1. ufw deny 80/tcp
  1. Use this to delete it:
  2. 删除时就这样写:
  1. ufw delete deny 80/tcp
  1. You may also specify the rule by NUM, as seen in the status numbered output. For
  2. example, if you want to delete rule number '3', use:
  3. 你也可以使用status numbered参数查看规则序号。比如你想删除第3条规则,这样写就行了:
  1. ufw delete 3
  1. If you have IPv6 enabled and are deleting a generic rule that applies to both
  2. IPv4 and IPv6 (eg 'ufw allow 22/tcp'), deleting by rule number will delete only
  3. the specified rule. To delete both with one command, prefix the original rule
  4. with delete.
  5. 如果IPv6启用,你想删除一条同时适用于IPv4IPv6的规则(如ufw allow 22/tcp),使用序号删除规则只会删除其中一条。一次性删

除干净就只能使用原规则前加delete的办法。

  1. To insert a rule, specify the new rule as normal, but prefix the rule with the
  2. rule number to insert. For example, if you have four rules, and you want to
  3. insert a new rule as rule number three, use:
  4. 为使用规则正常,你可以使用序号的方式插入新规则。例如,你有4条规则了,但你想把新规则放到第3的位置,可以这样写:

把 拒绝来自 10.0.0.135协议tcp指向任意地址端口22的数据进入本机 指条命令插入到第3的位置

  1. ufw insert 3 deny to any port 22 from 10.0.0.135 proto tcp
  1. To see a list of numbered rules, use:
  2. 查询规则序号,使用命令:
  1. ufw status numbered
  1. ufw supports per rule logging. By default, no logging is performed when a packet
  2. matches a rule. Specifying log will log all new connections matching the rule,
  3. and log-all will log all packets matching the rule. For example, to allow and
  4. log all new ssh connections, use:
  5. ufw支持规则运行状态日志。默认情况下符合规则的数据日志不显示。指定日志会记录下所有符合规则的数据、新连接。例如:允许并

记录所有新ssh连接。命令如下

  1. ufw allow log 22/tcp
  1. See LOGGING for more information on logging.
  2. 参见LOGGING

EXAMPLES例子

  1. Deny all access to port 53:

拒绝所有通过53端口的数据

  1. ufw deny 53
  1. Allow all access to tcp port 80:

允许所有通过80端口使用tcp的数据

  1. ufw allow 80/tcp
  1. Allow all access from RFC1918 networks to this host:

允许所有来自RFC1918网络的数据进入本机

  1. ufw allow from 10.0.0.0/8
  2. ufw allow from 172.16.0.0/12
  3. ufw allow from 192.168.0.0/16
  1. Deny access to udp port 514 from host 1.2.3.4:

拒绝来自1.2.3.4主机通过514端口使用udp协议的数据

  1. ufw deny proto udp from 1.2.3.4 to any port 514
  1. Allow access to udp 1.2.3.4 port 5469 from 1.2.3.5 port 5469:

允许来自主机1.2.3.5端口5469的数据到达本机1.2.3.4使用端口5469协议udp

  1. ufw allow proto udp from 1.2.3.5 port 5469 to 1.2.3.4 port 5469

REMOTE MANAGEMENT远程管理

  1. When running ufw enable or starting ufw via its initscript, ufw will flush its
  2. chains. This is required so ufw can maintain a consistent state, but it may drop
  3. existing connections (eg ssh). ufw does support adding rules before enabling the
  4. firewall, so administrators can do:

通过初始化脚本或命令启动ufw后,ufw将刷新连接。这是为了让ufw运行正常。但可能导致现有连接中断(如ssh)。ufw支持在启动前增加规则,在运行“ufw enable”命令前,管理者可以增加这个规则来进行远程管理:

  1. ufw allow proto tcp from any to any port 22
  1. before running 'ufw enable'. The rules will still be flushed, but the ssh port
  2. will be open after enabling the firewall. Please note that once ufw is
  3. 'enabled', ufw will not flush the chains when adding or removing rules (but will
  4. when modifying a rule or changing the default policy). By default, ufw will
  5. prompt when enabling the firewall while running under ssh. This can be disabled
  6. by using 'ufw --force enable'.

所有规则将被激活,ssh连接在启用防火墙时依然开通。请注意只要ufw处于'enabled'状态,增加或删除规则,都不进行连接刷新(改变默认策略或修改规则时除外)。默认情况,ufw如果处于ssh远程连接下,规则影响到ssh连接时都需要确认。使用ufw —force enable命令时,就不需要确认了。

APPLICATION INTEGRATION应用集成(强烈推荐此方法)

  1. ufw supports application integration by reading profiles located in
  2. /etc/ufw/applications.d. To list the names of application profiles known to ufw,
  3. use:

ufw支持查询/etc/ufw/applications.d文件完成应用集成。查看ufw已知应用集成(其它端口,由ubuntu在安装软件时自动定义,一般不需要自己新建。具体端口参见/etc/services),命令:

  1. ufw app list
  1. Users can specify an application name when adding a rule (quoting any profile
  2. names with spaces). For example, when using the simple syntax, users can use:

用户在增加规则时能使用应用名(引用带有空格的任何配置文件名称)。例如,使用如下简单语法:

  1. ufw allow <name>
  1. Or for the extended syntax:

或完整语法:

  1. ufw allow from 192.168.0.0/16 to any app <name>
  1. You should not specify the protocol with either syntax, and with the extended
  2. syntax, use app in place of the port clause.

使用应用名代替端口时,语法中不能指定协议

  1. Details on the firewall profile for a given application can be seen with:

查看关于应用名的具体内容,使用如下命令。

  1. ufw app info <name>
  1. where '<name>' is one of the applications seen with the app list command.
  2. User's may also specify all to see the profiles for all known applications.
  3. app list命令可以显示有哪些应用名。使用all代替应用名时,上面的命令会例出所有已知程序详细情况。
  1. After creating or editing an application profile, user's can run:

增加或编辑了应用名相关内容,请使用下面命刷新:

  1. ufw app update <name>
  1. This command will automatically update the firewall with updated profile infor
  2. mation. If specify 'all' for name, then all the profiles will be updated. To
  3. update a profile and add a new rule to the firewall automatically, user's can
  4. run:

该命令将自动更新配置应用名。应用名为all时,会更新所有应用名。如果需要更新应用名配置且作为新规则加入防火墙,请使用下面的命令。

  1. ufw app update --add-new <name>
  1. The behavior of the update --add-new command can be configured using:

—add-new 命令参数进行更新时,其行为方式可由下面的命令指定

  1. ufw app default <policy>
  1. The default application policy is skip, which means that the update --add-new
  2. command will do nothing. Users may also specify a policy of allow or deny so the
  3. update --add-new command may automatically update the firewall. WARNING: it may
  4. be a security to risk to use a default allow policy for application profiles.
  5. Carefully consider the security ramifications before using a default allow pol
  6. icy.

默认应用策略是跳过,也就意味着 —add-new 命令参数实际上没设定策略。用户能指定策略为allow或deny, 那之后—add-new 参数将自动更新防火墙。警告:使用allow策略作为应用策略将有安全风险。使用默认允许的政策之前,要仔细考虑的安全后果。

LOGGING日志

  1. ufw supports multiple logging levels. ufw defaults to a loglevel of 'low' when a
  2. loglevel is not specified. Users may specify a loglevel with:

ufw支持多种日志级别。默认为“低”。用户可使用下面的命令指定日志级别:

  1. ufw logging LEVEL
  1. LEVEL may be 'off', 'low', 'medium', 'high' and 'full'. Log levels are defined
  2. as:

级别分为 关闭\低\中\高\完全。区别如下:

  1. off disables ufw managed logging

关闭 关闭日志记录

  1. low logs all blocked packets not matching the default policy (with rate lim
  2. iting), as well as packets matching logged rules

低 记录所有被默认策略阻止的数据(速率限制),以及符合规则的数据。

  1. medium log level low, plus all allowed packets not matching the default policy,
  2. all INVALID packets, and all new connections. All logging is done with
  3. rate limiting.

中 低级别+不符合默认策略是数据+无效数据+所有新连接。所有记录在速率限制下进行。

  1. high log level medium (without rate limiting), plus all packets with rate lim
  2. iting

高 中级(取消速率限制)+速率限制下的所有数据包

  1. full log level high without rate limiting

完全 高级无速率限制。

  1. Loglevels above medium generate a lot of logging output, and may quickly fill up
  2. your disk. Loglevel medium may generate a lot of logging output on a busy sys
  3. tem.

中级别以可能产生大量日志,有可能快速填满硬盘。对繁忙的系统而言,中级别就会有大量日志产生。

  1. Specifying 'on' simply enables logging at log level 'low' if logging is cur
  2. rently not enabled.

on参数在没启用日志时,默认指定为低级别。

REPORTS报告

  1. The following reports are supported. Each is based on the live system and with
  2. the exception of the listening report, is in raw iptables format:

支持如下报告。它们均基于活动系统排外的监听报告,属于原始的iptable形式。

  1. raw
  2. builtins
  3. before-rules
  4. user-rules
  5. after-rules
  6. logging-rules
  7. listening
  8. added
  1. The raw report shows the complete firewall, while the others show a subset of
  2. what is in the raw report.

raw显示完整报告。其它级别在此基础上精简。

  1. The listening report will display the ports on the live system in the listening
  2. state for tcp and the open state for udp, along with the address of the inter
  3. face and the executable listening on the port. An '*' is used in place of the
  4. address of the interface when the executable is bound to all interfaces on that
  5. port. Following this information is a list of rules which may affect connections
  6. on this port. The rules are listed in the order they are evaluated by the ker
  7. nel, and the first match wins. Please note that the default policy is not listed
  8. and tcp6 and udp6 are shown only if IPV6 is enabled.

报告显示活动系统监听下的tcp upd状态及地址 网络接口,以及可监听的端口。*号代表该端口绑定到网络接口。该信息之下是所有能影响到该端口连接的规则。规则的监听由内核、第1匹配wins排序。注意默认策略未被监听,tcp6 udp6只有在IPv6启用的情况下有效。

  1. The added report displays the list of rules as they were added on the com
  2. mand-line. This report does not show the status of the running firewall (use
  3. 'ufw status' instead). Because rules are normalized by ufw, rules may look dif
  4. ferent than the originally added rule. Also, ufw does not record command order
  5. ing, so an equivalent ordering is used which lists IPv6-only rules after other
  6. rules.

新增报告将显示规则加入时的命令列表。报告不显示防火墙此时的运行状态(请使用ufw status命查询)。因为规则已被ufw标准化,看起来与加入时原规则不同了。此外,UFW不记录命令排序,所以等效排序,仅IPv6的规则位于其他规则后。

NOTES注意

  1. On installation, ufw is disabled with a default incoming policy of deny, a
  2. default forward policy of deny, and a default outgoing policy of allow, with
  3. stateful tracking for NEW connections for incoming and forwarded connections.
  4. In addition to the above, a default ruleset is put in place that does the fol
  5. lowing:

安装后,ufw不启动,默认策略:进入数据拒绝,转发拒绝,发出数据允许。默认策略跟踪进入\转发的新连接。除此外还增加了下列默认规则集:

  1. - DROP packets with RH0 headers

丢弃含RH0头的数据

  1. - DROP INVALID packets

丢弃无效数据

  1. - ACCEPT certain icmp packets (INPUT and FORWARD): destination-unreachable,
  2. source-quench, time-exceeded, parameter-problem, and echo-request for IPv4. des
  3. tination-unreachable, packet-too-big, time-exceeded, parameter-problem, and
  4. echo-request for IPv6.

接受部分ICMP数据包(进入\转发):IPv4:目的地不可达,源结束,超过时间,参数问题,回声请求。IPv6:目的地不可达,分组太大而,超过时间,参数问题,回声请求。

  1. - ACCEPT icmpv6 packets for stateless autoconfiguration (INPUT)

接受ICMPv6报文的无状态自动配置(进入)

  1. - ACCEPT ping replies from IPv6 link-local (ffe8::/10) addresses (INPUT)

接受IPv6链路本地地址(ffe8::/10)ping应答(进入)

  1. - ACCEPT DHCP client traffic (INPUT)

接受DHCP客户端数据(进入)

  1. - DROP non-local traffic (INPUT)

丢弃非本地通讯(进入)

  1. - ACCEPT mDNS (zeroconf/bonjour/avahi 224.0.0.251 for IPv4 and ff02::fb for
  2. IPv6) for service discovery (INPUT)

接受mDNS服务(zeroconf/bonjour/avahi 等协议使用,IPv4 224.0.0.251,IPv6 ff02::fb)(进入)

  1. - ACCEPT UPnP (239.255.255.250 for IPv4 and ff02::f for IPv6) for service dis
  2. covery (INPUT)

接受UPnP服务(IPv4:239.255.255.250 ,IPv6:ff02::f ) (进入)

  1. Rule ordering is important and the first match wins. Therefore when adding
  2. rules, add the more specific rules first with more general rules later.

规则的顺序很重要,依次匹配执行。因此先添加针对性强的规则,再添加影响广泛的规则。

  1. ufw is not intended to provide complete firewall functionality via its command
  2. interface, but instead provides an easy way to add or remove simple rules.

UFW不打算通过自身命令提供完整的防火墙功能,而是提供了一种简单的方法来添加或删除简单的规则。

  1. The status command shows basic information about the state of the firewall, as
  2. well as rules managed via the ufw command. It does not show rules from the rules
  3. files in /etc/ufw. To see the complete state of the firewall, users can ufw show
  4. raw. This displays the filter, nat, mangle and raw tables using:

status命令显示防火墙的状态及通过UFW命令管理的基本信息规则。它不显示/ etc/ UFW文件的规则。要查看防火墙的完整状态,用户可以UFW显示原料。这将显示过滤,NAT,损坏和原始表,命令如下:

  1. iptables -n -L -v -x -t <table>
  1. ip6tables -n -L -v -x -t <table>
  1. See the iptables and ip6tables documentation for more details.

更多信息查看iptables ip6tables

  1. If the default policy is set to REJECT, ufw may interfere with rules added out
  2. side of the ufw framework. See README for details.

如果默认策略设置为REJECT,UFW可能会干扰UFW框架之外添加的规则。

  1. IPV6 is allowed by default. To change this behavior to only accept IPv6 traffic
  2. on the loopback interface, set IPV6 to 'no' in /etc/default/ufw and reload ufw.
  3. When IPv6 is enabled, you may specify rules in the same way as for IPv4 rules,
  4. and they will be displayed with ufw status. Rules that match both IPv4 and IPv6
  5. addresses apply to both IP versions. For example, when IPv6 is enabled, the fol
  6. lowing rule will allow access to port 22 for both IPv4 and IPv6 traffic:

IPv6是默认允许。改变这种行为,只接受在回环接口上的IPv6数据,在/ etc/default/ UFW将IPv6设置为“no”,并重新加载UFW。当启用IPv6,则可以以相同的方式针对IPv4规则指定的规则,它们将在ufw status命令下被显示。同时匹配IPv4和IPv6地址的规则适用于两个IP版本。例如,当启用IPv6,下面的规则将同时允许IPv4和IPv6访问端口22为:

  1. ufw allow 22
  1. IPv6 over IPv4 tunnels and 6to4 are supported by using the 'ipv6' protocol
  2. ('41'). This protocol can only be used with the full syntax. For example:

IPv4借用IPv6进行封装时,需使用第41号协议。书写时使用proto ipv6,并且使用完整语法。例如:

  1. ufw allow to 10.0.0.1 proto ipv6
  2. ufw allow to 10.0.0.1 from 10.4.0.0/16 proto ipv6
  1. IPSec is supported by using the 'esp' ('50') and 'ah' ('51') protocols. These
  2. protocols can only be used with the full syntax. For example:

支持使用“Internet 协议安全性 (IPSec)”协议,协议书写为esp \ ah(分别是50号\51号协议)。语法必需使用完整结构。例如:

  1. ufw allow to 10.0.0.1 proto esp
  2. ufw allow to 10.0.0.1 from 10.4.0.0/16 proto esp
  3. ufw allow to 10.0.0.1 proto ah
  4. ufw allow to 10.0.0.1 from 10.4.0.0/16 proto ah
  1. In addition to the command-line interface, ufw also provides a framework which
  2. allows administrators to modify default behavior as well as take full advantage
  3. of netfilter. See the ufw-framework manual page for more information.

除了命令行界面,UFW还提供了一个框架,允许管理员修改默认的行为,达到对网络过滤功能充分利用。见UFW-framework手册页了解更多信息。

SEE ALSO

  1. ufw-framework(8), iptables(8), ip6tables(8), iptables-restore(8),
  2. ip6tables-restore(8), sysctl(8), sysctl.conf(5)

AUTHOR

  1. ufw is Copyright 2008-2014, Canonical Ltd.
  1. ufw and this manual page was originally written by Jamie Strandboge
  2. <jamie@canonical.com>

原文:

http://wiki.ubuntu.org.cn/Ufw%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97