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
允许某特定 IP
ufw allow from 192.168.254.254
删除上面的规则
ufw delete allow from 192.168.254.254
修改22端口
nano /etc/ssh/sshd_config
重启sshd服务
systemctl restart sshd