centos防火墙基本操作


#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
然后保存:
#/etc/rc.d/init.d/iptables save

查看打开的端口:
# /etc/init.d/iptables status

关闭端口
iptables -I INPUT -i eth0 -p tcp --dport 81 -j DROP

配置filter表防火墙


#清除预设表filter中的所有规则链的规则
iptables -F

#清除预设表filter中使用者自定链中的规则
iptables -X

#保存iptables配置
service iptables save

#重启iptables服务
service iptables restart

#查看iptables规则
iptables -L -n

#查看iptables规则文件
cat /etc/sysconfig/iptables

#设定预设规则
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

#开启22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#如果OUTPUT设置成DROP需要添加 iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
#关闭22端口 iptables -D INPUT -p tcp --dport 22 -j ACCEPT

#开启常用端口
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
#iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT
#iptables -A OUTPUT -p tcp --sport 3306 -j ACCEPT
#iptables -A INPUT -p tcp --dport 20 -j ACCEPT
#iptables -A INPUT -p tcp --dport 21 -j ACCEPT
#iptables -A INPUT -p tcp --dport 10000 -j ACCEPT
#iptables -A INPUT -p tcp --dport 25 -j ACCEPT
#iptables -A INPUT -p tcp --dport 110 -j ACCEPT
#iptables -A INPUT -p udp --dport 53 -j ACCEPT

#允许ping
iptables -A INPUT -p icmp -j ACCEPT
#如果OUTPUT设置成DROP需要添加 iptables -A OUTPUT -p icmp -j ACCEPT

#允许loopback
iptables -A INPUT -i lo -p all -j ACCEPT
#如果OUTPUT设置成DROP需要添加 iptables -A OUTPUT -o lo -p all -j ACCEPT

#屏蔽指定ip
#iptables -A INPUT -p tcp -s 192.168.10.1 -j DROP

#减少不安全的端口连接
#iptables -A OUTPUT -p tcp --sport 31337 -j DROP
#iptables -A OUTPUT -p tcp --dport 31337 -j DROP

#允许某个IP远程连接
#iptables -A INPUT -s 192.168.10.1 -p tcp --dport 22 -j ACCEPT
#允许某个网段的IP远程连接
iptables -A INPUT -s 192.168.10.0/24 -p tcp --dport 22 -j ACCEPT

#允许指定网段通过、指定网口通过SSH连接本机
#iptables -A INPUT -i eth0 -p tcp -s 192.168.10.0/24 --dport 22 -m state --state NEW,ESTABLESHED -j ACCEPT
#iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
#iptables -A INPUT -i eth0 -p tcp -s 192.168.10.0/24 --dport 22 -m state --state ESTABLESHED -j ACCEPT
#iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state NEW,ESTABLISHED -j ACCEPT

#开启转发功能
#iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
#iptables -A FORWARD -i eth1 -o eh0 -j ACCEPT

#丢弃坏的TCP包
#iptables -A FORWARD -p TCP ! --syn -m state --state NEW -j DROP

#处理IP碎片数量,防止攻击,允许每秒100个
#iptables -A FORWARD -f -m limit --limit 100/s --limit-burst 100 -j ACCEPT

#设置ICMP包过滤,允许每秒1个包,限制触发条件是10个包
#iptables -A FORWARD -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT

#丢弃非法连接
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -m state --state INVALID -j DROP
iptables -A FORWARD -m state --state INVALID -j DROP

#允许所有已经建立的和相关的连接
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

配置NAT表防火墙


#查看NAT表规则
iptables -t nat -L

#清除NAT规则
iptables -F -t nat
iptables -X -t nat
iptables -Z -t nat

#防止外网用内网IP欺骗
#iptables -t nat -A PREROUTING -i eth0 -s 10.0.0.0/8 -j DROP
#iptables -t nat -A PREROUTING -i eth0 -s 172.16.0.0/12 -j DROP
#iptables -t nat -A PREROUTING -i eth0 -s 192.168.0.0/16 -j DROP

#禁止与某个IP的所有连接
#iptables -t nat -A PREROUTING -d 192.168.10.1 -j DROP

#禁用80端口
#iptables -t nat -A PREROUTING -p tcp --dport 80 -j DROP

#禁用某个IP的80端口
#iptables -t nat -A PREROUTING -p tcp --dport 21 -d 192.168.10.1 -j DROP

保存iptables文件,重启服务


#保存iptables规则
service iptables save

#重启iptables服务
service iptables restart

#关闭防火墙
/etc/init.d/iptables stop
service iptables stop # 停止服务

#查看防火墙信息
/etc/init.d/iptables status

#开放端口:8080
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
#重启防火墙以便改动生效:(或者直接重启系统)

/etc/init.d/iptables restart

#将更改进行保存
/etc/rc.d/init.d/iptables save

