目录
1. 前提条件
- 防火墙是开启状态
2. 开启防火墙
1)查看防火墙状态
[root@afanty bin]# systemctl status firewalld.service
2)开启防火墙(临时)
[root@afanty bin]# systemctl start firewalld.service
3)开启防火墙(开机自启)
[root@afanty bin]# systemctl enable firewalld.service
3. 开放指定端口
1)添加端口
[root@afanty bin]# firewall-cmd --zone=public --add-port=2181/tcp --permanent
ps:
--zone #作用域
--add-port=2181/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
2)重启防火墙
[root@afanty bin]# systemctl restart firewalld.service
3)查看已添加的端口
[root@afanty bin]# firewall-cmd --list-ports
4. 关闭指定端口
1)移除端口
[root@afanty zookeeper-3.7.0]# firewall-cmd --zone=public --remove-port=2181/tcp --permanent
2)重启防火墙
[root@afanty bin]# systemctl restart firewalld.service
5. 其他命令
1)关闭防火墙(临时)
[root@afanty zookeeper-3.7.0]# systemctl stop firewalld.service
2)关闭防火墙(永久)
[root@afanty zookeeper-3.7.0]# systemctl disable firewalld.service