Linux CentOS 7默认的防火墙是firewalld,所以默认CentOS 7系统下并没有安装iptables,Linux百科网分享CentOS 7 iptables安装、iptables规则配置(放行或者禁用端口)教程方法:
检查firewalld并禁用
CentOS 7默认的防火墙是firewalld,想要安装iptables需要先禁用firewalld
一:查看firewalld状态
查看firewalld状态,命令:systemctl status firewalld
开启状态:显示绿色的“active (running)”,则代表开启;
关闭状态:显示“inactive (dead)”,代表关闭。
二:关闭firewalld
如果firewalld是开启状态,需要执行命令:systemctl stop firewalld
,关闭firewalld即可。
安装iptables
安装命令:iptables:yum install -y iptables-services
启动iptables
启动命令:systemctl start iptables
查看当前iptables状态
运行iptables启动命令后,可以查看下iptables是否启动成功,确保iptables启动成功
查看状态:systemctl status iptables
如果提示绿色的“active (exited)”,则iptables已经启动成功。
查看iptables默认规则
查看默认规则命令:iptables -L
安全起见,可以先备份下当前的iptables规则,然后再修改/添加规则
备份命令:cp -a /etc/sysconfig/iptables /etc/sysconfig/iptables.bak
添加或修改规则(放行或禁用端口)
Linux百科网以放行80号端口为例:
1 |
iptables -I INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT |
iptables -L
iptables-save > /etc/sysconfig/iptables
systemctl enable iptables.service
以上为CentOS 7系统下iptables安装、配置规则和启用的方法,赶紧重启服务器(命令:systemctl reboot
)去测试刚刚配置的iptables规则吧。
2021服务器优惠,阿里云PK腾讯云!免费提供技术支持: 咨询客服
服务器拼团:阿里云服务器特价57元(全网最低价)
①阿里云:阿里云服务器69元1年,203元3年(全网最低价)
②腾讯云:腾讯云服务器服务器秒杀88元一年起(有高配)
③代金券:阿里云代金券限量发放中(有账号就能领)
发表评论