Skip to content

Instantly share code, notes, and snippets.

@netnr
Last active Aug 9, 2021
Embed
What would you like to do?
Ubuntu ufw 防火墙
apt install ufw # 安装
ufw disable # 禁用
apt-get remove ufw # 卸载
apt-get purge ufw # 清除
ufw status # 查看
ufw enable # 启用
ufw disable # 关闭
ufw default deny # 配置默认拒绝
ufw allow | deny [service] # 配置允许、拒绝
ufw allow ssh # 配置 SSH
ufw allow 80/tcp # 允许 80(tcp)
ufw allow 443/tcp # 允许 443(tcp)
ufw allow 80 # 允许 80(tcp/udp)
ufw allow 6000:7000/tcp # 允许 6000-7000
ufw allow from 192.168.1.188 # 允许指定 IP 访问所有端口
ufw allow proto tcp from 192.168.0.0/24 to any port 22 # 允许指定 IP 段访问特定 tcp 端口
ufw delete allow 80 # 删除
ufw reload # 重启
# ufw 配置后,还需要 iptables 开放
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
iptables-save > /root/iptables # 保存
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment