ubuntu防火墙配置_如何配置Ubuntu的内置防火墙

ubuntu防火墙配置

ubuntu防火墙配置

image

Ubuntu includes its own firewall, known as ufw – short for “uncomplicated firewall.” Ufw is an easier-to-use frontend for the standard Linux iptables commands. You can even control ufw from a graphical interface.

Ubuntu包含自己的防火墙,称为ufw –“简单防火墙”的缩写。 Ufw是标准Linux iptables命令的易于使用的前端。 您甚至可以从图形界面控制ufw。

Ubuntu’s firewall is designed as an easy way to perform basic firewall tasks without learning iptables. It doesn’t offer all the power of the standard iptables commands, but it’s less complex.

Ubuntu的防火墙被设计为无需学习iptables即可执行基本防火墙任务的简便方法。 它不能提供标准iptables命令的所有功能,但是它不那么复杂。

终端使用 (Terminal Usage)

The firewall is disabled by default. To enable the firewall, run the following command from a terminal:

默认情况下禁用防火墙。 要启用防火墙,请在终端上运行以下命令:

sudo ufw enable

sudo ufw启用

You don’t necessarily have to enable the firewall first. You can add rules while the firewall is offline, and then enable it after you’re done configuring it.

您不一定必须先启用防火墙。 您可以在防火墙脱机时添加规则,然后在完成配置后将其启用。

image

使用规则 (Working With Rules)

Let’s say you want to allow SSH traffic on port 22. To do so, you can run one of several commands:

假设您要允许端口22上的SSH流量。为此,您可以运行以下命令之一:

sudo ufw allow 22 (Allows both TCP and UDP traffic – not ideal if UDP isn’t necessary.)

sudo ufw allow 22(同时允许TCP和UDP流量–如果不需要UDP,则不理想。)

sudo ufw allow 22/tcp  (Allows only TCP traffic on this port.)

sudo ufw allow 22 / tcp(仅允许该端口上的TCP通信。)

sudo ufw allow ssh (Checks the /etc/services file on your system for the port that SSH requires and allows it. Many common services are listed in this file.)

sudo ufw allow ssh(检查系统上的/ etc / services文件中是否包含SSH所需的端口,并允许它使用。此文件中列出了许多常用的服务。)

Ufw assumes you want to set the rule for incoming traffic, but you can also specify a direction. For example, to block outgoing SSH traffic, run the following command:

Ufw假定您要为传入流量设置规则,但是您也可以指定方向。 例如,要阻止传出的SSH流量,请运行以下命令:

sudo ufw reject out ssh

sudo ufw拒绝ssh

You can view the rules you’ve created with the following command:

您可以使用以下命令查看已创建的规则:

sudo ufw status

sudo ufw状态

image

To delete a rule, add the word delete before the rule. For example, to stop rejecting outgoing ssh traffic, run the following command:

要删除规则,请在规则之前添加单词delete。 例如,要停止拒绝传出的ssh通信,请运行以下命令:

sudo ufw delete reject out ssh

sudo ufw删除拒绝SSH

Ufw’s syntax allows for fairly complex rules. For example, this rule denies TCP traffic from the IP 12.34.56.78 to port 22 on the local system:

Ufw的语法允许使用相当复杂的规则。 例如,此规则拒绝从IP 12.34.56.78到本地系统上端口22的TCP通信:

sudo ufw deny proto tcp from 12.34.56.78 to any port 22

sudo ufw拒绝从12.34.56.78到任何端口22的proto tcp

To reset the firewall to its default state, run the following command:

要将防火墙重置为其默认状态,请运行以下命令:

sudo ufw reset

sudo ufw重置

image

应用资料 (Application Profiles)

Some applications requiring open ports come with ufw profiles to make this even easier. To see the application profiles available on your local system, run the following command:

某些需要打开端口的应用程序附带ufw配置文件,以使其变得更加容易。 要查看本地系统上可用的应用程序概要文件,请运行以下命令:

sudo ufw app list

sudo ufw应用程序列表

image

View information about a profile and its included rules with the following command:

使用以下命令查看有关配置文件及其包含的规则的信息:

sudo ufw app info Name

sudo ufw应用程序信息名称

image

Allow an application profile with the allow command:

使用allow命令允许应用程序配置文件:

sudo ufw allow Name

sudo ufw允许名称

image

更多信息 (More Information)

Logging is disabled by default, but you can also enable logging to print firewall messages to the system log:

默认情况下,日志记录是禁用的,但是您也可以启用日志记录以将防火墙消息打印到系统日志中:

sudo ufw logging on

sudo ufw登录

For more information, run the man ufw command to read ufw’s manual page.

有关更多信息,请运行man ufw命令以阅读ufw的手册页。

GUFW图形界面 (GUFW Graphical Interface)

GUFW is a graphical interface for ufw. Ubuntu doesn’t come with a graphical interface, but gufw is included in Ubuntu’s software repositories. You can install it with the following command:

GUFW是ufw的图形界面。 Ubuntu没有附带图形界面,但是gufw包含在Ubuntu的软件存储库中。 您可以使用以下命令进行安装:

sudo apt-get install gufw

须藤apt-get install gufw

GUFW appears in the Dash as an application named Firewall Configuration. Like ufw itself, GUFW provides a simple, easy-to-use interface. You can easily enable or disable the firewall, control the default policy for inbound or outbound traffic, and add rules.

GUFW作为名为“防火墙配置”的应用程序出现在Dash中。 像ufw本身一样,GUFW提供了一个简单易用的界面。 您可以轻松启用或禁用防火墙,控制入站或出站流量的默认策略以及添加规则。

image

The rules editor can be used to add simple rules or more complicated ones.

规则编辑器可用于添加简单规则或更复杂的规则。

image


Remember, you can’t do everything with ufw – for more complicated firewall tasks, you’ll have to get your hands dirty with iptables.

请记住,您不能使用ufw来做所有的事情–对于更复杂的防火墙任务,您必须动手使用iptables。

翻译自: https://www.howtogeek.com/115116/how-to-configure-ubuntus-built-in-firewall/

ubuntu防火墙配置

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值