CentOS配置iptables规则并使其永久生效

© 版权声明:本文为博主原创文章,转载请注明出处

 1. 目的

  最近为了使用redis,配置远程连接的使用需要使用iptable是设置允许外部访问6379端口,但是设置完成后重启总是失效。因此百度了一下如何设置永久生效,并记录。

 2. 设置

  2.1 添加iptables规则

iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT

  2.2 保存

service iptables save

  执行这个命令的时候有时候可能会报错:The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

  这是因为没有安装iptables服务,直接使用yum安装iptables服务即可.

yum install iptables-services

  安装完成后,重新执行 service iptables save 命令即可保存成功。

  2.3 配置iptables开机自启

  保存后重启依然没有生效,后百度得知,需要设置iptables开机自启才可使配置生效。

  执行如下命令(老版本命令为:service iptables on),设置iptables开机自启

systemctl enable iptables.service

 3. 注意

  需关闭firewalld防火墙

  systemctl stop firewalld.service

  systemctl disable firewalld.service

参考:

http://blog.csdn.net/donglynn/article/details/73530542

https://www.v2ex.com/t/114397

  

posted @ 2018-03-19 11:19  禁忌夜色153  阅读(24457)  评论(0编辑  收藏  举报