linux 的防火墙简单设置
1. 检查防火墙状态
- 代码
firewall-cam --state
[root@localhost ~]# firewall-cmd --state
running
[root@localhost ~]
2. 防火墙配置
- linux系统中有个配置文件,里面配置了开机后防火墙应该怎么工作
[root@localhost ~]# firewall-cmd --state
running
[root@localhost ~]#
- 关闭防火墙
[root@localhost ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# firewall-cmd --state
running
[root@localhost ~]#
- 开启防火墙
systemctl enable firewalld.service
- 但是,只会在下一次开机后才会启用当前配置
3. 手动关闭防火墙
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# firewall-cmd --state
not running
[root@localhost ~]#
4. 手动开启防火墙
[root@localhost ~]# systemctl start firewalld.service
[root@localhost ~]# firewall-cmd --state
running
[root@localhost ~]#
5. 检查开放的端口
firewall-cmd --list-ports
6. 查询指定端口
[root@localhost ~]# firewall-cmd --query-port=80/tcp
no
[root@localhost ~]#p
7. 开放指定端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost ~]#
可以开放一个范围的端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=19-21/tcp --permanent
success
[root@localhost ~]#
8. 移除指定端口
[root@localhost ~]# firewall-cmd --zone=public --remove-port=80/tcp --permanent
success
[root@localhost ~]#
也可以移除范围的端口
[root@localhost ~]# firewall-cmd --zone=public --remove-port=19-21/tcp --permanent
success
[root@localhost ~]#
注:开启或关闭了防火墙,需要重新加载防火墙后才会生效
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --query-port=80/tcp
yes
[root@localhost ~]#