CentOS   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了CentOS之——阿里云CentOS6.8启动iptables的sh文件,并设置常用端口大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/73823978 环境:阿里云CentOS6.8 运行命令: #新建文件 touch iptablesStart.sh #添加运行权限 chmod +x iptablesStart.sh #将附录内容复制到文件中,并启动 ./iptablesStart.sh 具体iptablesSta

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/73823978

环境:阿里云CentOS6.8
运行命令:

#新建文件
touch iptablesStart.sh
#添加运行权限
chmod +x iptablesStart.sh
#将附录内容复制到文件中,并启动
./iptablesStart.sh

具体iptablesStart.sh文件如下:

#!/bin/sh
yum install -y iptables
service iptables start

#首先在清除前要将policy INPUT改成ACCEPT,表示接受一切请求。
#这个一定要先做,不然清空后可能会悲剧
iptables -P INPUT ACCEPT
#清空认所有规则
iptables -F
#清空自定义的所有规则
iptables -X
#计数器置0
iptables -Z

service iptables save

#允许来自于lo接口的数据包
#如果没有此规则,你将不能通过127.0.0.1访问本地服务,例如ping 127.0.0.1
iptables -A INPUT -i lo -j ACCEPT
#ssh端口22
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#FTP端口21
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
#web服务端口80
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
#tomcat
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
#MysqL
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
#阿里云端口
iptables -A INPUT -p tcp --dport 8005 -j ACCEPT
iptables -A INPUT -p tcp --dport 8009 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT

#允许icmp包通过,也就是允许ping
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
#允许所有对外请求的返回包
#本机对外请求相当于OUTPUT,对于返回数据包必须接收啊,这相当于INPUT了
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
#如果要添加内网ip信任(接受其所有TCP请求)
iptables -A INPUT -p tcp -s 123.56.140.92 -j ACCEPT
#过滤所有非以上规则的请求
iptables -P INPUT DROP

service iptables save
service iptables restart
service iptables status

chkconfig iptables on

大佬总结

以上是大佬教程为你收集整理的CentOS之——阿里云CentOS6.8启动iptables的sh文件,并设置常用端口全部内容,希望文章能够帮你解决CentOS之——阿里云CentOS6.8启动iptables的sh文件,并设置常用端口所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。