{"id":24008,"date":"2020-02-11T21:02:53","date_gmt":"2020-02-11T13:02:53","guid":{"rendered":"http:\/\/4563.org\/?p=24008"},"modified":"2020-02-11T21:02:53","modified_gmt":"2020-02-11T13:02:53","slug":"%e4%bd%bf%e7%94%a8nftables-%e4%bd%8e%e6%88%90%e6%9c%ac%e9%ab%98%e6%95%88%e7%8e%87%e8%bd%ac%e5%8f%91","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=24008","title":{"rendered":"\u4f7f\u7528Nftables \u4f4e\u6210\u672c\u9ad8\u6548\u7387\u8f6c\u53d1"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>airski<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>\u4f7f\u7528Nftables \u4f4e\u6210\u672c\u9ad8\u6548\u7387\u8f6c\u53d1<\/h3>\n<p>  \t\t\u770b\u5230\u597d\u51e0\u6b21\u6d41\u91cf\u8f6c\u53d1\u7684\u5e16\u5b50, 2020\u5e74\u4e86, \u95f2\u7740\u5b66\u4e60\u4e86\u4e00\u4e0bNftables,\u57fa\u4e8e\u5305\u7684\u7b56\u7565, \u7406\u8bba\u8f6c\u53d1\u6548\u7387\u8981\u6bd4\u5e94\u7528\u5c42\u7684\u8f6f\u4ef6 haproxy socat \u4e4b\u7c7b\u7684\u597dN\u500d.<\/p>\n<p>  #!\/usr\/sbin\/nft -f<\/p>\n<p>  delete table ip nat<\/p>\n<p>  table ip nat {<br \/>  &nbsp; &nbsp;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; map port_to_ip {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type inet_service : ipv4_addr<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elements = {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 1000: 192.168.1.1<br \/>  &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>  &nbsp; &nbsp; &nbsp; &nbsp; map port_to_port {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type inet_service : inet_service<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elements = {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 1000: 1000<br \/>  &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>  &nbsp; &nbsp; &nbsp; &nbsp; chain prerouting {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type nat hook prerouting priority 100; policy accept;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dnat to tcp dport map @port_to_ip:tcp dport map @port_to_port<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dnat to udp dport map @port_to_ip:udp dport map @port_to_port<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>  &nbsp; &nbsp; &nbsp; &nbsp; chain postrouting {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type nat hook postrouting priority 100; policy accept;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; masquerade random,persistent<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>  }<\/p>\n<p>  \u4f7f\u7528\u65b9\u6cd5:<\/p>\n<p>  1. \u5b89\u88c5nftables<br \/>  2. \u4fdd\u5b58\u4ee5\u4e0a\u7684code, \u8bb0\u5f97\u7f16\u8f91 port_to_ip, port_to_port. 2\u4e2a\u6570\u636e\u8868\u4e3a \u8f6c\u53d1\u7aef\u53e3\u5bf9\u5e94\u76ee\u6807\u8282\u70b9, \u8f6c\u53d1\u7aef\u53e3\u5bf9\u5e94\u76ee\u6807\u7aef\u53e3.<br \/>  3. \u52a0\u8f7d `nft -f xxx`<\/p>\n<p>  \u7279\u522b\u63d0\u9192, \u5b89\u88c5\u4e86docker\u673a\u5668\u614e\u7528   \t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>guonning2000<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u53ef\u4ee5\u8bd5\u8bd5\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>airski \u5927\u4f6c\u6709\u8bdd\u8bf4 : \u4f7f\u7528&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/24008"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24008"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/24008\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=24008"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=24008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}