iptables:应用防火墙规则:ptables-restore: 【失败

https://blog.csdn.net/ypf1527542612/article/details/78908199

开启端口的方法:

        方法一:命令行方式

               1.开放端口命令: /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

                     8080 端口,根据你自己的需要进行修改 

              2.保存:/etc/rc.d/init.d/iptables save


           3.重启服务:/etc/init.d/iptables restart


           4.查看端口是否开放:/sbin/iptables -L -n

  

      方法二:直接编辑/etc/sysconfig/iptables文件


               1.编辑/etc/sysconfig/iptables文件:vi /etc/sysconfig/iptables
                   加入内容并保存:-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT


               2.重启服务:/etc/init.d/iptables restart


               3.查看端口是否开放:/sbin/iptables -L -n

          

介绍几个查看进程命令

 lsof命令用于查看你进程开打的文件,打开文件的进程,进程打开的端口(TCP、UDP)。找回/恢复删除的文件

       -a:列出打开文件存在的进程;
      -c<进程名>:列出指定进程所打开的文件;
      -g:列出GID号进程详情;
      -d<文件号>:列出占用该文件号的进程;
      +d<目录>:列出目录下被打开的文件;
     +D<目录>:递归列出目录下被打开的文件;
     -n<目录>:列出使用NFS的文件;
     -i<条件>:列出符合条件的进程。(4、6、协议、:端口、 @ip )
     -p<进程号>:列出指定进程号所打开的文件;
     -u:列出UID号进程详情;
     -h:显示帮助信息;
     -v:显示版本信息。

netstat -tulp|grep 6379

或者

netstat -tulp|grep redis

或者

ps -ef|grep redis

iptables:应用防火墙规则:ptables-restore: 【失败】

 

[root@localhost ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:iptables-restore v1.4.7: Couldn't load match `-udp':/lib64/xtables/libipt_-udp.so: cannot open shared object file: No such file or directory

Error occurred at line: 14
Try `iptables-restore -h' or 'iptables-restore --help' for more information.               [失败]

解决办法:
[root@localhost~]#iptables -N RH-Firewall-1-INPUT

[root@localhost~]# service iptables save

编辑/etc/sysconfig/iptables
[root@localhost~]#vim /etc/sysconfig/iptables
添加   -ARH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3690 -j ACCEPT
再重新启动3690端口
[root@localhost~]# service iptables restart
 
启动后显示正常
iptables:将链设置为政策ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                        [确定]
iptables:正在卸载模块:                                            [确定]

iptables:应用防火墙规则:                                        [确定]

 

 

修改iptables后重启返回错误

在防火墙添加规则后我是这样改的vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

重启:/etc/init.d/iptables restart

返回值:Error occurred at line: 16
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
[FAILED]

找到解决方法:

/sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT

/etc/rc.d/init.d/iptables save

/etc/init.d/iptables restart

重启成功:iptables: Setting chains to policy ACCEPT: filter [  OK  ]
iptables: Flushing firewall rules: [  OK  ]
iptables: Unloading modules: [  OK  ]
iptables: Applying firewall rules: [  OK  ]

 #屏蔽单个IP的命令是
iptables -I INPUT -s 123.45.6.7 -j DROP
#封整个段即从123.0.0.1到123.255.255.254的命令
iptables -I INPUT -s 123.0.0.0/8 -j DROP
#封IP段即从123.45.0.1到123.45.255.254的命令
iptables -I INPUT -s 124.45.0.0/16 -j DROP
#封IP段即从123.45.6.1到123.45.6.254的命令是
iptables -I INPUT -s 123.45.6.0/24 -j DROP

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值