1.策略与规则链

iptables 服务把用于处理或过滤流量的策略条目称之为规则,多条规则可以组成一个规则链,而规则链则依据数据包处理位置的不同进行分类,具体如下:

在进行路由选择前处理数据包(PREROUTING);
    处理流入的数据包(INPUT);
    处理流出的数据包(OUTPUT);
    处理转发的数据包(FORWARD);
    在进行路由选择后处理数据包(POSTROUTING)。

一般来说,从内网向外网发送的流量一般都是可控且良性的,因此我们使用最多的就是INPUT 规则链,该规则链可以增大黑客人员从外网入侵内网的难度。

处理匹配流量的动作:

ACCEPT(允许流量通过)、REJECT(拒绝流量通过)、LOG(记录日志信息)、DROP(拒绝流量通过)。

DROP:直接将流量丢弃而且不响应;

REJECT :在拒绝流量后再回复一条“您的信息已经收到,但是被扔掉了”信息,从而让流量发送方清晰地看到数据被拒绝的响应信息。

当把 Linux 系统中的防火墙策略修改成DROP 拒绝动作后,流量发送方会看到响应超时的提醒。但是流量发送方无法判断流量是被拒绝,还是接收方主机当前不在线:

当把 Linux 系统中的防火墙策略设置为REJECT 拒绝动作后,流量发送方会看到端口不可达的响应;

举例: reject

[root@localhost ~]# ping -c 4 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
From 192.168.10.10 icmp_seq=1 Destination Port Unreachable
From 192.168.10.10 icmp_seq=2 Destination Port Unreachable
From 192.168.10.10 icmp_seq=3 Destination Port Unreachable
From 192.168.10.10 icmp_seq=4 Destination Port Unreachable
--- 192.168.10.10 ping statistics ---
4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 3002ms

drop

[root@localhost ~]# ping -c 4 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
--- 192.168.10.10 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3000ms

2.iptables中的基本命令参数

1)把INPUT规则链的默认规则设置为拒绝:

[root@localhost ~]# iptables -P INPUT  DROP

此时ssh远程连接会断开。

2)向INPUT规则链中添加允许ICMP 和SSH流量进入的策略规则:

root@localhost ~]# iptables -I INPUT -p icmp -j ACCEPT

此时从远程设备ping 通测试机

3)向INPUT规则链中添加允许10.10.65.65远程SSH登录的策略规则:

[root@localhost ~]# iptables -I INPUT -s 10.10.65.65/32 -p tcp --dport 22 -j ACCEPT

4)查看规则链

[root@localhost ~]# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- 10.10.65.65 anywhere tcp dpt:ssh
ACCEPT icmp -- anywhere anywhere Chain FORWARD (policy ACCEPT)
target prot opt source destination Chain OUTPUT (policy ACCEPT)
target prot opt source destination

5)清除所有的防火墙规则链,默认规则除外

[root@localhost ~]# iptables -F
[root@localhost ~]# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination Chain FORWARD (policy ACCEPT)
target prot opt source destination Chain OUTPUT (policy ACCEPT)
target prot opt source destination

此时ssh远程连接会断开。

6)向INPUT 规则链中添加拒绝所有人访问本机12345 端口的策略规则:

[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
REJECT udp -- anywhere anywhere udp dpt:italk reject-with icmp-port-unreachable
REJECT tcp -- anywhere anywhere tcp dpt:italk reject-with icmp-port-unreachable

7)向INPUT 规则链中添加拒绝所有主机访问本机1000~1024 端口的策略规则:

[root@localhost ~]# iptables -A INPUT -p tcp --dport 1000:1024 -j REJECT
[root@localhost ~]# iptables -A INPUT -p udp --dport 1000:1024 -j REJECT

注:使用iptables 命令配置的防火墙规则默认会在系统下一次重启时失效,如果想让配置的防火墙策略永久生效,还要执行保存命令:

