{"id":460,"date":"2013-07-16T16:37:39","date_gmt":"2013-07-16T08:37:39","guid":{"rendered":"http:\/\/blog.marvelplanet.tk\/?p=460"},"modified":"2014-01-24T11:23:52","modified_gmt":"2014-01-24T03:23:52","slug":"openstacknat-gateway%e5%92%8cport%e4%b8%8d%e4%b8%80%e8%87%b4%e5%af%bc%e8%87%b4vm%e4%b8%8d%e8%83%bd%e5%88%b0%e5%a4%96%e7%bd%91","status":"publish","type":"post","link":"https:\/\/marvelliu.space\/?p=460","title":{"rendered":"[openstack]NAT gateway\u548cport\u4e0d\u4e00\u81f4\u5bfc\u81f4VM\u4e0d\u80fd\u5230\u5916\u7f51"},"content":{"rendered":"<p>\u5f53VM\u8bbe\u7f6e\u5b8cfloatingip\u540e\uff0cVM\u8fd8\u662f\u4e0d\u80fd\u8fde\u63a5\u5916\u7f51\uff0c\u6392\u67e5\u539f\u56e0\uff0c\u53d1\u73b0\u662fquantum\u4e2d\u8bbe\u7f6e\u7684\u95ee\u9898\uff1a<\/p>\n<p>quantum\u4e2d\u8bbe\u7f6e\u5916\u7f51\u4e3a192.168.19.129\/25\uff0c\u4e0d\u8bbe\u7f51\u5173\uff0callocation_pools\u4e3a{&#8220;start&#8221;: &#8220;192.168.19.130&#8221;, &#8220;end&#8221;: &#8220;192.168.19.254&#8221;}\u3002<\/p>\n<p>root@controller:\/usr\/src\/nova# ip netns exec qrouter-b4721d20-9d39-4d4d-9c37-f18ecb460d02 route -n<br \/>\nKernel IP routing table<br \/>\nDestination     Gateway         Genmask         Flags Metric Ref    Use Iface<br \/>\n0.0.0.0         192.168.19.129  0.0.0.0         UG    0      0        0 qg-29c30020-2e<br \/>\n10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 qr-cd728374-d8<br \/>\n10.0.1.0        0.0.0.0         255.255.255.0   U     0      0        0 qr-f915c799-96<br \/>\n192.168.19.128  0.0.0.0         255.255.255.128 U     0      0        0 qg-29c30020-2e<\/p>\n<p>\u8def\u7531\u5668\u7684\u7f51\u5361\u5374\u662f\uff1a<\/p>\n<pre>\r\nroot@controller:\/usr\/src\/nova# ip netns exec qrouter-b4721d20-9d39-4d4d-9c37-f18ecb460d02 ifconfig\r\nlo        Link encap:Local Loopback  \r\n          inet addr:127.0.0.1  Mask:255.0.0.0\r\n          inet6 addr: ::1\/128 Scope:Host\r\n          UP LOOPBACK RUNNING  MTU:16436  Metric:1\r\n          RX packets:14 errors:0 dropped:0 overruns:0 frame:0\r\n          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0\r\n          collisions:0 txqueuelen:0 \r\n          RX bytes:1390 (1.3 KB)  TX bytes:1390 (1.3 KB)\r\n\r\nqg-29c30020-2e Link encap:Ethernet  HWaddr fa:16:3e:10:18:21  \r\n          inet addr:<strong>192.168.19.130<\/strong>  Bcast:192.168.19.255  Mask:255.255.255.128\r\n          inet6 addr: fe80::f816:3eff:fe10:1821\/64 Scope:Link\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          RX packets:87 errors:0 dropped:0 overruns:0 frame:0\r\n          TX packets:67 errors:0 dropped:0 overruns:0 carrier:0\r\n          collisions:0 txqueuelen:0 \r\n          RX bytes:12593 (12.5 KB)  TX bytes:9608 (9.6 KB)\r\n\r\nqr-cd728374-d8 Link encap:Ethernet  HWaddr fa:16:3e:d7:5a:2f  \r\n          inet addr:10.0.0.1  Bcast:10.0.0.255  Mask:255.255.255.0\r\n          inet6 addr: fe80::f816:3eff:fed7:5a2f\/64 Scope:Link\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          RX packets:64 errors:0 dropped:0 overruns:0 frame:0\r\n          TX packets:89 errors:0 dropped:0 overruns:0 carrier:0\r\n          collisions:0 txqueuelen:0 \r\n          RX bytes:9710 (9.7 KB)  TX bytes:10627 (10.6 KB)\r\n\r\nqr-f915c799-96 Link encap:Ethernet  HWaddr fa:16:3e:96:89:3a  \r\n          inet addr:10.0.1.1  Bcast:10.0.1.255  Mask:255.255.255.0\r\n          inet6 addr: fe80::f816:3eff:fe96:893a\/64 Scope:Link\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          RX packets:0 errors:0 dropped:0 overruns:0 frame:0\r\n          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0\r\n          collisions:0 txqueuelen:0 \r\n          RX bytes:0 (0.0 B)  TX bytes:594 (594.0 B)\r\n<\/pre>\n<p>\u8fd9\u4e24\u4e2a\u503c\u662f\u4e0d\u540c\u7684\uff0c\u672c\u5e94\u4ece192.168.19.130\u8def\u7531\u7684\u6570\u636e\u5305\u5747\u53d1\u5f80192.168.19.129\uff0c\u5bfc\u81f4VM\u65e0\u6cd5\u51fa\u53bb\u3002\u5176\u5b9e\u540e\u8005\u662fquantum\u4e2d\u4e0e\u5916\u7f51\u8fde\u63a5\u7684port\u4e2d\u7684fixed_ips\u503c\uff1a<\/p>\n<pre>\r\n+--------------------------------------+------+-------------------+---------------------------------------------------------------------------------------+\r\n| id                                   | name | mac_address       | fixed_ips                                                                             |\r\n+--------------------------------------+------+-------------------+---------------------------------------------------------------------------------------+\r\n| 10d13e25-cc01-4edc-aba4-5e2b3a6dff80 |      | fa:16:3e:e6:9e:30 | {\"subnet_id\": \"169ad3b8-c961-4128-b053-2d6d36afbe1f\", \"ip_address\": \"10.0.0.4\"}       |\r\n| <strong>29c30020-2e91-4ffa-91e3-a8acef553641 |      | fa:16:3e:10:18:21 | {\"subnet_id\": \"3f53264f-683b-45a8-a7ab-289afd2288b5\", \"ip_address\": \"192.168.19.130\"}<\/strong> |\r\n| 7e659611-43b3-4f52-b392-28ddd5051bca |      | fa:16:3e:9e:84:c8 | {\"subnet_id\": \"3f53264f-683b-45a8-a7ab-289afd2288b5\", \"ip_address\": \"192.168.19.131\"} |\r\n| 7f000789-2e36-4aef-8d08-acb700ddde9f |      | fa:16:3e:07:92:81 | {\"subnet_id\": \"169ad3b8-c961-4128-b053-2d6d36afbe1f\", \"ip_address\": \"10.0.0.2\"}       |\r\n| 91da98b9-e9df-4a2c-b97d-02299d33fe89 |      | fa:16:3e:f7:42:d9 | {\"subnet_id\": \"3f53264f-683b-45a8-a7ab-289afd2288b5\", \"ip_address\": \"192.168.19.132\"} |\r\n| a132b58c-238a-4b9f-92ce-c47521cda668 |      | fa:16:3e:31:81:8e | {\"subnet_id\": \"169ad3b8-c961-4128-b053-2d6d36afbe1f\", \"ip_address\": \"10.0.0.3\"}       |\r\n| b1a9afa6-6850-4044-a2b6-cca6c12fc6fa |      | fa:16:3e:89:2e:fb | {\"subnet_id\": \"0636c5f2-70ab-4fb9-a7d5-986c92eaf1aa\", \"ip_address\": \"10.0.1.2\"}       |\r\n| b629349e-ad6e-427a-8aae-291f55ef4b32 |      | fa:16:3e:31:a2:cf | {\"subnet_id\": \"169ad3b8-c961-4128-b053-2d6d36afbe1f\", \"ip_address\": \"10.0.0.5\"}       |\r\n| cd728374-d89e-4f64-b437-b3e1580b49e9 |      | fa:16:3e:d7:5a:2f | {\"subnet_id\": \"169ad3b8-c961-4128-b053-2d6d36afbe1f\", \"ip_address\": \"10.0.0.1\"}       |\r\n| f915c799-96aa-40bf-a3aa-06d43bc1c284 |      | fa:16:3e:96:89:3a | {\"subnet_id\": \"0636c5f2-70ab-4fb9-a7d5-986c92eaf1aa\", \"ip_address\": \"10.0.1.1\"}       |\r\n+--------------------------------------+------+-------------------+---------------------------------------------------------------------------------------+\r\n<\/pre>\n<p>\u5982\u679c\u8bbe\u7f6e\u8be5\u7f51\u7edc\u7684\u7f51\u5173\u4e3a130\uff0c\u63d0\u793a\u5931\u8d25\uff1a<\/p>\n<pre>\r\n# quantum subnet-update userA-public --gateway_ip 192.168.19.130\r\nGateway ip 192.168.19.130 conflicts with allocation pool 192.168.19.130-192.168.19.254\r\n<\/pre>\n<p>\u5728quantum\u4ee3\u7801\u4e2d\u4f53\u73b0\u662f\uff1a<br \/>\nagent\/l3_agent.py<\/p>\n<pre class=\"python\" name=\"code\">\r\n        ex_gw_ip = ex_gw_port['fixed_ips'][0]['ip_address']\r\n        if not ip_lib.device_exists(interface_name,\r\n                                    root_helper=self.root_helper,\r\n                                    namespace=ri.ns_name()):\r\n            \r\n......\r\n\r\n        gw_ip = ex_gw_port['subnet']['gateway_ip']\r\n        if ex_gw_port['subnet']['gateway_ip']:\r\n            cmd = ['route', 'add', 'default', 'gw', gw_ip]\r\n<\/pre>\n<p>\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\u8fd9\u91cc\u6709\u4e24\u4e2a\uff1aex_gw_ip\u548cgw_ip\uff0c\u4e0d\u4e00\u81f4\u5bfc\u81f4\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p>workaround\u5f88\u7b80\u5355\uff1a<\/p>\n<pre>\r\n# ip netns exec qrouter-b4721d20-9d39-4d4d-9c37-f18ecb460d02 route del default gw 192.168.19.129\r\n# ip netns exec qrouter-b4721d20-9d39-4d4d-9c37-f18ecb460d02 route add default gw 192.168.19.130\r\n<\/pre>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;\u6211\u662f\u5206\u5272\u7ebf&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n\u4e0a\u9762\u7684workaround\u5f88\u662f\u9ebb\u70e6\uff0c\u6bcf\u6b21\u91cd\u542fl3agent\u90fd\u9700\u8981\u6dfb\u52a0\uff0c\u6211\u4eca\u5929\u770b\u4e86\u4e00\u4e0b\u8fd9\u4e2a\u95ee\u9898\uff0c\u5176\u5b9e\u8fd8\u662f\u56e0\u4e3a\u6211\u4eec\u5bf9neutron\u7f51\u7edc\u4e0d\u592a\u7406\u89e3\u9020\u6210\u7684\u3002\u6211\u524d\u9762\u7684\u65b9\u6cd5\u662f\u5148\u5c06\u6570\u636e\u5305\u6254\u5230qg-f103a9f2-d6\u63a5\u53e3\uff0c\u7136\u540e\u5728\u547d\u540d\u7a7a\u95f4\u5916\u7684\u8def\u7531\u8868\u4e2d\u8fdb\u884c\u8def\u7531\u51b3\u7b56\uff1a<\/p>\n<pre>\r\n# ip netns exec qrouter-09be29ea-25f6-4a53-b3ab-8d0e13dc7198 route -n\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags Metric Ref    Use Iface\r\n0.0.0.0         192.168.19.130  0.0.0.0         UG    0      0        0 qg-f103a9f2-d6\r\n100.0.0.0       0.0.0.0         255.255.255.0   U     0      0        0 qr-d8fcb028-ea\r\n192.168.19.0    0.0.0.0         255.255.255.0   U     0      0        0 qg-f103a9f2-d6\r\n200.0.0.0       0.0.0.0         255.255.255.0   U     0      0        0 qr-b422c431-d8\r\n\r\n# route -n\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags Metric Ref    Use Iface\r\n0.0.0.0         192.168.19.254  0.0.0.0         UG    100    0        0 br-ex\r\n20.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth1\r\n30.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth2\r\n192.168.19.0    0.0.0.0         255.255.255.0   U     0      0        0 br-ex\r\n<\/pre>\n<p>\u6570\u636e\u5305\u7684\u6d41\u5411\u662fqr-d8fcb028-ea->(namespace routing)->qg-f103a9f2-d6->(routing)->br-ex->eth0->router<\/p>\n<p>\u5176\u5b9epublic-net\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u5916\u7f51\uff0c\u6240\u4ee5\u5e94\u8be5\u8ddf\u7269\u7406\u673a\u7684\u7f51\u7edc\u4e00\u81f4\uff0c\u4e5f\u5c31\u662f192.168.19.0\/24\uff0c\u7f51\u5173\u662f\u7269\u7406\u7f51\u5173192.168.19.254\u3002\u8fd9\u6837\uff0c\u6bcf\u6b21l3agent\u90fd\u4f1a\u5728\u547d\u540d\u7a7a\u95f4\u4e2d\u65b0\u5efa\u9ed8\u8ba4\u8def\u7531\uff1a<\/p>\n<pre>\r\n# ip netns exec qrouter-09be29ea-25f6-4a53-b3ab-8d0e13dc7198 route -n\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags Metric Ref    Use Iface\r\n0.0.0.0         192.168.19.254  0.0.0.0         UG    0      0        0 qg-f103a9f2-d6\r\n100.0.0.0       0.0.0.0         255.255.255.0   U     0      0        0 qr-d8fcb028-ea\r\n192.168.19.0    0.0.0.0         255.255.255.0   U     0      0        0 qg-f103a9f2-d6\r\n200.0.0.0       0.0.0.0         255.255.255.0   U     0      0        0 qr-b422c431-d8\r\n<\/pre>\n<p>\u8fd9\u6837\u6570\u636e\u5305\u5230\u4e86\u8fd9\u4e2a\u547d\u540d\u7a7a\u95f4\u540e\uff0c\u76f4\u63a5\u7ecf\u8fc7\u8def\u7531\u51b3\u7b56\u4eceqg-f103a9f2-d6\u7ecf\u8fc7br-ex\u5230eth0\u51fa\u53bb\u4e86\u3002\u867d\u7136\u6570\u636e\u5305\u6d41\u5411\u4e0e\u524d\u9762\u7684\u4e00\u6837\uff0c\u4f46\u662f\u4ece\u547d\u540d\u7a7a\u95f4\u5230\u7269\u7406\u7f51\u5173\u8fd8\u662f\u5728\u4e00\u4e2a\u7f51\u7edc\u4e2d\u6d41\u52a8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53VM\u8bbe\u7f6e\u5b8cfloatingip\u540e\uff0cVM\u8fd8\u662f\u4e0d\u80fd\u8fde\u63a5\u5916\u7f51\uff0c\u6392\u67e5\u539f\u56e0\uff0c\u53d1\u73b0\u662fquantum\u4e2d\u8bbe\u7f6e\u7684\u95ee\u9898\uff1a quantum\u4e2d\u8bbe\u7f6e\u5916\u7f51\u4e3a192.168.19.129\/25\uff0c\u4e0d\u8bbe\u7f51\u5173\uff0callocation_pools\u4e3a{&#8220;start&#8221;: &#8220;192.168.19.130&#8221;, &#8220;end&#8221;: &#8220;192.168.19.254&#8221;}\u3002 root@controller:\/usr\/src\/nova# ip netns exec qrouter-b4721d20-9d39-4d4d-9c37-f18ecb460d02 route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.19.129 0.0.0.0 UG 0 0 0 qg-29c30020-2e 10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 qr-cd728374-d8 10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 qr-f915c799-96 192.168.19.128 0.0.0.0 255.255.255.128 U 0 0 0 &hellip; <a href=\"https:\/\/marvelliu.space\/?p=460\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;[openstack]NAT gateway\u548cport\u4e0d\u4e00\u81f4\u5bfc\u81f4VM\u4e0d\u80fd\u5230\u5916\u7f51&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[29],"class_list":["post-460","post","type-post","status-publish","format-standard","hentry","category-tech","tag-openstack"],"_links":{"self":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=460"}],"version-history":[{"count":6,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/460\/revisions"}],"predecessor-version":[{"id":539,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/460\/revisions\/539"}],"wp:attachment":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}