neutron是如何通过iptables管理网络的

2024-06-06 02:08

本文主要是介绍neutron是如何通过iptables管理网络的,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在访问与安全的菜单下,新建一个安全组test。点击进入test,可以看到两个默认的出口,这个是系统自动定义好的,表示无论从哪个端口哪个ip都能出去。


然后添加两个新的规则

第一个规则表示,只能从默认安全组可以ping通该组的虚拟机;
第二个规则表示,只能从默认安全组跳进该组的虚拟机。

启动云主机创建新的虚拟机,选择oa环境和刚刚创建的安全组。
然后进入该虚拟机,查看虚拟机创在哪个物理机的节点上。我这里发现时在4号机的节点上,再次之间4号机上是没有任何虚拟机的。
查看iptables也看不到与虚拟机有关的规则。
Sugon04:~ # iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
neutron-linuxbri-INPUT  all  --  anywhere             anywhere            Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
neutron-filter-top  all  --  anywhere             anywhere            
neutron-linuxbri-FORWARD  all  --  anywhere             anywhere            Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
neutron-filter-top  all  --  anywhere             anywhere            
neutron-linuxbri-OUTPUT  all  --  anywhere             anywhere            Chain neutron-filter-top (2 references)
target     prot opt source               destination         
neutron-linuxbri-local  all  --  anywhere             anywhere            Chain neutron-linuxbri-FORWARD (1 references)
target     prot opt source               destination         Chain neutron-linuxbri-INPUT (1 references)
target     prot opt source               destination         Chain neutron-linuxbri-OUTPUT (1 references)
target     prot opt source               destination         Chain neutron-linuxbri-local (1 references)
target     prot opt source               destination         Chain neutron-linuxbri-sg-chain (0 references)
target     prot opt source               destination         Chain neutron-linuxbri-sg-fallback (0 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere             /* Default drop rule for unmatched traffic. */
Sugon04:~ # 

创建新的虚拟机之后规则就出来了
Sugon04:~ # iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
neutron-linuxbri-INPUT  all  --  anywhere             anywhere            Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
neutron-filter-top  all  --  anywhere             anywhere            
neutron-linuxbri-FORWARD  all  --  anywhere             anywhere            Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
neutron-filter-top  all  --  anywhere             anywhere            
neutron-linuxbri-OUTPUT  all  --  anywhere             anywhere            Chain neutron-filter-top (2 references)
target     prot opt source               destination         
neutron-linuxbri-local  all  --  anywhere             anywhere            Chain neutron-linuxbri-FORWARD (1 references)
target     prot opt source               destination         
neutron-linuxbri-sg-chain  all  --  anywhere             anywhere             PHYSDEV match --physdev-out tape68040f5-c3 --physdev-is-bridged /* Direct traffic from the VM interface to the security group chain. */
neutron-linuxbri-sg-chain  all  --  anywhere             anywhere             PHYSDEV match --physdev-in tape68040f5-c3 --physdev-is-bridged /* Direct traffic from the VM interface to the security group chain. */Chain neutron-linuxbri-INPUT (1 references)
target     prot opt source               destination         
neutron-linuxbri-oe68040f5-c  all  --  anywhere             anywhere             PHYSDEV match --physdev-in tape68040f5-c3 --physdev-is-bridged /* Direct incoming traffic from VM to the security group chain. */Chain neutron-linuxbri-OUTPUT (1 references)
target     prot opt source               destination         Chain neutron-linuxbri-ie68040f5-c (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere             state RELATED,ESTABLISHED /* Direct packets associated with a known session to the RETURN chain. */
RETURN     udp  --  172.16.15.23         anywhere             udp spt:bootps dpt:bootpc
RETURN     tcp  --  anywhere             anywhere             tcp dpt:ssh match-set NIPv43e07d4ff-0fdd-4fe0-988f- src
RETURN     icmp --  anywhere             anywhere             match-set NIPv43e07d4ff-0fdd-4fe0-988f- src
DROP       all  --  anywhere             anywhere             state INVALID /* Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack. */
neutron-linuxbri-sg-fallback  all  --  anywhere             anywhere             /* Send unmatched traffic to the fallback chain. */Chain neutron-linuxbri-local (1 references)
target     prot opt source               destination         Chain neutron-linuxbri-oe68040f5-c (2 references)
target     prot opt source               destination         
RETURN     udp  --  anywhere             anywhere             udp spt:bootpc dpt:bootps /* Allow DHCP client traffic. */
neutron-linuxbri-se68040f5-c  all  --  anywhere             anywhere            
DROP       udp  --  anywhere             anywhere             udp spt:bootps dpt:bootpc /* Prevent DHCP Spoofing by VM. */
RETURN     all  --  anywhere             anywhere             state RELATED,ESTABLISHED /* Direct packets associated with a known session to the RETURN chain. */
RETURN     all  --  anywhere             anywhere            
DROP       all  --  anywhere             anywhere             state INVALID /* Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack. */
neutron-linuxbri-sg-fallback  all  --  anywhere             anywhere             /* Send unmatched traffic to the fallback chain. */Chain neutron-linuxbri-se68040f5-c (1 references)
target     prot opt source               destination         
RETURN     all  --  172.16.15.31         anywhere             MAC FA:16:3E:05:B8:03 /* Allow traffic from defined IP/MAC pairs. */
DROP       all  --  anywhere             anywhere             /* Drop traffic without an IP/MAC allow rule. */Chain neutron-linuxbri-sg-chain (2 references)
target     prot opt source               destination         
neutron-linuxbri-ie68040f5-c  all  --  anywhere             anywhere             PHYSDEV match --physdev-out tape68040f5-c3 --physdev-is-bridged /* Jump to the VM specific chain. */
neutron-linuxbri-oe68040f5-c  all  --  anywhere             anywhere             PHYSDEV match --physdev-in tape68040f5-c3 --physdev-is-bridged /* Jump to the VM specific chain. */
ACCEPT     all  --  anywhere             anywhere            Chain neutron-linuxbri-sg-fallback (2 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere             /* Default drop rule for unmatched traffic. */
Sugon04:~ # 

这个时候发现多了很多规则,那么这些规则和安全组的规则又是如何对应的呢?
先说INPUT链
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
neutron-linuxbri-INPUT  all  --  anywhere             anywhere  
该链又指向下面这个
Chain neutron-linuxbri-INPUT (1 references)
target     prot opt source               destination         
neutron-linuxbri-oe68040f5-c  all  --  anywhere             anywhere             PHYSDEV match --physdev-in tape68040f5-c3 --physdev-is-bridged /* Direct incoming traffic from VM to the security group chain. */
然后接着往下指
Chain neutron-linuxbri-oe68040f5-c (2 references)
target     prot opt source               destination         
RETURN     udp  --  anywhere             anywhere             udp spt:bootpc dpt:bootps /* Allow DHCP client traffic. */
neutron-linuxbri-se68040f5-c  all  --  anywhere             anywhere            
DROP       udp  --  anywhere             anywhere             udp spt:bootps dpt:bootpc /* Prevent DHCP Spoofing by VM. */
RETURN     all  --  anywhere             anywhere             state RELATED,ESTABLISHED /* Direct packets associated with a known session to the RETURN chain. */
RETURN     all  --  anywhere             anywhere            
DROP       all  --  anywhere             anywhere             state INVALID /* Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack. */
neutron-linuxbri-sg-fallback  all  --  anywhere             anywhere             /* Send unmatched traffic to the fallback chain. */
可以看到,到了这一步已经有了实际的规则,前两个规则和DHCP有关,不需理会。紧接着两个规则表示建立有效连接就返回包,无效连接就丢弃。这里的anywhere表示规则对所有的ip地址有效。
最后一条又指向一条链
Chain neutron-linuxbri-sg-fallback (2 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere             /* Default drop rule for unmatched traffic. */
这条链表示凡是不匹配规则的都包都扔了,其实这也说明该iptables主要是通得策略,只让符合要求的通过。(相对有堵得策略,符合要求的就堵住不让过)

接着说FORWARD链
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
neutron-filter-top  all  --  anywhere             anywhere            
neutron-linuxbri-FORWARD  all  --  anywhere             anywhere   
第一个分支
Chain neutron-filter-top (2 references)
target     prot opt source               destination         
neutron-linuxbri-local  all  --  anywhere             anywhere  
再指向他,而且没有任何动作
Chain neutron-linuxbri-local (1 references)
target     prot opt source               destination   
第二个分支
Chain neutron-linuxbri-FORWARD (1 references)
target     prot opt source               destination         
neutron-linuxbri-sg-chain  all  --  anywhere             anywhere             PHYSDEV match --physdev-out tape68040f5-c3 --physdev-is-bridged /* Direct traffic from the VM interface to the security group chain. */
neutron-linuxbri-sg-chain  all  --  anywhere             anywhere             PHYSDEV match --physdev-in tape68040f5-c3 --physdev-is-bridged /* Direct traffic from the VM interface to the security group chain. */
这里表示通过
neutron-linuxbri-sg-chain
转发物理设备的进出包
Chain neutron-linuxbri-sg-chain (2 references)
target     prot opt source               destination         
neutron-linuxbri-ie68040f5-c  all  --  anywhere             anywhere             PHYSDEV match --physdev-out tape68040f5-c3 --physdev-is-bridged /* Jump to the VM specific chain. */
neutron-linuxbri-oe68040f5-c  all  --  anywhere             anywhere             PHYSDEV match --physdev-in tape68040f5-c3 --physdev-is-bridged /* Jump to the VM specific chain. */
ACCEPT     all  --  anywhere             anywhere            
再看这两个链

neutron-linuxbri-ie68040f5-c
Chain neutron-linuxbri-ie68040f5-c (1 references)
<span style="color:#FF0000;">target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere             state RELATED,ESTABLISHED /* Direct packets associated with a known session to the RETURN chain. */
RETURN     udp  --  172.16.15.23         anywhere             udp spt:bootps dpt:bootpc
RETURN     tcp  --  anywhere             anywhere             tcp dpt:ssh match-set NIPv43e07d4ff-0fdd-4fe0-988f- src
RETURN     icmp --  anywhere             anywhere             match-set NIPv43e07d4ff-0fdd-4fe0-988f- src
DROP       all  --  anywhere             anywhere             state INVALID /* Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack. */
neutron-linuxbri-sg-fallback  all  --  anywhere             anywhere             /* Send unmatched traffic to the fallback chain. */</span>
Chain neutron-linuxbri-sg-fallback (2 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere             /* Default drop rule for unmatched traffic. */


neutron-linuxbri-oe68040f5-c
Chain neutron-linuxbri-oe68040f5-c (2 references)
target     prot opt source               destination         
<span style="color:#FF0000;">RETURN     udp  --  anywhere             anywhere             udp spt:bootpc dpt:bootps /* Allow DHCP client traffic. */
neutron-linuxbri-se68040f5-c  all  --  anywhere             anywhere            
DROP       udp  --  anywhere             anywhere             udp spt:bootps dpt:bootpc /* Prevent DHCP Spoofing by VM. */
RETURN     all  --  anywhere             anywhere             state RELATED,ESTABLISHED /* Direct packets associated with a known session to the RETURN chain. */
RETURN     all  --  anywhere             anywhere            
DROP       all  --  anywhere             anywhere             state INVALID /* Drop packets that appear related to an existing connection (e.g. TCP ACK/FIN) but do not have an entry in conntrack. */
neutron-linuxbri-sg-fallback  all  --  anywhere             anywhere             /* Send unmatched traffic to the fallback chain. */</span>
Chain neutron-linuxbri-sg-fallback (2 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere             /* Default drop rule for unmatched traffic. */

最后说output链:
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
neutron-filter-top  all  --  anywhere             anywhere            
neutron-linuxbri-OUTPUT  all  --  anywhere             anywhere   
1.1先走
neutron-filter-top
Chain neutron-filter-top (2 references)
target     prot opt source               destination         
neutron-linuxbri-local  all  --  anywhere             anywhere 

1.2再到
Chain neutron-linuxbri-local (1 references)
target     prot opt source               destination  
这条链下来没有任何动作

2.1再走
neutron-linuxbri-OUTPUT
Chain neutron-linuxbri-OUTPUT (1 references)
target     prot opt source               destination  



这里只是厘清链的动作,还需要进一步补充,如果没有动作就使用默认动作,一般是accept。

补充:
这里操作iptables的地方是04节点,而虚拟机正是结立在该节点上。前期我们过多的将注意力放在INPUT和Output上,但是我们研究的却是针对虚拟机的规则。由此就造成了概念上走不通。现在换个思路。04节点作为虚拟机的中转站,那么所有的虚拟机获得的包都是从04上转发过来的。这样一来,当我们看04节点的iptables规则时,就无需关注INPUT和output,只需关注forward。因为INPUT和output是进出04节点的规则,而forward才是真正针对虚拟机的规则。




这篇关于neutron是如何通过iptables管理网络的的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1034796

相关文章

iptables(7)扩展模块state

简介         前面文章我们已经介绍了一些扩展模块,如iprange、string、time、connlimit、limit,还有扩展匹配条件如--tcp-flags、icmp。这篇文章我们介绍state扩展模块  state          在 iptables 的上下文中,--state 选项并不是直接关联于一个扩展模块,而是与 iptables 的 state 匹配机制相关,特

CentOS linux关闭iptables防火墙(Linux中的防火墙叫iptables)

linux服务器下防火墙为iptables组件,在安装一些软件的时候,iptables防火墙会阻止我们一些必要的连接。 查看iptables状态:service iptables status iptables开机自动启动: 开启: chkconfig iptables on  关闭: chkconfig iptables off iptables关闭服务: 开启: service

运维iptables与firewalld详解

iptables与firewalld 一、iptables 1.1 iptables简介 iptables 是一个在 Linux 系统上用来配置 IPv4 数据包过滤规则的工具。它允许系统管理员控制数据包的流向,实现网络安全、网络地址转换(NAT)和端口转发等功能。 具体来说,iptables 可以用来定义规则集(ruleset),这些规则决定了哪些数据包可以通过系统,哪些需要被丢弃或者拒

Iptables(1)基本概念

简介 iptables 是一个用于 Linux 操作系统的包过滤防火墙工具,可帮助管理网络流量和实施安全策略。它允许用户配置规则集以控制数据包如何在计算机上移动和处理。通过定义规则来允许或拒绝特定类型的流量,iptables 可以提供有效的网络安全保护。 主要功能包括: 数据包过滤:基于规则集来决定是否接受、拒绝或转发数据包。网络地址转换:支持网络地址转换 (NAT) 功能,允许隐藏内部网络

【Linux】使用 iptables 验证访问HDFS 所使用到的端口

目录 ​编辑 一、实操背景 二、iptables 简介 三、模拟操作 一、实操背景 背景: 在客户有外网的服务器需要访问内网大数据集群HDFS,使用iptable模拟测试需要开放的端口。 二、iptables 简介 具体介绍看文章: 【Linux】Iptables 详解与实战案例_linux iptable-CSDN博客 表(tables)提供特定的功能

Linux 防火墙 Firewall 和 Iptables 的使用

如果我们在Linux服务器的某个端口上运行了个服务,需要外网能访问到,就必须通过防火墙将服务运行端口给开启。Linux中有两种防火墙软件,CentOS7.0以上使用的是firewall,CentOS7.0以下使用的是iptables(使用较少且不建议使用)。  Firewall 开启防火墙: systemctl start firewalld 关闭防火墙: systemctl st

iptables 从放弃 到 熟悉

之前碰到 iptables 就感觉像天书一样,其实找到靠谱的资料,然后自己理解,也并不是那么难。 靠谱资料 强烈推荐–>http://www.zsythink.net/archives/tag/iptables/page/2/ 如果认真读完,可以有个很全面的理解视频:http://www.imooc.com/video/7602

初探iptables -- 下

接上篇blog。 具体流程估计都了解了吧。 下面来看看他具体是如何操作,添加,删除以及修改规则。 先上个例子。 iptables -t filter -I INPUT -p icmp -j DROP-t   -->  tables -I   -->  插入方式 INPUT  -->  chain -p  --> 匹配的选项 后面接着协议 -j  -->  target

初探iptables -- 上

最近看了下iptables  给自己总结一下 什么是iptables? 他是一种linux的访问控制机制,也就是大家所说的防火墙了。目前大部分的linux基本都是预装的。 iptables在的实现是通过和底层的netfilter内核模块的调用。iptables/netfilter就是一个工作于用户空间和防火墙的应用软件。 那他能做些什么? netfilter 支持的常用过滤模块

iptables常用命令总结

1.iptables 是什么 在Linux中,iptables就是一款强大而灵活的防火墙工具,它为系统管理员提供了广泛的配置选项,可以有效地控制数据包的流动,实现网络访问的控制及安全性增强。 iptables 使用三个不同的链来允许或阻止流量:输入(input)、输出(output)和转发(forward) 输入(input) —— 此链用于控制传入连接的行为 输出(output) —— 此