openstack单网卡使用多IP说明、openstack虚拟机IP通网关但同网段IP不互通处理方法

openstack虚拟机IP通网关但同网段IP不互通处理方法

问题描述

  • 云平台的防火墙虚拟机部署再我们云平台上,防火墙虚拟机所属物理机坏了,将虚拟机迁移到别的宿主机上后,出现了以下问题
    • 1、虚拟机能通网关,但同网段直接不能互通【并非全部,偶尔有一两台能互通】;
    • 2、有外网的主机,部分能正常使用。

处理方法

  • 处理流程如下:

    • 再防火墙虚拟机所属计算节点宿主机上,用iptables 过滤你的 nf 192.168.252的ip地址 【nf地址也就是每个地址端的网关地址(好像记得网络部同事说是网关地址)】
      如:iptables -S|grep 192.168.252(你nf具有的192.168.252.的ip地址)
    • 然后 iptables -R 刚才你过滤得到的链的名称 2 -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT
      • 如:192.168.252.101接口:iptables -R neutron-linuxbri-s89f58cf4-4 2 -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT
      • 如111.11.199.65接口:iptables -R neutron-linuxbri-sbc8e8a29-d 2 -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT
  • 下面是实操,一个地址的流程【有多个地址,就重复下面操作即可,我们这其实有六七个这种网关地址,所以是执行了六七次的,只是将其中一次的过程放到这里了而已】

[root@computer04 ~]# iptables -S | grep 192.168.244.125
-A neutron-linuxbri-s679500a7-9 -s 192.168.244.125/32 -m mac --mac-source FA:16:3E:95:08:2C -m comment --comment "Allow traffic from defined IP/MAC pairs." -j RETURN
[root@computer04 ~]# iptables -S | grep neutron-linuxbri-s679500a7-9
-N neutron-linuxbri-s679500a7-9
-A neutron-linuxbri-o679500a7-9 -j neutron-linuxbri-s679500a7-9
-A neutron-linuxbri-s679500a7-9 -s 192.168.244.125/32 -m mac --mac-source FA:16:3E:95:08:2C -m comment --comment "Allow traffic from defined IP/MAC pairs." -j RETURN
-A neutron-linuxbri-s679500a7-9 -m comment --comment "Drop traffic without an IP/MAC allow rule." -j DROP
[root@computer04 ~]#  # 上面可以看到是被 DROP的
[root@computer04 ~]# iptables -R neutron-linuxbri-s679500a7-9  2 -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT
[root@computer04 ~]# 
[root@computer04 ~]# iptables -S | grep neutron-linuxbri-s679500a7-9
-N neutron-linuxbri-s679500a7-9
-A neutron-linuxbri-o679500a7-9 -j neutron-linuxbri-s679500a7-9
-A neutron-linuxbri-s679500a7-9 -s 192.168.244.125/32 -m mac --mac-source FA:16:3E:95:08:2C -m comment --comment "Allow traffic from defined IP/MAC pairs." -j RETURN
-A neutron-linuxbri-s679500a7-9 -j ACCEPT
[root@computer04 ~]#  # 放开以后可以看到为ACCEPT了
  • 放个图片,记录一下,现在公有云防火墙虚拟机在computer04上,如果后面换主机了,这些操作全部得再新宿主机上执行一遍。。。不然网络还是有问题。
    在这里插入图片描述

Openstack中单网卡使用多ip

  • 其实我上面的操作实现的效果也是单网卡使用多IP。下面内容来源于网络,更主要是介绍单网卡使用多IP这个概念

  • 创建虚拟机时主机上会有一条iptables 用来将ip和mac绑定,用来防止arp欺骗。在需要给单个网卡配置多个ip的场景下(例如keepalive)另外添加的ip地址是无法与外界通信的。 两种方法来解决。

  • 第一种是使用allowed-address-pairs来扩展端口属性,允许手动指定端口的mac_address和ip 地址对的流量通过。

      1. 建立port时指定allowed-address-pairs属性
        # neutron port-create e13762dc-9af7-49b6-a74e-2ed2a9728a6c --allowed-address-pairs type=dict list=true ip_address=172.16.1.5
        在这里插入图片描述
        可以看出新建的port的ip_address为172.16.1.7,而对应的allowed-address-pairs为172.16.1.5,两个ip对应的mac是相同的。
      1. 给现有网卡添加allowed-address-pairs属性
        在这里插入图片描述
        # neutron port-update 18dea4cb-db1d-4c44-96f0-0b57305e7b1e --allowed-address-pairs type=dict list=true ip_address=172.16.1.23
        在这里插入图片描述
  • 设置了属性后主机的iptables如下:

RETURN     all  --  172.16.1.5           anywhere             MAC FA:16:3E:65:5B:C7 /* Allow traffic from defined IP/MAC pairs. */
RETURN     all  --  172.16.1.4           anywhere             MAC FA:16:3E:65:5B:C7 /* Allow traffic from defined IP/MAC pairs. */
  • 第二种是使用port_security_enabled属性,可以针对整个网络更改,也针对某个端口更改。
    创建net和port时现在没有参数来指定port_security_enabled,默认是True,所以需要在创建之后更新。

  • 首先移除port上的安全组(创建port时默认是有安全组的,可以添加参数–no-security-groups创建没有安全组的prot),然后设置port的port_security_enabled为False(有安全组时port_security_enabled无法设置为False ) :

neutron port-update b0ddb9ad-6250-45f2-9927-a6633ddaf406 --no-security-groups --port_security_enabled=False
  • 设置了port_security_enabled=False后再主机的iptables中对应的下面规则会被删除。
RETURN     all  --  172.16.1.4           anywhere             MAC FA:16:3E:65:5B:C7 /* Allow traffic from defined IP/MAC pairs. */

猜你喜欢

转载自blog.csdn.net/cuichongxin/article/details/129442920