author:troy
website : https://www.zygd.site
statement : Some source networks
1. 安装
sudo apt-get install ufw
2. 启用
sudo ufw enable
sudo ufw default deny
sudo ufw allow|deny [service]
sudo ufw allow smtp 允许所有的外部IP访问本机的25/tcp (smtp)端口
sudo ufw allow 22/tcp 允许所有的外部IP访问本机的22/tcp (ssh)端口
sudo ufw allow 53 允许外部访问53端口(tcp/udp)
sudo ufw allow from 192.168.1.100 允许此IP访问所有的本机端口
sudo ufw allow proto udp 192.168.0.1 port 53 to 192.168.0.2 port 53
sudo ufw deny smtp 禁止外部访问smtp服务
sudo ufw delete allow smtp 删除上面建立的某条规则
sudo ufw status
sudo apt-get install ufw
sudo ufw enable
sudo ufw default deny
以上三条命令已经足够安全了,如果你需要开放某些服务,再使用sudo ufw allow开启。
开启/关闭防火墙 (默认设置是’disable’)
sudo ufw enable|disable
sudo ufw logging on|off
sudo ufw default allow|deny
sudo ufw allow|deny [service]
sudo ufw status
sudo ufw allow 53
sudo ufw delete allow 53
sudo ufw allow 80/tcp
sudo ufw delete allow 80/tcp
sudo ufw allow smtp
sudo ufw delete allow smtp
sudo ufw allow from 192.168.254.254
sudo ufw delete allow from 192.168.254.254
yum install firewalld
yum install firewall-config
开启防火墙
systemctl start firewalld.service
防火墙开机启动
systemctl enable firewalld.service
关闭防火墙
systemctl stop firewalld.service
查看防火墙状态
firewall-cmd --state
查看现有的规则
iptables -nL
重载防火墙配置
firewall-cmd --reload
添加单个单端口
firewall-cmd --permanent --zone=public --add-port=81/tcp
添加多个端口
firewall-cmd --permanent --zone=public --add-port=8080-8083/tcp
删除某个端口
firewall-cmd --permanent --zone=public --remove-port=81/tcp
针对某个 IP开放端口
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="6379" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.233" accept"
删除某个IP
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.1.51" accept"
针对一个ip段访问
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="9200" accept"
添加操作后别忘了执行重载
firewall-cmd --reload
查看指定级别的所有信息,譬如 public
firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client http ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
原文:https://www.cnblogs.com/zygd/p/13915746.html