跟着示例学Ubuntu UFW防火墙设置

# 安装ufw防火墙

sudo apt install ufw

 

# 启用UFW

sudo ufw enable

 

# 默认设置 UFW 为:

# 拒绝所有传入连接,

# 并允许所有传出连接。

sudo ufw default deny incoming

sudo ufw default allow outgoing

 

# 允许端口示例

sudo ufw allow 20/tcp

sudo ufw allow 21/tcp

sudo ufw allow 22

sudo ufw allow 53

sudo ufw allow 80

sudo ufw allow 443

sudo ufw allow 8080

 

sudo ufw allow 6000:6007/tcp

sudo ufw allow 6000:6007/udp

sudo ufw allow from 192.168.3.160

sudo ufw allow from 192.168.3.160 to any port 22

sudo ufw allow from 192.168.3.0/24

sudo ufw allow from 192.168.3.0/24 to any port 22

 

# 允许内部所有私有地址访问该主机:

sudo ufw allow from 10.0.0.0/8

sudo ufw allow from 172.16.0.0/12

sudo ufw allow from 192.168.0.0/16

 

# 高级设置,结合网络端口进行控制

sudo ufw allow in on eth0 to any port 80

sudo ufw allow in on eth1 to any port 3306

 

# 拒绝端口示例

sudo ufw deny 80

sudo ufw deny from 192.168.3.160

 

# 删除端口示例

sudo ufw delete allow 22

sudo ufw delete allow 53

sudo ufw delete allow 80

sudo ufw delete allow 443

sudo ufw delete allow 80

 

 

# 查看防火墙的状态

sudo ufw status verbose

sudo ufw status numbered

 

# 防火墙搞乱了?重置一下:

sudo ufw reset

 

# 关闭UFW

sudo ufw disable

 

# 相关配置文件:

/etc/default/ufw

/etc/ufw/before.rules

/etc/ufw/after.rules

/etc/ufw/sysctl.conf

/etc/ufw/ufw.conf

/etc/ufw/maps

/var/lib/ufw/maps

/var/lib/ufw/user.rules

/etc/services

你可能感兴趣的:(网络安全)