设置firewalld 允许指定IP访问某端口

1. 打开firewalld防火墙

systemctl start firewalld.service

2. 添加防火墙规则(对指定ip开放指定端口)

 Postgresql端口设置。允许192.168.142.166访问5432端口

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="5432" accept"

redis端口设置。允许192.168.142.166访问6379端口

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="6379" accept"

3. 重启防火墙,使配置生效

systemctl restart firewalld.service

4. 查看配置结果,验证配置

firewall-cmd --list-all

5. 删除规则

firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="11300" accept"
 
systemctl restart firewalld.service

则查询端口是否打开

firewall-cmd    --query-port=6379/tcp

firewall-cmd --zone=public --add-port=80/tcp --permanent

命令含义:

--zone #作用域

--add-port=80/tcp  #添加端口,格式为:端口/通讯协议

--permanent  #永久生效,没有此参数重启后失效

 

 

你可能感兴趣的:(服务器技术)