ufw安装:
apt-get install ufw
查看端口开启状态:
ufw status
允许185.192.58.0访问本机的22端口
ufw allow from 185.192.58.0/32 to any port 22
允许185.192.58.0访问本机的22TCP端口
ufw allow from 185.192.58.0 to any port 22 proto tcp
允许外部访问8381/tcp:
ufw allow 8381/tcp
允许外部访问8381端口(tcp/udp):
ufw allow 8381
开启防火墙:
ufw enable
出现iptables-restore错误
apt purge ufw iptables
apt install iptables
update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
apt install ufw
关闭防火墙:
ufw disable
重启防火墙:
ufw reload
查看端口ip
netstat -ltn
- netstat安装
apt install net-tools
禁止外部某个端口比如80
ufw delete allow 80
彻底重置 UFW 规则(会清空所有自定义规则并暂时禁用)
ufw --force reset
设置默认策略为拒绝所有入站
ufw default deny incoming
ufw default allow outgoing
允许指定的单个 IPv4访问所有端口:
ufw allow from 192.168.254.254
允许指定的单个 IPv6 访问所有端口:
ufw allow from 2xxx:xxxx:xxxx:xxxx::3
检查最终规则状态
ufw status verbose
删除上面的规则
ufw delete allow from 192.168.254.254
修改22端口
nano /etc/ssh/sshd_config
重启sshd服务
systemctl restart sshd