另外直接在/etc/sysconfig/iptables中增加一行:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT

centos防火墙操作的更多相关文章

  1. CentOS防火墙操作实例(启动、停止、开、闭端口)

    注:防火墙的基本操作命令: 查询防火墙状态: [root@localhost ~]# service   iptables status<回车>   停止防火墙: [root@localh ...

  2. CentOS 配置防火墙操作实例(启、停、开、闭端口):

    CentOS 配置防火墙操作实例(启.停.开.闭端口): 注:防火墙的基本操作命令: 查询防火墙状态: [root@localhost ~]# service   iptables status< ...

  3. CentOS 配置防火墙操作实例(启、停、开、闭端口)CentOS Linux-FTP/对外开放端口(接口)TomCat相关

    链接地址:http://blog.csdn.net/jemlee2002/article/details/7042991 CentOS 配置防火墙操作实例(启.停.开.闭端口): 注:防火墙的基本操作 ...

  4. CentOS配置防火墙操作实例

    CentOS 配置防火墙操作实例(启.停.开.闭端口): 注:防火墙的基本操作命令: 查询防火墙状态: [root@localhost ~]# service iptables status<回 ...

  5. CentOS 配置防火墙操作实例(启、停、开、闭port)

    CentOS 配置防火墙操作实例(启.停.开.闭port): 注:防火墙的基本操作命令: 查询防火墙状态: [root@localhost ~]# service   iptables status& ...

  6. Linux安全调优1:CentOS防火墙的设置与优化

    CentOS防火墙的设置与优化 时间:2014-09-11 02:11来源:blog.csdn.net 作者:成长的小虫 的BLOG 举报 点击:4908次 一.设置主机防火墙. 开放: 服务器的:w ...

  7. 解决宿主机不能访问虚拟机CentOS中的站点 | 更新CentOS防火墙设置开启80端口访问

    前阵子在虚拟机上装好了centos6.0,并配好了nginx+php+mysql,但是本机就是无法访问.一直就没去折腾了. 具体情况如下 1.本机能ping通虚拟机 2.虚拟机也能ping通本机 3. ...

  8. CentOS防火墙iptables的配置方法详解

    CentOS系统也是基于linux中的它的防火墙其实就是iptables了,下面我来介绍在CentOS防火墙iptables的配置教程,希望此教程对各位朋友会有所帮助. iptables是与Linux ...

  9. Centos防火墙禁止ping和开启ping

    1.允许PING设置 iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT iptables -A OUTPUT -p icmp - ...

随机推荐

  1. http 常用状态码及含义

    http://www.kuaipan.cn/developers/document_status.htm

  2. Cocoapod错误 - Xcode6.4

    当我从Xcode 6.3切换到Xcode6.4的时候,因为我是mac上安装了两个不同的版本,现在把Xcode 6.3卸掉了. 现在再次运行pod install命令的时候,提示如下错误:   Upda ...

  3. htm、html、shtml区别

    htm.html.shtml都是静态网页的后缀,三者也可以说都是只是扩展名不同,其他一样,都是静态的网页. htm和html是完全静态的网页不通过服务器编译解释直接送出给浏览器读取的静态网页,以htm ...

  4. 一个奇怪的编码 big5-hkscs

    # --*-- coding:utf-8 --*-- import urllib2 import urllib postDict = { 'IsExist_Slt_Part_Id': 'False', ...

  5. TFS环境搭建

    这篇文章主要介绍了微软源代码管理工具TFS2013安装与使用图文教程,本文详细的给出了TFS2013的安装配置过程.使用教程,需要的朋友可以参考下 最近公司新开发一个项目要用微软的TFS2013进行项 ...

  6. 【网络流24题】No.11(航空路线问题 最长不相交路径 最大费用流)

    [题意] 给定一张航空图, 图中顶点代表城市, 边代表 2 城市间的直通航线. 现要求找出一条满足下述限制条件的且途经城市最多的旅行路线.(1) 从最西端城市出发,单向从西向东途经若干城市到达最东端城 ...

  7. 【UVA 1411】 Ants (KM)

    Young naturalist Bill studies ants in school. His ants feed onplant-louses that live on apple trees. ...

  8. 猜测:信号槽的本质是使用Windows的自定义消息来实现的

    在不断执行: void MyTool::DeleteAllFiles(){ for (i = 0; i <= n - 1; i++) { // do something }}在for循环没有执行 ...

  9. iOS -view横向变成竖向

    -------

  10. bzoj1232

    由题意知,最后要保留的边肯定都要被走过 来回一条边所花费的时间=2*边长+安慰边两端的牛所要花的时间和 总时间就等于所保留边来回的时间和+根节点时间: 不难想到做一下最小生成树即可 贪心可知,根一定选 ...