iptables 配置
一、概述
1、redhat7/centos7系列默认防火墙使用firewalld,关闭之
systemctl stop firewalld.service
2、安装iptables
yum install -y iptables-services
3、systemctl start iptables.service
systemctl enable iptables.service
/etc/sysconfig/iptables #编辑防火墙配置文件
4、查看规则:
iptables -nL //注意,该输出的顺序很重要
对filter表(iptables默认表)的INPUT链配置:
//所有input都丢弃;然后开放22端口
iptables -A INPUT -j DROP ; iptables -A INPUT -p tcp --dport 22 -j ACCEPT
对filter表(iptables默认表)的FORWARD链配置:
iptables -A FORWARD -j DROP
对filter表(iptables默认表)的OUTPUT链配置:
iptables -A OUTPUT -j ACCEPT
放开lo:
iptables -A INPUT -p all -j ACCEPT
iptables -F #清空规则
iptables -X #清空自定义规则
5、note:
使用以上命令设置规则之后,systemctl restart iptables.service之后,规则完全丢失;
方法一: iptables-save > /etc/sysconfig/iptables
方法二: service iptables save
执行之后,重启之后依然可以生效;
#打开本地回环
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
#打开ping
iptabels -A INPUT -p icmp --icmp-type 8 -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type 0 -j ACCEPT
# Generated by iptables-save v1.4.21 on Fri Mar 3 12:10:36 2017 *filter :INPUT ACCEPT [0:0] :FORWARD DROP [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -i lo -j ACCEPT #允许本机ping其他host -I INPUT -p icmp -j ACCEPT -A INPUT -p tcp -m tcp --dport 2222 -j ACCEPT -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT #允许本机被ping -A INPUT -p icmp --icmp-type echo-request -j ACCEPT #允许dns #-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A OUTPUT -p udp --dport 53 -j ACCEPT -A INPUT -p udp --sport 53 -j ACCEPT -A INPUT -p udp --dport 53 -j ACCEPT -A OUTPUT -p udp --sport 53 -j ACCEPT #允许本机被ping -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT -A OUTPUT -p tcp -m tcp --sport 80 -j ACCEPT -A OUTPUT -p tcp -m tcp --sport 2222 -j ACCEPT -A INPUT -j DROP -A FORWARD -j DROP -A OUTPUT -j ACCEPT COMMIT # Completed on Fri Mar 3 12:10:36 2017
相关文章
- pycharm目录下的文件没有显示出来,可能是一下配置不对
- 关于TRIANGLE二维三角网格生成器在windows下的配置说明
- PLSQL 配置连接ORACLE数据库
- Spring Boot 2.5.0 重新设计的spring.sql.init 配置有啥用?
- Jmeter下载安装配置及使用(windows)
- 微信公众账号高级功能的开发模式配置
- Ubuntu18.04系统下网络文件系统nfs的安装及简单配置
- iOS云打包如何设置通用链接等Capabilities配置
- 思科模拟器 | 交换机与路由器的配置汇总【收藏备用】
- 深入理解Spring源码之剖析AOP(注解配置方式)
- IDEA 中配置 Gradle 和使用
- 使用 ZooKeeper 同步集群配置
- 静态路由的拓展配置
- Flume NG 配置详解(转)
- 配置activeMQ