[root@localhost ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables: [ OK ]

3.centos 7 中没有iptables 和service iptables save 指令使用失败问题解决方案

如果执行service iptables save 命令来保存iptables时失败,报出:

The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

解决方法:

systemctl stop firewalld 关闭防火墙

yum install iptables-services 安装或更新服务

再使用systemctl enable iptables 启动iptables

最后 systemctl start iptables 打开iptables

再执行service iptables save

重启iptables服务:

service iptables restart

执行完毕之后/etc/syscofig/iptables文件就有了

21.iptables的更多相关文章

  1. CentOS系统配置 iptables防火墙

    阿里云CentOS系统配置iptables防火墙   虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT.OUTPUT和FO ...

  2. 阿里云Centos配置iptables防火墙

    虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT.OUTPUT和FORWORD都是ACCEPT的规则 一.检查iptabl ...

  3. CentOS6.4 配置iptables

    如果没有安装iptables可以直接用yum安装 yum install -t iptables 检查iptables服务的状态, service iptables status 如果出现“iptab ...

  4. 阿里云 centos 修改iptables

    一.检查iptables服务状态 首先检查iptables服务的状态 [root@woxplife ~]# service iptables status iptables: Firewall is ...

  5. 阿里云CentOS配置iptables防火墙[转]

    虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT.OUTPUT和FORWORD都是ACCEPT的规则 一.检查iptabl ...

  6. 【安装防火墙】没有iptables时的解决办法

    一.检查iptables服务状态 首先检查iptables服务的状态 [root@woxplife ~]# service iptables status iptables: Firewall is ...

  7. 〖Linux〗iptables使用实例

    1. 使局域网用户可共享外网(拨号上网) > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -o ppp0 -j MA ...

  8. centos配置iptables

    第一次配置前消除默认的规则 #这个一定要先做,不然清空后可能会悲剧 iptables -P INPUT ACCEPT #清空默认所有规则 iptables -F #清空自定义的所有规则 iptable ...

  9. iptables最常用的规则示例

    iptables v1.4.21 iptables基础 规则(rules)其实就是网络管理员预定义的条件,规则一般的定义为“如果数据包头符合这样的条件,就这样处理这个数据包”.规则存储在内核空间的信息 ...

随机推荐

  1. linux resolver

    linux resolver 概要 解析域名,由libresolv提供,用法参见man 3 resolver 配置文件,resolv.conf(参看 man 5 resolv.conf)配置dns s ...

  2. springboot源码解析-管中窥豹系列之项目类型(二)

    一.前言 Springboot源码解析是一件大工程,逐行逐句的去研究代码,会很枯燥,也不容易坚持下去. 我们不追求大而全,而是试着每次去研究一个小知识点,最终聚沙成塔,这就是我们的springboot ...

  3. RewriteCond 和RewriteRule规则说明 (转)

    Apache的Mod_rewrite学习 (RewriteCond重写规则的条件)收藏RewriteCond Syntax: RewriteCond TestString CondPattern [f ...

  4. 第12章 DOM操作

    目录 *1. 向DOM中注入HTML 1.1 将HTNL字符串转换成DOM 预处理HTML源字符串 包装HTML 1.2 将DOM元素插入到文档中 2. DOM的特性和属性 通过DOM方法和属性访问特 ...

  5. WPF 调试时拖拽不生效

    WPF窗体代码 <Window x:Class="SerialLabelDemo.Test.Window10" xmlns="http://schemas.micr ...

  6. 详解Vue中的computed和watch

    作者:小土豆 博客园:https://www.cnblogs.com/HouJiao/ 掘金:https://juejin.cn/user/2436173500265335 1. 前言 作为一名Vue ...

  7. 肌肤管家SkinRun V3S智能皮肤检测仪,用AI探索肌肤问题

    继肌肤管家SkinRun V3皮肤检测仪之后,肌肤管家SkinRun近期又一重磅推出的肌肤管家SkinRun V3S 智能肌肤测试仪引起了美业人的广泛关注.据了解它汇集百万皮肤数据,利用五光谱原理和人 ...

  8. 天梯赛练习 L3-006 迎风一刀斩 (30分) 几何关系

    题目分析: 对于给出的两个多边形是否可以组成一个矩形,这里我们分以下几种情况讨论 1.首先对于给出的两个多边形只有3-3,3-4,3-5,4-4才有可能组成一个矩形,并且两个多边形只可能是旋转90,1 ...

  9. 解压rpm文件

    rpm2cpio zabbix-2.2.2-0.el6.zbx.src.rpm |cpio -div

  10. Netty学习:伪共享

    目录 Netty中的伪共享 伪共享的原理以及介绍 Netty中的伪共享 先说为什么知道这个概念吧,期初看Netty源码的时候,看到了NioEventLoop的构建,其中有这么一句代码: private ...