文章來自作者維護的社群微信公衆号【虛拟化雲計算】) ( 目前有兩個微信群《kvm虛拟化》和《openstack》,掃描二維碼點選“雲-交流”,進群交流提問)
建立虛拟機時主機上會有一條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是相同的。 2. 給現有網卡添加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 RETURN all -- 172.16.1.4 anywhere MAC FA:16:3E:65:5B:C7 |
第二種是使用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 |
============================================================ 關注微信公衆号【虛拟化雲計算】,閱讀更多虛拟化雲計算知識,純技術幹貨更新不停。