﻿{"id":755,"date":"2012-03-19T16:32:18","date_gmt":"2012-03-19T08:32:18","guid":{"rendered":"http:\/\/nick.workao.org\/?p=755"},"modified":"2021-11-25T16:26:07","modified_gmt":"2021-11-25T08:26:07","slug":"%e7%94%a8iptables%e5%81%9a%e6%9c%ac%e6%9c%ba%e7%ab%af%e5%8f%a3%e8%bd%ac%e5%8f%91","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/linux\/755","title":{"rendered":"\u7528iptables\u505a\u7aef\u53e3\u8f6c\u53d1"},"content":{"rendered":"<p>\u672c\u673a\u7aef\u53e3\u8f6c\u53d1\uff1a<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a iptables -t nat -A PREROUTING -p tcp &#8211;dport 80 -j REDIRECT &#8211;to-ports 8080 \u4f30\u8ba1\u9002\u5f53\u589e\u52a0\u5176\u5b83\u7684\u53c2\u6570\u4e5f\u53ef\u4ee5\u505a\u4e0d\u540cIP\u7684\u7aef\u53e3\u8f6c\u53d1\u3002 \u5982\u679c\u9700\u8981\u672c\u673a\u4e5f\u53ef\u4ee5\u8bbf\u95ee\uff0c\u5219\u9700\u8981\u914d\u7f6eOUTPUT\u94fe\uff1a iptables -t nat -A OUTPUT -p tcp &#8211;dport 80 -j REDIRECT &#8211;to-ports 8080 \u539f\u56e0\uff1a \u5916\u7f51\u8bbf\u95ee\u9700\u8981\u7ecf\u8fc7PREROUTING\u94fe\uff0c\u4f46\u662flocalhost\u4e0d\u7ecf\u8fc7\u8be5\u94fe\uff0c\u56e0\u6b64\u9700\u8981\u7528OUTPUT\uff0c\u6216\u8005POSTROUTING\u3002 POSTROUTING\u4e0d\u884c\uff0c\u9700\u8981\u770b\u770b\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u8f6c\u53d1\u5230\u5176\u5b83\u7535\u8111\uff1a<\/p>\n<p>\u673a\u5668A\u548c\u673a\u5668B\u901a\u8fc7\u5185\u7f51\u5730\u5740\u76f8\u8fde\uff0c\u4e24\u53f0\u673a\u5668\u7684ip\u5206\u522b\u5982\u4e0b<\/p>\n<p>\u673a\u5668A\uff1aeth0 123.123.123.123\neth1 192.168.0.1<\/p>\n<p>\u673a\u5668B\uff1aeth0 192.168.0.2<\/p>\n<p>\u73b0\u5728\u8981\u628a \u673a\u5668A 123.123.123.123\u768481\u7aef\u53e3\uff0c\u6620\u5c04\u5230\u673a\u5668B\u768480\u7aef\u53e3<\/p>\n<p>\u5728\u673a\u5668A\u4e0a\u9700\u8981\u505a\u5982\u4e0b\u64cd\u4f5c\nvi \/etc\/sysctl.conf\n\u5c06 net.ipv4.ip_forward \u7684\u503c\u4fee\u6539\u4e3a 1\n\u7136\u540e\u6267\u884c sysctl -p\n\u7136\u540e\u6267\u884c\u4e24\u6761\u547d\u4ee4<\/p>\n<p>iptables -t nat -A PREROUTING -d 123.123.123.123 -p tcp -m tcp &#8211;dport 81 -j DNAT &#8211;to-destination 192.168.0.2:80<\/p>\n<p>iptables -t nat -A POSTROUTING -d 192.168.0.2 -p tcp -m tcp &#8211;dport 80 -j SNAT &#8211;to-source 192.168.0.1<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u53ea\u5141\u8bb8\u6307\u5b9aIP\u8bbf\u95ee\u6307\u5b9a\u7aef\u53e3\u8bbe\u7f6e\niptables -I INPUT -p TCP &#8211;dport 3306 -j DROP\niptables -I INPUT -s 10.10.10.1 -p TCP &#8211;dport 3306 -j ACCEPT\niptables -I INPUT -s 127.0.0.1 -p TCP &#8211;dport 3306 -j ACCEPT<\/p>\n<p><span style=\"color: #ff6600;\">\u6ce8\u610f\uff1a\u4ee5\u4e0a\u9650\u5236IP\u5728nat\u8303\u56f4\u662f\u65e0\u6548\u7684\uff0c\u5982\u679c\u9700\u8981\u5728nat\u5f71\u5c04\u7aef\u53e3\u505a\u9650\u5236\uff0c\u53ef\u4ee5\u5728\u505a\u5f71\u5c04\u65f6\u52a0\u53c2\u6570-s\u9650\u5236\u6307\u5b9aip\u5b9e\u73b0<\/span><\/p>\n<p>\u6700\u540e\u8bb0\u5f97\u8981\u5728\u91cd\u542f\u65f6\u52a0\u8f7diptables\u7684\u8bbe\u7f6e\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>portmap \u7aef\u53e3\u8f6c\u53d1<\/strong><\/p>\n<p>Linux \u7248\u7684lcx\uff0c\u5185\u7f51\u7aef\u53e3\u8f6c\u53d1\u5de5\u5177\u3002<\/p>\n<p>\uff081\uff09\u4e0b\u8f7d\u5730\u5740\uff1a<\/p>\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"hljs apache\">&lt;span class=&quot;code-snippet_outer&quot;&gt;&lt;span class=&quot;hljs-attribute&quot;&gt;http&lt;\/span&gt;:\/\/www.vuln.cn\/wp-content\/uploads\/&lt;span class=&quot;hljs-number&quot;&gt;2016&lt;\/span&gt;\/&lt;span class=&quot;hljs-number&quot;&gt;06&lt;\/span&gt;\/lcx_vuln.cn_.zip&lt;\/span&gt;<\/code><\/pre>\n<p>\uff082\uff09\u76d1\u542c\u672c\u57301234\u7aef\u53e3\uff0c\u8f6c\u53d1\u7ed9192.168.172.131\u768422\u7aef\u53e3<\/p>\n<pre class=\"code-snippet__js\"><code class=\"hljs yaml\">&lt;span class=&quot;code-snippet_outer&quot;&gt;&lt;span class=&quot;hljs-string&quot;&gt;.\/portmap&lt;\/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;-m&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;\/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;-p1&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1234&lt;\/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;-h2&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;192.168&lt;\/span&gt;\n&lt;span class=&quot;hljs-number&quot;&gt;.172&lt;\/span&gt;\n&lt;span class=&quot;hljs-number&quot;&gt;.131&lt;\/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;-p2&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;22&lt;\/span&gt;&lt;\/span&gt;<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u672c\u673a\u7aef\u53e3\u8f6c\u53d1\uff1a \u4ee3\u7801\u5982\u4e0b\uff1a iptables -t nat -A PREROUTING -p tcp &#8211;dport 80 -j REDIRECT &#8211;to-ports 8080 &#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-755","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=755"}],"version-history":[{"count":8,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/755\/revisions"}],"predecessor-version":[{"id":2270,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/755\/revisions\/2270"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=755"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}