Linux中centos7中防火墙知识篇

Linux防火墙知识篇

一. CentOS 6.5

1. 开放指定端口
/sbin/iptables -I INPUT -p tcp --dport 端口号 -j ACCEPT   //写入修改
/etc/init.d/iptables save                                //保存修改
service iptables restart               //重启防火墙,修改生效

2.关闭指定端口
/sbin/iptables -I INPUT -p tcp --dport 端口号 -j DROP   //写入修改
/etc/init.d/iptables save           //保存修改
service iptables restart    	 --重启防火墙,修改生效 

3.查看端口状态 
/etc/init.d/iptables status

二. CentOS 7

1.防火墙操作
启动:    	 		systemctl start firewalld
查看状态:	 		systemctl status firewalld 
停止:				systemctl disable firewalld
禁用:    	 		systemctl stop firewalld
停止防火墙:			systemctl stop firewalld.service 
重启防火墙:			systemctl restart firewalld.service   
禁止firewall开机启动:systemctl disable firewalld.service 
设置开机启用防火墙:	systemctl enable firewalld.service   

2.开放指定端口
firewall-cmd --zone=public --add-port=80/tcp --permanent   //开放端口
firewall-cmd --reload                     //重新载入,使其生效

3.关闭指定端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent   //关闭端口
firewall-cmd --reload               //重新载入,使其生效

4.查看端口状态
firewall-cmd --zone=public --query-port=80/tcp	  //查看端口状态
命令说明
ss -ant查看本机已经启用的监听端口
firewall-cmd --list-all查看防火墙所有信息
firewall-cmd --list-portscentos7查看防火墙开放的端口信息
netstat -lnp|grep 8000检查8000端口被哪个进程占用
ps 11100查看进程的详细信息
kill -9 11100强制杀掉编号为11100的进程
firewall-cmd --zone=public --remove-port=80/tcp --permanent关闭开放的80端口

其他常用命令
firewall-cmd --state -----------------查看防火墙状态,是否是running
firewall-cmd --reload -----------------重新载入配置,比如添加规则之后,需要执行此命令
firewall-cmd --get-zones -----------------列出支持的zone
firewall-cmd --get-services -----------------列出支持的服务,在列表中的服务是放行的
firewall-cmd --query-service ftp -----------------查看ftp服务是否支持,返回yes或者no
firewall-cmd --add-service=ftp -----------------临时开放ftp服务
firewall-cmd --add-service=ftp --permanent -----------------永久开放ftp服务
firewall-cmd --remove-service=ftp --permanent -----------------永久移除ftp服务
firewall-cmd --add-port=80/tcp --permanent -----------------永久添加80端口
iptables -L-n -----------------查看规则,这个命令是和iptables的相同的man
firewall-cmd -----------------查看帮助

CentOS 7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下
1、直接关闭防火墙
systemctl stop firewalld.service -----------------停止firewall systemctl
disable firewalld.service -----------------禁止firewall开机启动

2、设置 iptables service
yum -y install iptables-services -----------------如果要修改防火墙配置,如增加防火墙端口3306
3、增加规则
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT-------------------保存退出后
systemctl restart iptables.service -----------------重启防火墙使配置生效
systemctl enable iptables.service -----------------设置防火墙开机启动

4、最后重启系统使设置生效即可。
systemctl restart iptables.service -----------------重启防火墙使配置生效
systemctl enable iptables.service -----------------设置防火墙开机启动

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值