{"id":595,"date":"2015-02-12T14:29:43","date_gmt":"2015-02-12T06:29:43","guid":{"rendered":"https:\/\/marvelliu.space\/?p=595"},"modified":"2015-02-12T14:31:52","modified_gmt":"2015-02-12T06:31:52","slug":"%e5%9c%a8%e5%ae%bf%e4%b8%bb%e6%9c%ba%e4%b8%ad%e7%94%a8ovs%e8%bf%9e%e6%8e%a5%e5%86%85%e7%bd%91vm","status":"publish","type":"post","link":"https:\/\/marvelliu.space\/?p=595","title":{"rendered":"\u5728\u5bbf\u4e3b\u673a\u4e2d\u7528ovs\u8fde\u63a5\u5185\u7f51vm"},"content":{"rendered":"<p>\u7ecf\u5e38\u9700\u8981\u505a\u5b9e\u9a8c\u9a8c\u8bc1VM\u7684\u6027\u80fd\uff0c\u90a3\u4e48\u5b9e\u9a8c\u73af\u5883\u4e3a\uff1aH\u662f\u4e00\u4e2a\u7269\u7406\u4e3b\u673a\uff08\u7269\u7406\u7f51\u5361\u7f51\u6bb5\u4e3a192.168.19.0\/24\uff09\uff0cH\u4e2d\u542f\u52a8\u4e00\u53f0VM\uff0cVM\u7684\u4e00\u4e2a\u7ba1\u7406\u53e3eth-M\u914d\u6709\u79c1\u7f51ip\uff08\u7f51\u6bb5100.100.100.0\/24\uff09\uff0c\u5e76\u8fde\u63a5\u5230\u4e00\u4e2aOVS\u6865br-test\u4e0a\u3002\u73b0\u5728\u9700\u8981\u5728H\u4e2d\u76f4\u63a5\u8fde\u63a5VM\u3002<\/p>\n<p>\u4e00\u4e2a\u76f4\u89c2\u7684\u60f3\u6cd5\u662f\u76f4\u63a5ping VM\uff0c\u4f46VM\u4e0e\u5bbf\u4e3b\u673a\u7684\u4e3bIP\u4e0d\u662f\u4e00\u4e2a\u7f51\u6bb5\uff0c\u6240\u4ee5\u4e0d\u80fd\u76f4\u63a5\u901a\u4fe1\uff0c\u9700\u8981\u4e00\u4e2a\u7f51\u5173GW\u3002\u90a3\u5c31\u76f4\u63a5\u5728br-test\u4e0a\u65b0\u5efa\u4e00\u4e2a\u7c7b\u578b\u4e3ainternal\u7684\u63a5\u53e3\u505a\u7f51\u5173\u3002<\/p>\n<pre>\r\novs-vsctl add-port br-test gw -- set Interface gw type=internal\r\nifconfig gw 100.100.100.1\r\niptables -t nat -I POSTROUTING -j SNAT  -s 192.168.19.0\/24 --to-source 100.100.100.1\r\niptables -t nat -I POSTROUTING -j SNAT  -s 100.100.100.0\/24 --to-source 192.168.19.13\r\n<\/pre>\n<p>\u5e76\u4f7f\u7528iptables\u505aNAT\uff0c\u4f46\u53d1\u73b0\u8fd8\u662fping\u4e0d\u901a\u3002\u6211\u5370\u8c61\u4e2diptables\u7684\u8bbf\u95ee\u89c4\u5219\u4e0eopenvswitch\u4e0d\u517c\u5bb9\uff0c\u4e0d\u77e5\u9053nat\u662f\u4e0d\u662f\u4e5f\u53d7\u5230\u5f71\u54cd\u3002<\/p>\n<p>\u65e2\u7136\u5982\u6b64\uff0cgw\u7684\u8def\u7531\u5e94\u8be5\u4e0d\u80fd\u653e\u5728openvswitch\u4e2d\uff0c\u53ea\u80fd\u5728namespace\u6216\u539flinux\u7cfb\u7edf\u4e2d\u3002\u6362\u4e00\u4e2a\u601d\u8def\uff0c\u4e0d\u5c06\u7f51\u5173\u76f4\u63a5\u653e\u5728br-test\u4e0a\uff0c\u800c\u662f\u4f7f\u7528veth\u5bf9\u7684\u5f62\u5f0f\uff1a<\/p>\n<pre>\r\n ip link add gw type veth peer name gw-o\r\novs-vsctl add-port br-test gw\r\nifconfig gw 100.100.100.1\r\niptables -t nat -I POSTROUTING -j SNAT  -s 192.168.19.0\/24 --to-source 100.100.100.100\r\niptables -t nat -I POSTROUTING -j SNAT  -s 100.100.100.0\/24 --to-source 192.168.19.13\r\n<\/pre>\n<p>\u90a3\u4e48\u6570\u636e\u4ecegw\u4f20\u5230\u4e86gw-o\uff0c\u6b64\u65f6\u53ef\u4ee5\u6b63\u5e38\u8def\u7531\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ecf\u5e38\u9700\u8981\u505a\u5b9e\u9a8c\u9a8c\u8bc1VM\u7684\u6027\u80fd\uff0c\u90a3\u4e48\u5b9e\u9a8c\u73af\u5883\u4e3a\uff1aH\u662f\u4e00\u4e2a\u7269\u7406\u4e3b\u673a\uff08\u7269\u7406\u7f51\u5361\u7f51\u6bb5\u4e3a192.168.19.0\/24\uff09\uff0cH\u4e2d\u542f\u52a8\u4e00\u53f0VM\uff0cVM\u7684\u4e00\u4e2a\u7ba1\u7406\u53e3eth-M\u914d\u6709\u79c1\u7f51ip\uff08\u7f51\u6bb5100.100.100.0\/24\uff09\uff0c\u5e76\u8fde\u63a5\u5230\u4e00\u4e2aOVS\u6865br-test\u4e0a\u3002\u73b0\u5728\u9700\u8981\u5728H\u4e2d\u76f4\u63a5\u8fde\u63a5VM\u3002 \u4e00\u4e2a\u76f4\u89c2\u7684\u60f3\u6cd5\u662f\u76f4\u63a5ping VM\uff0c\u4f46VM\u4e0e\u5bbf\u4e3b\u673a\u7684\u4e3bIP\u4e0d\u662f\u4e00\u4e2a\u7f51\u6bb5\uff0c\u6240\u4ee5\u4e0d\u80fd\u76f4\u63a5\u901a\u4fe1\uff0c\u9700\u8981\u4e00\u4e2a\u7f51\u5173GW\u3002\u90a3\u5c31\u76f4\u63a5\u5728br-test\u4e0a\u65b0\u5efa\u4e00\u4e2a\u7c7b\u578b\u4e3ainternal\u7684\u63a5\u53e3\u505a\u7f51\u5173\u3002 ovs-vsctl add-port br-test gw &#8212; set Interface gw type=internal ifconfig gw 100.100.100.1 iptables -t nat -I POSTROUTING -j SNAT -s 192.168.19.0\/24 &#8211;to-source 100.100.100.1 iptables -t nat -I POSTROUTING -j SNAT -s 100.100.100.0\/24 &#8211;to-source 192.168.19.13 \u5e76\u4f7f\u7528iptables\u505aNAT\uff0c\u4f46\u53d1\u73b0\u8fd8\u662fping\u4e0d\u901a\u3002\u6211\u5370\u8c61\u4e2diptables\u7684\u8bbf\u95ee\u89c4\u5219\u4e0eopenvswitch\u4e0d\u517c\u5bb9\uff0c\u4e0d\u77e5\u9053nat\u662f\u4e0d\u662f\u4e5f\u53d7\u5230\u5f71\u54cd\u3002 \u65e2\u7136\u5982\u6b64\uff0cgw\u7684\u8def\u7531\u5e94\u8be5\u4e0d\u80fd\u653e\u5728openvswitch\u4e2d\uff0c\u53ea\u80fd\u5728namespace\u6216\u539flinux\u7cfb\u7edf\u4e2d\u3002\u6362\u4e00\u4e2a\u601d\u8def\uff0c\u4e0d\u5c06\u7f51\u5173\u76f4\u63a5\u653e\u5728br-test\u4e0a\uff0c\u800c\u662f\u4f7f\u7528veth\u5bf9\u7684\u5f62\u5f0f\uff1a ip link add gw type veth peer name gw-o ovs-vsctl add-port br-test gw ifconfig gw 100.100.100.1 &hellip; <a href=\"https:\/\/marvelliu.space\/?p=595\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;\u5728\u5bbf\u4e3b\u673a\u4e2d\u7528ovs\u8fde\u63a5\u5185\u7f51vm&#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":[26],"tags":[],"class_list":["post-595","post","type-post","status-publish","format-standard","hentry","category-sdn"],"_links":{"self":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/595","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=595"}],"version-history":[{"count":3,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/595\/revisions"}],"predecessor-version":[{"id":598,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/595\/revisions\/598"}],"wp:attachment":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}