腾讯云Ubuntu Server 18.04 LTS 64位云服务器配置ufw防火墙

这里写自定义目录标题

一、概述

1、腾讯云Ubuntu Server 18.04 LTS默认配置的是ufw防火墙。相对于 iptables,ufw 使用起来非常方便,真正地简化了 ​​​​​​iptables。
2、ufw,即简单防火墙(Uncomplicated FireWall)),从出现至今短短时间,就成了 Ubuntu 和 Debian 等系统上的默认防火墙。由于简单,对新手Linux操作者来说是一个福音。
3、本文仅探讨Linux上的ufw防火墙,包括更改防火墙的一些命令和一些见解。

二、ufw 常用命令

1、安装ufw。虽然ufw是Ubuntu等系统的默认防火墙,但是若是系统本来没有带ufw,或是系统有其它操作需要重新安装ufw,则可以使用下述命令:

sudo apt install ufw

2、我们可以在/etc/default/ufw路径下快速查看 ufw 配置,以及它的配置文件。

sudo vim /etc/default/ufw

其结果为:

# /etc/default/ufw
#

# Set to yes to apply rules to support IPv6 (no means only IPv6 on loopback
# accepted). You will need to 'disable' and then 'enable' the firewall for
# the changes to take affect.
IPV6=yes

# Set the default input policy to ACCEPT, DROP, or REJECT. Please note that if
# you change this you will most likely want to adjust your rules.
DEFAULT_INPUT_POLICY="DROP"

# Set the default output policy to ACCEPT, DROP, or REJECT. Please note that if
# you change this you will most likely want to adjust your rules.
DEFAULT_OUTPUT_POLICY="ACCEPT"

# Set the default forward policy to ACCEPT, DROP or REJECT.  Please note that
# if you change this you will most likely want to adjust your rules
DEFAULT_FORWARD_POLICY="DROP"

# Set the default application policy to ACCEPT, DROP, REJECT or SKIP. Please
# note that setting this to ACCEPT may be a security risk. See 'man ufw' for
# details
DEFAULT_APPLICATION_POLICY="SKIP"

# By default, ufw only touches its own chains. Set this to 'yes' to have ufw
# manage the built-in chains too. Warning: setting this to 'yes' will break
# non-ufw managed firewall rules
MANAGE_BUILTINS=no

#
# IPT backend
#
# only enable if using iptables backend
IPT_SYSCTL=/etc/ufw/sysctl.conf

# Extra connection tracking modules to load. Complete list can be found in
# net/netfilter/Kconfig of your kernel source. Some common modules:
# nf_conntrack_irc, nf_nat_irc: DCC (Direct Client to Client) support
# nf_conntrack_netbios_ns: NetBIOS (samba) client support
# nf_conntrack_pptp, nf_nat_pptp: PPTP over stateful firewall/NAT
# nf_conntrack_ftp, nf_nat_ftp: active FTP support
# nf_conntrack_tftp, nf_nat_tftp: TFTP support (server side)
# nf_conntrack_sane: sane support
IPT_MODULES="nf_conntrack_ftp nf_nat_ftp nf_conntrack_netbios_ns"

3、启动ufw命令

sudo ufw enable

4、查看当前防火墙状态,inactive表示ufw防火墙未被启用,active表示已经启用。

sudo ufw status

在这里插入图片描述

在这里插入图片描述
5、允许访问一个端口

sudo ufw allow 80#允许80端口访问,包括tcp和udp
sudo ufw allow 443#允许443端口访问,包括tcp和udp

6、允许一个端口段访问

sudo ufw allow 8000:8080/tcp
sudo ufw allow 8000:8080/udp

注:此处必须指定是tcp还是udp
7、禁止端口访问

sudo ufw deny 9000#禁止9000端口访问

8、指定ip地址

# 允许ip地址访问任意端口
sudo ufw allow from 192.168.0.100

# 运行ip地址访问指定端口
sudo ufw allow from 192.168.0.101 to any port 3306

# 指定一个网段访问端口
sudo ufw allow from 192.168.0.0/24 to any port 3306

9、删除指定的规则

sudo ufw delete deny 9000

# 删除指定编号的规则
sudo ufw delete 5#数字5代表规则列表的编号

三、小结

以上就是在腾讯云Ubuntu Server 18.04 LTS 64位云服务器配置ufw防火墙的一些小知识。希望能帮助到大家。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值