我可以运行iptables-save并将输出转储到stdout但是如果我重定向到文件 – 该文件为空:
- [root@nhd-vlx2 tmp]# iptables-save
- # Generated by iptables-save v1.4.7 on Sun Dec 18 15:11:42 2011
- *filter
- :INPUT ACCEPT [0:0]
- :FORWARD ACCEPT [0:0]
- :OUTPUT ACCEPT [90971:17757587]
- -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
- -A INPUT -p icmp -j ACCEPT
- -A INPUT -i lo -j ACCEPT
- -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
- -A INPUT -p tcp -m state --state NEW -m tcp --dport 9090:9999 -j ACCEPT
- -A INPUT -j REJECT --reject-with icmp-host-prohibited
- -A FORWARD -j REJECT --reject-with icmp-host-prohibited
- COMMIT
- # Completed on Sun Dec 18 15:11:42 2011
- [root@nhd-vlx2 tmp]# iptables-save > save
- [root@nhd-vlx2 tmp]# cat save
- [root@nhd-vlx2 tmp]#
- [root@nhd-vlx2 tmp]#
管道工程(iptables-save | cat),以及通过tee保存到文件也有效,但为什么iptables-save不允许保存到文件?
我能想到的唯一原因是这台机器可能被病毒感染(试图削弱防火墙)
解决方法
远射,但是:
其他人在另一个论坛上发布了类似的问题.事实证明,SELinux上下文是错误的.
在iptables-multi上运行ls -laZ.它应该返回:
- -rwxr-xr-x. root root system_u:object_r:iptables_exec_t:s0 /sbin/iptables-multi
- [root@cacti tmp]# ls -laZ /sbin/iptables*
- lrwxrwxrwx. root root system_u:object_r:bin_t:s0 /sbin/iptables -> iptables-multi
- -rwxr-xr-x. root root system_u:object_r:iptables_exec_t:s0 /sbin/iptables-multi
- lrwxrwxrwx. root root system_u:object_r:bin_t:s0 /sbin/iptables-restore -> iptables-multi
- lrwxrwxrwx. root root system_u:object_r:bin_t:s0 /sbin/iptables-save -> iptables-multi
如果SELinux上下文不正确,请使用主文件上的chcon命令进行更改:
- chcon -u system_u -t iptables_exec_t /sbin/iptables-multi
如果符号链接上的SELinux上下文不正确,请使用上面的命令修复它们(尽管这次使用bin_t类型)