{"id":4609,"date":"2016-09-27T20:25:41","date_gmt":"2016-09-27T12:25:41","guid":{"rendered":"https:\/\/www.icocean.com\/blog\/?p=4609"},"modified":"2016-09-27T20:26:16","modified_gmt":"2016-09-27T12:26:16","slug":"h2byte%ef%bc%9a%e9%82%a3%e4%ba%9b%e4%bb%8e%e5%a2%99%e4%b8%8a%e5%ad%a6%e4%bc%9a%e7%9a%84%e7%9f%a5%e8%af%86","status":"publish","type":"post","link":"https:\/\/www.icocean.com\/blog\/?p=4609","title":{"rendered":"h2byte\uff1a\u90a3\u4e9b\u4ece\u5899\u4e0a\u5b66\u4f1a\u7684\u77e5\u8bc6"},"content":{"rendered":"<div class=\"toc\">\n<ul>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_0\">\u90a3\u4e9b\u4ece\u5899\u4e0a\u5b66\u4f1a\u7684\u77e5\u8bc6<\/a>\n<ul>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_1\">\u5e8f.\u62d3\u6251\u56fe<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_2\">\u58f9.Shadowsocks\u600e\u4e48\u7a7f\u5899\u7684<\/a>\n<ul>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_3\">\u7aef\u53e3\u8f6c\u53d1<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_4\">\u6570\u636e\u4f20\u9001<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_5\">\u9a8c\u8bc1<\/a>\n<ul>\n<li>\n<ul>\n<li>\n<ul>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_6\">\u573a\u666f\uff1a<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_7\">\u6dfb\u52a0\u89c4\u5219<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_8\">\u89c2\u5bdf<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_9\">\u8d30.\u8f6c\u53d1\u5927\u91cf\u7684Evil-IP<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_10\">\u53c1.\u5982\u4f55\u5f97\u5230Evil-IP<\/a>\n<ul>\n<li>\n<ul>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_11\">dnsmasq-full<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_12\">\u8086.\u89e3\u51b3DNS\u6295\u6bd2<\/a>\n<ul>\n<li>\n<ul>\n<li>\n<ul>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_13\">\u4e00\u662f\u4ece\u6bd2\u9505\u91cc\u76db\u7ca5\uff0c\u628a\u6709\u6bd2\u7684\u7c73\u6311\u51fa\u6765\u6254\u6389<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_14\">\u4e8c\u662f\u4ece\u5b89\u5168\u7684\u9505\u91cc\u76db\u7ca5\uff0c\u653e\u5fc3\u5403<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_15\">&gt; \u7528ss-redir\u8f6c\u53d1UDP DNS\u67e5\u8be2<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_16\">&gt; \u7528ss-tunnel\u8f6c\u53d1UDP DNS\u67e5\u8be2<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_17\">&gt; iptables + tproxy\u8f6c\u53d1UDP DNS\u67e5\u8be2<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_18\">&gt; \u7528unbound\u505aTCP DNS\u67e5\u8be2<\/a><\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_19\">&gt; \u7528pdnsd\u505aTCP DNS\u67e5\u8be2<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"http:\/\/h2byte.com\/post\/tech\/learn-from-gfw#toc_20\">\u4f0d.\u672b<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n<p><!--more--><\/p>\n<div class=\"post_body\">\n<h1 id=\"toc_0\">\u90a3\u4e9b\u4ece\u5899\u4e0a\u5b66\u4f1a\u7684\u77e5\u8bc6<\/h1>\n<blockquote><p>\u4e0d\u597d\u597d\u5b66\u4e60\u8ba1\u7b97\u673a\u7f51\u7edc\uff0c\u5c31\u4f1a\u88ab\u56fd\u5bb6\u6559\u80b2\u3002<\/p><\/blockquote>\n<h2 id=\"toc_1\">\u5e8f.\u62d3\u6251\u56fe<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/www.icocean.com\/blog\/wp-content\/uploads\/auto_save_image\/2016\/09\/122611Ze1.jpg\" alt=\"topological\" \/><\/p>\n<h2 id=\"toc_2\">\u58f9.Shadowsocks\u600e\u4e48\u7a7f\u5899\u7684<\/h2>\n<h3 id=\"toc_3\">\u7aef\u53e3\u8f6c\u53d1<\/h3>\n<p>\u9996\u5148\uff0c\u628aSS\u90e8\u7f72\u5728\u8def\u7531\u5668\u4e0a\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u662f\u76d1\u542c1080\u7aef\u53e3\u7684\uff0c\u6240\u6709\u7ecf\u8fc7\u8fd9\u4e2a\u7aef\u53e3\u7684\u6570\u636e\u5305\u90fd\u7531SS\u8f6c\u53d1\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u3002OpenWrt\u4e0a\u7684Shadowsocks-libev\u81ea\u5e26\u67093\u4e2a\u7a0b\u5e8f\uff0c\u5206\u522b\u662fss-local, ss-redir \u548css-tunnel\u3002\u8fd9\u91cc\u7531ss-redir\u8f6c\u53d1\u6570\u636e\u5230\u670d\u52a1\u5668\u3002<br \/>\n\u5728\u672a\u505a\u914d\u7f6e\u7684\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u7684\u6570\u636e\u90fd\u662f\u76f4\u63a5\u6709\u8def\u7531\u5668\u76f4\u63a5\u53d1\u51fa\u53bb\u7684\u3002\u600e\u4e48\u624d\u80fd\u8ba9\u6570\u636e\u5305\u591a\u8d70\u4e00\u6b65\uff0c\u5148\u53d1\u9001\u52301080\u7aef\u53e3\u8ba9ss-redir\u8fdb\u884c\u518d\u52a0\u5de5\u5462\uff1f\u8fd9\u4e2a\u53ef\u4ee5\u7528linux\u5185\u6838\u5185\u7684netfilter\u6846\u67b6\u5bf9\u8fdb\u5165\u7cfb\u7edf\u7684\u6570\u636e\u5305\u8fdb\u884c\u7b5b\u9009\u7136\u540e\u7aef\u53e3\u8f6c\u53d1\u3002netfilter\u5728\u8fdb\u884c\u7aef\u53e3\u8f6c\u53d1\u7684\u65f6\u5019\uff0c\u8fd8\u4f1a\u81ea\u52a8\u7ef4\u62a4\u4e00\u4e9b\u5fc5\u8981\u7684\u4fe1\u606f\uff0c\u4ee5\u4fbf\u505a\u4e00\u4e2a\u56de\u7a0b\u7684\u9006\u5904\u7406\uff1a\u5c06\u670d\u52a1\u5668\u8fd4\u56de\u7684\u6570\u636e\u8f6c\u56de\u539f\u59cb\u7684\u7aef\u53e3\u3002netfilter\u7684\u914d\u7f6e\u5de5\u5177\u662fiptables, \u9e1f\u54e5\u90a3\u6709\u4e00\u4e9b\u5f88\u597d\u7684<a href=\"http:\/\/linux.vbird.org\/linux_server\/0250simple_firewall.php#netfilter\">\u8d44\u6599<\/a>\uff0c\u4e5f\u53ef\u770b\u770b\u8fd9\u7bc7<a href=\"https:\/\/blog.coocla.org\/207.html\">blog<\/a>\u3002<\/p>\n<h3 id=\"toc_4\">\u6570\u636e\u4f20\u9001<\/h3>\n<p>ss-redir\u4ece1080\u7aef\u53e3\u83b7\u53d6\u539f\u59cb\u6570\u636e\u5305\u4e4b\u540e, \u6839\u636e\u9009\u62e9\u7684\u52a0\u5bc6\u65b9\u5f0f\u5bf9\u539f\u59cb\u6570\u636e\u5305\u8fdb\u884c\u52a0\u5de5\uff0c\u76ee\u7684\u662f\u8ba9\u5899\u65e0\u6cd5\u8f7b\u6613\u63a2\u77e5\u6570\u636e\u5305\u7684\u5185\u5bb9\u4ece\u800c\u9003\u8fc7\u88ab\u5bb0\u6740\u7684\u547d\u8fd0\u3002VPS\u4e0a\u8fd0\u884c\u7684ss-server\u63a5\u53d7\u5230\u6570\u636e\u540e\uff0c\u6839\u636e\u7ea6\u5b9a\u7684\u52a0\u5bc6\u65b9\u5f0f\u8fd8\u539f\u6570\u636e\uff0c\u5e76\u53d1\u5230\u5b83\u7684\u771f\u5b9e\u76ee\u7684\u5730\u3002<br \/>\n\u8fd4\u7a0b\u4e5f\u662f\u7c7b\u4f3c\u7684\u8fc7\u7a0b\u3002<\/p>\n<h3 id=\"toc_5\">\u9a8c\u8bc1<\/h3>\n<h6 id=\"toc_6\">\u573a\u666f\uff1a<\/h6>\n<p>\u5047\u8bbeGFW\u7684\u9ed1\u540d\u5355\u4e2d\u6709\u4e00\u6761IP\u5730\u5740: 206.125.164.82, \u4e3a\u4e86\u8868\u8ff0\u65b9\u4fbf\uff0c\u59d1\u4e14\u7ed9\u5b83\u4e2a\u4ee3\u53f7\u53ebEvil-IP\u3002\u6240\u6709\u7ecf\u8fc7GFW\u7684\u6570\u636e\u5305\uff0c\u5982\u679c\u76ee\u7684\u5730\u5740\u662f\u8fd9Evil-IP\uff0c\u5c31\u4f1a\u88ab\u65e0\u60c5\u4e22\u5f03\u3002<\/p>\n<p>\u6211\u4eec\u901a\u8fc7telnet\u53d1\u8d77TCP\u8bf7\u6c42\uff0c\u751f\u6210\u53d1\u5f80Evil-IP\u7684\u6570\u636e\u5305:<\/p>\n<p><code>telnet 206.125.164.82 80<\/code><\/p>\n<p>\u5982\u679c\u94fe\u63a5\u6210\u529f\u4e86\uff0c\u8bf7\u5047\u88c5\u6ca1\u6709\u770b\u5230\u3002\u6bd5\u7adf\u6211\u4eec\u5047\u8bbe\u5b83\u88ab\u5899\u4e86\u561b\u3002<\/p>\n<h6 id=\"toc_7\">\u6dfb\u52a0\u89c4\u5219<\/h6>\n<p>\u9996\u5148\u5c06\u8def\u7531\u5668\u9632\u706b\u5899\u7684\u5f53\u524d\u89c4\u5219\u4fdd\u5b58:<\/p>\n<p><code>iptables-save &gt; iptables.rules<\/code><\/p>\n<p>\u5982\u679c\u56e0\u4e3a\u89c4\u5219\u6df7\u4e71\u65e0\u6cd5\u4e0a\u7f51\u4e86\u53ef\u4ee5\u901a\u8fc7<\/p>\n<p><code>iptables-restore &lt; iptables.rules<\/code><\/p>\n<p>\u76f4\u63a5\u6062\u590d\u800c\u65e0\u9700\u91cd\u542f\u8def\u7531\u5668\u3002<\/p>\n<p>\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u89c4\u5219\uff0c\u5c06\u6211\u4eec\u7684\u6570\u636e\u5305\u8f6c\u53d1\u5230ss-redir\u76d1\u542c\u7684\u7aef\u53e3\u4e0a:<\/p>\n<p><code>iptables -t nat -A PREROUTING -d 206.125.164.82 -p tcp --dport 80 -j REDIRECT --to-port 1080<\/code><\/p>\n<p>-t nat\u8868\u793a\u8fd9\u6761\u89c4\u5219\u6dfb\u52a0\u5230nat\u8868\uff0c\u56e0\u4e3a\u7aef\u53e3\u8f6c\u53d1\u53ea\u80fd\u5728nat\u8868\u4e0a\uff0c\u6240\u4ee5\u8fd9\u91cc\u662f\u4e0d\u80fd\u7528\u9ed8\u8ba4\u7684filter\u8868\u7684\u3002-A PREROUTING\u8868\u660e\u5c06\u8fd9\u6761\u89c4\u5219\u6dfb\u52a0\u5230PREROUTING\u8fd9\u6761\u89c4\u5219\u94fe\u7684\u6700\u540e\u3002-j REDIRECT\u662f\u8bf4\u7b26\u5408\u6761\u4ef6\u7684\u6570\u636e\u5305\u90fdjump\u5230REDIRECT\u8fd9\u4e2a\u76ee\u6807\uff0c\u540e\u9762\u7684\u6269\u5c55\u53c2\u6570&#8211;to-port\u6307\u660e\u4e86\u8df3\u8f6c\u5230\u7684\u7aef\u53e3\u53f7\u3002<\/p>\n<p>\u7528<code>iptables -t nat --list<\/code>\u6216\u8005<code>iptables -t nat -L<\/code>\u547d\u4ee4\u770b\u770b\u8f93\u51fa\uff0c\u770b\u5230Chain PREROUTING\u4e0a\u5df2\u7ecf\u663e\u793a\u8fd9\u6761\u89c4\u5219\u4e86\uff0c\u6dfb\u52a0\u6210\u529f\u3002<\/p>\n<p>iptables\u7684\u5404\u4e2a\u8868\u7684\u5904\u7406\u987a\u5e8f\uff0c\u53ef\u4ee5\u770b\u8fd9\u5f20\u56fe<img decoding=\"async\" src=\"https:\/\/www.icocean.com\/blog\/wp-content\/uploads\/auto_save_image\/2016\/09\/122614sq0.jpg\" alt=\"iptables-flow\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0cClient\u53d1\u5f80Evil-IP\u7684\u6570\u636e\u88ab\u9632\u706b\u5899\u5904\u7406\u7684\u89c4\u5219\u8def\u5f84\u88ab\u7ea2\u8272\u7bad\u5934\u6807\u793a.<\/p>\n<p>\u800cRouter\u81ea\u8eab\u53d1\u5f80Evil-IP\u7684\u6570\u636e\uff0c\u4f9d\u6b21\u5e94\u7528\u7684Chain\u7528\u84dd\u8272\u6807\u793a\u3002<\/p>\n<p>\u56e0\u6b64\u6211\u4eec\u5c06\u89c4\u5219\u6dfb\u52a0\u5230PREROUTING\u94fe\u53ea\u80fd\u8f6c\u53d1Client\u7684\u6570\u636e\u52301080\uff0c\u5982\u679c\u4f60\u8fd8\u8981\u5728Router\u4e0a\u505a\u7f9e\u7f9e\u7684\u4e8b\uff0c\u8fd8\u8981\u518d\u6dfb\u52a0\u4e00\u6761\u89c4\u5219: <code>iptables -t nat -A OUTPUT -d 206.125.164.82 -p tcp --dport 80 -j REDIRECT --to-port 1080<\/code>\u3002<\/p>\n<p>\u89c2\u5bdf\u5230Client\u7684\u6570\u636e\u548cRouter\u7684\u6570\u636e\u6700\u540e\u90fd\u7ecf\u8fc7nat\u8868\u7684POSTROUTING\u94fe\u624d\u53d1\u51fa\uff0c\u90a3\u4e48\u5c06\u8f6c\u53d1\u89c4\u5219\u6dfb\u52a0\u5230\u8fd9\u4e2a\u94fe\u4e0a\u4e0d\u5c31\u4e07\u4e8b\u5927\u5409\u4e86\u561b\uff1f\u6211\u4eec\u8bd5\u8bd5\uff1a<\/p>\n<p><code>iptables -t nat -A POSTROUTING -d 206.125.164.82 -p tcp -j REDIRECT --to-port 1080<\/code><\/p>\n<p>\u5475\u5475\uff0c\u6dfb\u52a0\u4e0d\u6210\u529f\uff0c\u63d0\u793a\u201cip_tables: REDIRECT target: used from hooks POSTROUTING, but only usable from PREROUTING\/OUTPUT\u201d, \u81f3\u4e8e\u4e3a\u4ec0\u4e48REDIRECT\u4e0d\u80fd\u5e94\u7528\u5728\u8fd9\u4e2a\u94fe\u4e0a\uff0c\u76f4\u89c9\u4e0a\u5e94\u8be5\u662f\u8fd9\u4e2a\u94fe\u53ea\u80fd\u7528\u6765\u505aSNAT\uff0c\u66f4\u4e25\u8c28\u7684\u539f\u56e0\u6211\u5e76\u6ca1\u6709\u53bb\u63a2\u7a76\uff0c\u5982\u679c\u6709\u4eba\u77e5\u9053\u6211\u987a\u4fbf\u77e5\u4f1a\u6211\u4e00\u58f0\u3002<\/p>\n<p><a name=\"more\"><\/a><\/p>\n<h6 id=\"toc_8\">\u89c2\u5bdf<\/h6>\n<p>\u63a5\u4e0b\u6765\u5c31\u8981\u89c2\u5bdf\u6570\u636e\u5305\u662f\u5426\u88ab\u6b63\u786e\u8f6c\u53d1\u4e86\u3002<\/p>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u6293\u53d6\u6570\u636e\u5305\u7684\u6d3b\u4ea4\u7ed9tcpdump\u8fd9\u79cd\u795e\u5668\u6700\u5408\u9002\u4e0d\u8fc7\u4e86\uff0c\u4f46\u662f\u6211\u76d1\u542c1080\u7aef\u53e3\u51e0\u5343\u5e74\uff0c\u90fd\u6ca1\u89c2\u5bdf\u5230\u6709\u6570\u636e\u6d41\u91cf\uff0c\u7ed3\u679c\u81ea\u7136\u662f\u5927\u4e3a\u6cae\u4e27. \u540e\u6765Google\u540e\u624d\u53d1\u73b0\u662f\u6389\u8fdb\u4e86\u7aef\u53e3\u8f6c\u53d1\u7684\u5751\uff0c\u7aef\u53e3\u8f6c\u53d1\u662f\u4e0d\u80fd\u88abtcpdump\u6355\u83b7\u5230\u7684(<a href=\"http:\/\/serverfault.com\/questions\/502003\/tcpdump-not-picking-up-traffic-redirected-by-iptables\">\u539f\u56e0<\/a>). \u800c\u4e14\u7531\u4e8e\u8def\u7531\u5668\u4e0a\u7684ss-redir\u7684Verbose mode\u592a\u5b89\u9759\u4e86\uff0c\u65e0\u6cd5\u89c2\u5bdf\u5230\u4ec0\u4e48\u6709\u7528\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u6211\u60f3\u5230\u7684\u6709\u4e24\u4e2a\u65b9\u6cd5\u6765\u9a8c\u8bc1\u6570\u636e\u662f\u5426\u88ab\u6b63\u786e\u8f6c\u53d1(\u5982\u679c\u6709\u66f4\u597d\u7684\u65b9\u6cd5\u8bf7\u544a\u8bc9\u6211)\uff1a<\/p>\n<pre><code>- \u901a\u8fc7\u670d\u52a1\u5668\u7aef\u7684ss-server\u89c2\u5bdf  \r\n\r\n\u5206\u522b\u5728VPS\u548c\u8def\u7531\u5668\u4e0a\u8fd0\u884css-server\u548css-redir\uff0c\u6ce8\u610f\u6dfb\u52a0-v\u53c2\u6570\u53ef\u4ee5\u770b\u5230\u66f4\u591a\u7684\u8fd0\u884c\u6d88\u606f.  \r\nVPS\uff1a`\/usr\/local\/bin\/ss-server -c \/etc\/shadowsocks\/ching.json -u -v`  \r\nrouter: `\/usr\/bin\/ss-redir -c \/etc\/ching.json -b 0.0.0.0 -v`  \r\n\u5728Client\u6216\u8005Router\u4e0a\u5411Evil-IP\u53d1\u9001\u6570\u636e\uff1a  \r\n`telnet 206.125.164.82 80`  \r\n\u6309\u4e0b\u4f1a\u8f66\u540e\u5e94\u8be5\u5c31\u53ef\u4ee5\u770b\u5230VPS\u8fd0\u884c\u7684ss-server\u7684\u5de5\u4f5c\u72b6\u6001\u53d1\u751f\u4e86\u6539\u53d8\uff0c\u63a5\u53d7\u4e86\u4e00\u4e2a\u8fde\u63a5\u5e76\u5411Evil-IP\u53d1\u9001\u4e86\u6570\u636e\u3002\r\n\r\n- nc\u547d\u4ee4  \r\n\r\n\u5982\u679c\u53ea\u60f3\u9a8c\u8bc1iptables\u8fdb\u884c\u7aef\u53e3\u8f6c\u53d1\u7684\u6548\u679c\uff0c\u800c\u4e0d\u7406\u4f1aShadowsocks\u7684\u8bdd\u3002nc\u547d\u4ee4\u662f\u4e00\u4e2a\u597d\u5de5\u5177\u3002\u5173\u6389Router\u4e0a\u8fd0\u884c\u7684ss-redir\u548cuhttpd\u8fdb\u7a0b\uff0c\u4ee5\u91ca\u653e1080\u7aef\u53e3\u548c80\u7aef\u53e3\u3002openwrt\u81ea\u5e26\u7684nc\u4e0d\u80fd\u76d1\u542c\u7aef\u53e3([\u539f\u56e0][openwrt-nc]), \u9700\u8981\u5b89\u88c5netcat\u6765\u8865\u5145\u8fd9\u4e2a\u529f\u80fd:  \r\n`opkg install netcat`  \r\n\u7136\u540e\u5728\u8def\u7531\u5668\u4e0a\u8fd0\u884c\u4e24\u4e2anc\u5b9e\u4f8b\uff0c\u4e00\u4e2a\u76d1\u542c80\u7aef\u53e3\uff1a  \r\n`nc -l -p 80`  \r\n\u53e6\u5916\u4e00\u4e2a\u76d1\u542c1080:  \r\n`nc -l -p 1080`  \r\n\u6700\u540e\u6211\u4eec\u4eceClient\u5bf9Evil-IP\u768480\u7aef\u53e3\u53d1\u9001\u6570\u636e  \r\n`nc 206.125.164.82 80`  \r\n\u5982\u679c\u662f\u76d1\u542c1080\u7684\u5b9e\u4f8b\u6536\u5230\u4e86\u6570\u636e\uff0c\u8bf4\u660e\u7aef\u53e3\u8f6c\u53d1\u6210\u529f, \u4e8b\u5b9e\u8bc1\u660e\u786e\u5b9e\u8f6c\u53d1\u6210\u529f\u4e86.<\/code><\/pre>\n<h2 id=\"toc_9\">\u8d30.\u8f6c\u53d1\u5927\u91cf\u7684Evil-IP<\/h2>\n<p>\u5982\u679c\u53ea\u6709\u5c11\u6570\u51e0\u4e2aEvil-IP\u7684\u8bdd\uff0c\u4e00\u4e2a\u4e2a\u7528iptables\u6dfb\u52a0\u8f6c\u53d1\u89c4\u5219\u4e5f\u6ca1\u4ec0\u4e48\u95ee\u9898\uff0c\u4f46\u662f\u5982\u679c\u6570\u91cf\u4e00\u591a\uff0c\u51e0\u767e\u51e0\u5343\u6761\u7684IP\uff0c\u5c31\u7b97\u6dfb\u52a0\u5230\u89c4\u5219\u91cc\u4e0d\u662f\u4ec0\u4e48\u5927\u4e8b\uff0c\u4f46\u662f\u6bcf\u4e2a\u6570\u636e\u5305\u8fdb\u51fa\u90fd\u8981\u505a\u90a3\u4e48\u591a\u7684\u68c0\u67e5\u548c\u5339\u914d\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(n)\uff0c\u6548\u7387\u8fd8\u80fd\u8fdb\u4e00\u6b65\u63d0\u9ad8\uff0c\u5229\u7528IPset\u53ef\u4ee5\u5c06\u65f6\u95f4\u590d\u6742\u5ea6\u53d8\u6210O(1)<\/p>\n<ul>\n<li>IP sets\n<p><a href=\"http:\/\/ipset.netfilter.org\/index.html\">IP sets<\/a>\u662f\u5185\u6838\u91cc\u7684\u4e00\u4e2a\u6846\u67b6,\u4e00\u4e2aIP set\u53ef\u4ee5\u5b58\u50a8IP\u3001\u7f51\u7edc\u3001MAC\u5730\u5740\u7b49\u7b49\uff0c\u67e5\u627e\u96c6\u5408\u4e2d\u67d0\u5143\u7d20\u7684\u7684\u901f\u5ea6\u6781\u5feb, \u5229\u7528ipset\u5de5\u5177<br \/>\n\u7ba1\u7406\u3002<br \/>\nipset\u7684\u7684<a href=\"https:\/\/intxt.net\/block-ip-with-ipset\/\">\u4f7f\u7528\u65b9\u6cd5<\/a>\u4e5f\u5f88\u76f4\u767d\uff0c\u76f4\u63a5\u9a8c\u8bc1\u5229\u7528IP sets\u7684\u7ed3\u679c\u5427\u3002<\/li>\n<li>\u9a8c\u8bc1\u7ed3\u679c\n<p>\u5efa\u7acb\u4e00\u4e2a\u5b58\u50a8IP\u7684\u96c6\u5408\uff1aSHADOWSOCKS:<\/p>\n<p><code>ipset -N SHADOWSOCKS hash:ip<\/code><\/p>\n<p>\u5411\u96c6\u5408\u4e2d\u6dfb\u52a0Evil-IPs:<\/p>\n<p><code>ipset add SHADOWSOCKS 206.125.164.82<\/code><\/p>\n<p><code>ipset add SHADOWSOCKS 74.125.200.113<\/code><\/p>\n<p>\u67e5\u770bSHADOWSOCKS\u96c6\u5408\u7684\u5143\u7d20:<\/p>\n<p><code>ipset list SHADOWSOCKS<\/code><\/p>\n<p>\u8fd8\u539f\u521d\u59cbiptables:<\/p>\n<p><code>iptables-restore &lt; iptables.rules<\/code><\/p>\n<p>\u6dfb\u52a0\u9488\u5bf9IP sets\u8fdb\u884c\u5339\u914d\u7684\u89c4\u5219\uff1a<\/p>\n<p><code>iptables -t nat -A OUTPUT -p tcp -m set --match-set SHADOWSOCKS dst -j REDIRECT --to-port 1080<\/code><\/p>\n<p><code>iptables -t nat -A PREROUTING -p tcp -m set --match-set SHADOWSOCKS dst -j REDIRECT --to-port 1080<\/code><\/p>\n<p>\u6700\u540e\u6309\u4e0a\u4e00\u8282\u7684\u65b9\u6cd5\u8fdb\u884c\u9a8c\u8bc1, \u53ef\u4ee5\u89c2\u5bdf\u5230\u5df2\u7ecf\u6210\u529f\u901a\u8fc7ss-redir\u8bbf\u95ee\u8fd9\u4e24\u4e2aEvil-IP\u3002<\/li>\n<\/ul>\n<h2 id=\"toc_10\">\u53c1.\u5982\u4f55\u5f97\u5230Evil-IP<\/h2>\n<p>\u6d4f\u89c8\u7f51\u7edc\u8fc7\u7a0b\u4e2d\uff0c\u6bd4\u8f83\u7528\u57df\u540d\u800c\u8a00\uff0c\u5229\u7528IP\u4e0a\u7f51\u8fd8\u662f\u592a\u539f\u59cb\u4e86\uff0c\u800c\u4e14\u57df\u540d\u662f\u56fa\u5b9a\u7684\uff0c\u800c\u57df\u540d\u5bf9\u5e94\u7684IP\u5730\u5740\u5374\u662f\u53ef\u4ee5\u52a8\u6001\u53d8\u5316\uff0c\u5982\u679c\u80fd\u5f97\u5230\u52a8\u6001\u53d8\u5316\u7684Evil-IPs\u90a3\u5c31\u597d\u4e86\u3002\u7531\u4e8eiptables\u5de5\u4f5c\u5728\u7f51\u7edc\u534f\u8bae\u7b2c\u4e09\u5c42\u548c\u7b2c\u4e8c\u5c42\uff0c\u8bc6\u522bIP\u8bc6\u522bMAC\uff0c\u4f46\u662f\u5bf9\u9ad8\u5c42\u7684\u57df\u540d\u662f\u65e0\u5bdf\u89c9\u7684\uff0c\u6240\u4ee5\u65e0\u6cd5\u7528iptables\u6765\u5339\u914dEvil-Domain\uff0c\u53ea\u80fd\u5148\u627e\u5230Evil-Domain\u5bf9\u5e94\u7684Evil-IP\uff0c\u5c06\u8fd9\u4e9bIP\u52a0\u5165IP set\uff0c\u6700\u540e\u624d\u8ba9iptables\u4e0a\u573a\u5de5\u4f5c\u3002<\/p>\n<h4 id=\"toc_11\">dnsmasq-full<\/h4>\n<p>dnsmasq\u662f\u8f7b\u91cf\u7684DHCP\u548cDNS\u7f13\u5b58\u670d\u52a1\uff0c\u5b83\u6709\u4e2a&#8211;ipset\u9009\u9879\uff0c\u53ef\u4ee5\u5c06\u6307\u5b9a\u57df\u540d\u67e5\u8be2\u5230\u7684IP\u5730\u5740\u52a0\u5165\u6307\u5b9a\u7684ip set\u3002\u4f46\u662fOpenWrt\u81ea\u5e26\u7684\u7248\u672c\u4e0d\u652f\u6301ipset\u9009\u9879\uff0c\u9700\u8981\u5b89\u88c5dnsmasq-full:<\/p>\n<p><code>opkg remove dnsmasq<\/code><\/p>\n<p><code>opkg install dnsmasq<\/code><\/p>\n<p><code>\/etc\/init.d\/dnsmasq restart<\/code><\/p>\n<p>\u9a8c\u8bc1\u7248\u672c\uff0cipset\u5b57\u6837\u8868\u660e\u652f\u6301ipset:<\/p>\n<p><code>dnsmasq -v<\/code><\/p>\n<blockquote><p>Dnsmasq version 2.73 Copyright (c) 2000-2015 Simon Kelley<\/p>\n<p>Compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth DNSSEC loop-detect inotify<\/p><\/blockquote>\n<p>\u4ee5\u4e0b\u7b2c\u4e00\u6761\u53c2\u6570\u4e3aEvil-Domain\u6307\u5b9aDNS\u670d\u52a1\u5668\uff0c\u8fd9\u91cc\u8981\u6ce8\u610f\u5373\u4f7f\u662f\u5229\u7528dnsmasq\u672c\u8eab\u53d1\u8d77\u67e5\u8be2\uff0c\u4e5f\u9700\u8981\u660e\u786e\u8bf4\u660e\uff0c\u4e0d\u7136\u662f\u65e0\u6cd5\u89e3\u6790Evil-Domain\u7684\u3002\u7b2c\u4e8c\u6761\u53c2\u6570\u5c06\u89e3\u6790\u7ed3\u679c\u52a0\u5165\u4e4b\u524d\u5efa\u7acb\u7684SHADOWSOCKS ip set<\/p>\n<p><code>echo \u201cserver=\/h2byte.com\/127.0.0.1#53\u201d &gt;&gt; \/etc\/dnsmasq.conf<\/code><\/p>\n<p><code>echo \u201cipset=\/h2byte.com\/SHADOWSOCKS\u201d &gt;&gt; \/etc\/dnsmasq.conf<\/code><\/p>\n<p>\u53d1\u8d77DNS\u67e5\u8be2\u540e\uff0c\u89c2\u5bdfSHADOWSOCKS set\u7684\u53d8\u5316\uff0c\u53ef\u4ee5\u770b\u5230\u96c6\u5408\u91cc\u5df2\u7ecf\u591a\u4e86\u4e00\u6761\u8bb0\u5f55\uff0c\u90a3\u5c31\u662f\u67e5\u8be2\u5230\u7684h2byte.com\u7684IP\uff1a<\/p>\n<p><code>nslookup h2byte.com<\/code><\/p>\n<p><code>ipset list SHADOWSOCKS<\/code><\/p>\n<p>\u76f4\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u90fd\u662f\u5047\u8bbeDNS\u4e00\u76f4\u80fd\u8fd4\u56de\u6b63\u786e\u7684\u5730\u5740\u3002\u4f46\u662f\u4e8b\u5b9e\u5f80\u5f80\u4e0d\u5c3d\u5982\u4eba\u610f\uff0c\u7531\u4e8e<a href=\"http:\/\/www.williamlong.info\/archives\/3356.html\">DNS\u6295\u6bd2<\/a>\u7684\u5b58\u5728\uff0c\u5728\u8bbf\u95eeEvil-Domain\u65f6\uff0c\u6211\u4eec\u4f1a\u88ab\u865a\u5047\u7684DNS\u54cd\u5e94\u5e26\u5230\u5751\u91cc\u53bb\u3002<\/p>\n<p>\u5f53\u4f60\u89c9\u5f97\u81ea\u5df1\u5b66\u5f97\u591f\u591a\u4e86\u7684\u65f6\u5019\uff0c\u5899\u603b\u4f1a\u8df3\u51fa\u6765\u7ed9\u4f60\u4e00\u5df4\u638c\uff0c\u5475\u5475\u54d2\u3002<\/p>\n<h2 id=\"toc_12\">\u8086.\u89e3\u51b3DNS\u6295\u6bd2<\/h2>\n<p>\u8981\u60f3\u4e0d\u88ab\u6bd2\u7ca5\u6bd2\u6b7b\uff0c\u6709\u4e24\u4e2a\u601d\u8def:<\/p>\n<h5 id=\"toc_13\">\u4e00\u662f\u4ece\u6bd2\u9505\u91cc\u76db\u7ca5\uff0c\u628a\u6709\u6bd2\u7684\u7c73\u6311\u51fa\u6765\u6254\u6389<\/h5>\n<p>\u5982\u679c\u6bd2\u7c73\u7684\u7279\u5f81\u5f88\u660e\u663e\uff0c\u7528\u8fd9\u79cd\u65b9\u6cd5\u4e5f\u672a\u5c1d\u4e0d\u53ef\u3002\u4ee5\u524d\u4f2aDNS\u54cd\u5e94\u603b\u662f\u8fd4\u56de\u56fa\u5b9a\u7684\u82e5\u5e72\u4e2a\u5047IP\uff0c\u5229\u7528iptables\u5339\u914d53\u7aef\u53e3\u7684udp\u6570\u636e\uff0c\u518d\u7528iptable\u7684u32\u6a21\u5757\u6216\u8005string\u6a21\u5757\u627e\u5230\u6570\u636e\u5305\u643a\u5e26\u7684IP\u5730\u5740\uff0c\u8ddf\u6211\u4eec\u6536\u96c6\u5230\u7684\u4f2aIP\u96c6\u5408\u5bf9\u6bd4\uff0c\u53d1\u73b0\u662f\u6709\u6bd2\u7684\u5c31\u6254\u6389\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u53ef\u60dc\u5899\u4e3a\u4e86\u7763\u4fc3\u6211\u4eec\u5b66\u4e60\uff0c\u8fd4\u56de\u7684IP\u5730\u5740\u5df2\u7ecf\u662f\u968f\u673a\u7684\u4e86\u3002\u4ece\u6bd2\u7ca5\u91cc\u76db\u7ca5\u559d\uff0c\u65e2\u5371\u9669\u53c8\u4e0d\u4f18\u96c5\uff0c\u4e0d\u8fc7\u770b\u770b\u5148\u9a71\u4eec<a href=\"https:\/\/www.lifetyper.com\/2014\/06\/anti-dns-poison-without-vpn.html\">\u600e\u4e48\u505a\u7684<\/a>\u4e5f\u662f\u4e00\u79cd\u81f4\u656c\u3002<\/p>\n<h5 id=\"toc_14\">\u4e8c\u662f\u4ece\u5b89\u5168\u7684\u9505\u91cc\u76db\u7ca5\uff0c\u653e\u5fc3\u5403<\/h5>\n<p>\u56fd\u5916\u7684\u6708\u4eae\u5706\uff0c\u56fd\u5916\u7684\u7ca5\u4e5f\u66f4\u597d\u5403\u3002DNS\u6295\u6bd2\u662f\u6211\u4eec\u5927\u5b8b\u7279\u6709\u7684\u72ec\u95e8\u6697\u5668\uff0c\u56fd\u5916\u7684DNS\u624d\u662f\u5e72\u51c0\u65e0\u6bd2\u7684\u3002\u53ea\u8981\u80fd\u4ece\u56fd\u5916\u7684\u9505\u91cc\u76db\uff0c\u5c31\u80fd\u653e\u5fc3\u5403\u3002\u600e\u4e48\u76db\u7ca5\u5b66\u95ee\u592a\u591a\u4e86\uff0c\u4f46\u5927\u81f4\u53ef\u4ee5\u5206\u4e3a\u4e24\u5927\u7c7b\uff1a\u4e00\u662f\u7528Shadowsocks\u8fdb\u884cudp DNS\u67e5\u8be2\uff0c\u7531\u4e8eShadowsocks\u5bf9DNS\u8bf7\u6c42\u8fdb\u884c\u4e86\u5c01\u88c5\uff0c\u5899\u65e0\u6cd5\u77e5\u9053\u67e5\u8be2\u5185\u5bb9\u6240\u4ee5\u6570\u636e\u5305\u88ab\u653e\u884c\uff1b\u4e8c\u662f\u7528TCP\u8fdb\u884cDNS\u67e5\u8be2\uff0c\u76ee\u524d\u5899\u8fd8\u672a\u5bf9TCP\u67e5\u8be2\u8fdb\u884c\u5e72\u6270\u3002<\/p>\n<p>\u6bcf\u4e2a\u7c7b\u522b\u90fd\u6709\u82e5\u5e72\u79cd\u65b9\u6cd5\uff0c\u4f46\u662f\u53ea\u8981\u5f04\u6e05\u695a\u539f\u7406\uff0c\u54ea\u91cc\u65b9\u6cd5\u90fd\u80fd\u7528\u5f97\u5f97\u5fc3\u5e94\u624b\uff0c\u4ee5\u4e0b\u662f\u51e0\u4e2a\u65b9\u6cd5\u7684\u9a8c\u8bc1\uff1a<\/p>\n<h4 id=\"toc_15\">&gt; \u7528ss-redir\u8f6c\u53d1UDP DNS\u67e5\u8be2<\/h4>\n<p>\u6309\u7167SS\u7684<a href=\"https:\/\/github.com\/shadowsocks\/shadowsocks-libev\"> WiKi <\/a>\uff0c\u8f6c\u53d1UDP\u8be5\u7528ss-tunnel\u6765\u505a\uff0c\u4f46\u662f\u901a\u8fc7<code>\/etc\/bin\/ss-redir -h<\/code>\u67e5\u770bss-redir\u7684\u5e2e\u52a9\uff0c\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a-u\u9009\u9879\u6765\u8ba9SS\u8f6c\u53d1udp\u6570\u636e\uff0c\u59d1\u4e14\u5148\u7528ss-redir\u8bd5\u8bd5\u3002<\/p>\n<p>\u8ba9ss-redir\u652f\u6301udp\u8f6c\u53d1\uff1a<\/p>\n<p><code>\/usr\/bin\/ss-redir -c \/etc\/ching.json -b 0.0.0.0 -u -v<\/code><\/p>\n<p>\u628a\/etc\/dnsmasq.conf\u91cc\u7684server=\/h2byte.com\/127.0.0.1#53\u6539\u6210server=\/h2byte.com\/127.0.0.1#1080\uff0c\u610f\u601d\u662f\u544a\u8bc9dnsmasq\u8ba9Evil-Domain\u7528\u672c\u673a\u76841080\u7aef\u53e3\u67e5\u8be2<\/p>\n<p>\u91cd\u542fdnsmasq\uff0c \u5f53\u6211\u4eec\u7528<code>nslookup h2byte.com<\/code>\u53d1\u8d77DNS\u67e5\u8be2\u65f6\uff0css-redir\u63d0\u793a\u6536\u5230\u4e86udp\u6570\u636e\uff1a<\/p>\n<blockquote><p>2015-12-24 04:21:55 INFO: [udp] server receive a packet<\/p>\n<p>2015-12-24 04:21:55 INFO: [udp] cache miss: 127.0.0.1:1080 &lt;-&gt; 127.0.0.1:17706<\/p>\n<p>2015-12-24 04:56:28 INFO: [udp] server receive a packet<\/p>\n<p>2015-12-24 04:56:28 INFO: [udp] cache miss: 127.0.0.1:1080 &lt;-&gt; 127.0.0.1:14898<\/p><\/blockquote>\n<p>\u670d\u52a1\u5668\u7684ss-server\u4e5f\u6536\u5230\u4e86UDP\u6570\u636e:<\/p>\n<blockquote><p>2015-12-23 23:56:15 INFO: [udp] server receive a packet<\/p>\n<p>2015-12-23 23:56:15 INFO: [udp] cache miss: 127.0.0.1:1080 &lt;-&gt; 60.223.238.62:15850<\/p>\n<p>2015-12-23 23:56:20 INFO: [udp] server receive a packet<\/p>\n<p>2015-12-23 23:56:20 INFO: [udp] cache miss: 127.0.0.1:1080 &lt;-&gt; 60.223.238.62:5488<\/p><\/blockquote>\n<p>\u4ecess-server\u7684\u8f93\u51fa\u53ef\u4ee5\u770b\u5230\uff1aVPS\u76841080\u7aef\u53e3\u5728\u5c1d\u8bd5\u54cd\u5e94DNS\u67e5\u8be2\uff0c\u5e76\u6ca1\u6709\u50cf\u9884\u6599\u7684\u90a3\u6837\u628aDNS\u67e5\u8be2\u5305\u7ee7\u7eed\u5f80\u5916\u53d1\u9001\u3002\u8bf4\u660e\u76f4\u63a5\u914d\u7f6ednsmasq\u7684\u65b9\u6cd5\u597d\u50cf\u4e0d\u592a\u5bf9\u3002\u634b\u4e00\u634b\uff1a<\/p>\n<p>\u5f53\u6211\u4eec\u5728\u8def\u7531\u5668\u4e0a\u53d1\u8d77DNS\u67e5\u8be2h2byte.com\u7684\u65f6\u5019\uff0c\u7531\u4e8ednsmasq\u5b9a\u4e49\u7684DNS\u670d\u52a1\u5668\u662f127.0.0.1#1080\uff0c\u6240\u4ee5upd\u5305\u7684\u76ee\u6807\u5730\u5740\u662f127.0.0.1#1080\uff0c\u63a5\u7740\u8fd9\u4e2a\u5305\u5230\u4e861080\u7aef\u53e3\u88abss-redir\u5c01\u88c5\u53d1\u5230ss-server\uff0css-server\u5f97\u5230\u7684udp\u5305\u7684\u76ee\u6807\u5730\u5740\u4ecd\u7136\u662f127.0.0.1#1080\u3002\u8fd9\u5c31\u89e3\u91ca\u4e86\u4e3a\u5565VPS\u76841080\u5728\u548cRouter\u901a\u4fe1\u3002VPS\u76841080\u7aef\u53e3\u5e76\u6ca1\u6709DNS\u67e5\u8be2\u7684\u670d\u52a1\uff0c\u9e21\u540c\u9e2d\u8bb2\uff0c\u518d\u600e\u4e48\u901a\u4fe1Router\u4e5f\u65e0\u6cd5\u4eceVPS\u90a3\u91cc\u5f97\u5230h2byte.com\u7684IP\u5730\u5740\uff0c\u6700\u540e\u5c31\u8d85\u65f6\u7ed3\u675f\u4e86\u901a\u4fe1\u3002<\/p>\n<p>\u634b\u6e05\u695a\u4e86\u8fd8\u5f97\u89e3\u51b3\u95ee\u9898\uff0c\u57fa\u4e8e\u8fd9\u4e2a\u72b6\u51b5\uff0c\u5e94\u8be5\u67093\u4e2a\u89e3\u51b3\u65b9\u6cd5\u5427\uff1a<\/p>\n<ul>\n<li><strong>\u5728VPS\u76841080\u7aef\u53e3\u7ed1\u5b9a\u4e00\u4e2aDNS\u670d\u52a1\u3002<\/strong>\n<p><code>yum install dnsmasq #\u5b89\u88c5<\/code><\/p>\n<p><code>echo \u201cport=1080\u201d &gt;&gt; \/etc\/dnsmasq #\u914d\u7f6e\u76d1\u542c\u7684\u7aef\u53e3<\/code><\/p>\n<p><code>service dnsmasq start #\u542f\u52a8dnsmasq<\/code><\/p>\n<p><code>dig @127.0.0.1 -p 1080 google.com #\u9a8c\u8bc1dnsmasq\u5df2\u6b63\u786e\u5de5\u4f5c<\/code><\/p>\n<p>\u6700\u540e\u4eceRouter\u53d1\u8d77DNS\u67e5\u8be2Evil-Domain\uff0c\u53d1\u73b0\u5df2\u7ecf\u80fd\u5f97\u5230\u6b63\u786e\u7ed3\u679c\u4e86\u3002<\/li>\n<li><strong>\u5728VPS\u628a127.0.0.1#1080\u91cd\u5b9a\u5411\u52308.8.8.8#53<\/strong>\u3002\n<p>CentOS7 \u9ed8\u8ba4\u7684\u9632\u706b\u5899\u6539\u6210\u4e86FirewallD\uff0c\u4e0d\u518d\u662f\u6211\u521a\u5b66\u7684iptables\u4e86\u3002\u5c31\u4e0d\u505a\u8fd9\u4e2a\u9a8c\u8bc1\u4e86\uff0c\u5e94\u8be5\u662f\u53ef\u4ee5\u5b9e\u73b0\u7684\u3002\u5982\u679c\u60f3\u8bd5\u8bd5\uff0c\u628a\u9632\u706b\u5899\u6362\u56deiptables\u7684\u8bdd\u53ef\u4ee5\u53c2\u8003\u8fd9\u7bc7<a href=\"https:\/\/community.rackspace.com\/products\/f\/25\/t\/4504\"> \u6559\u7a0b <\/a><\/li>\n<li><strong>\u5728Router\u4e0a\u75288.8.8.8#53\u67e5\u8be2Evil-Domain\uff0c\u7136\u540e\u7528iptables\u628a\u53d1\u5f808.8.8.8\u7684\u5305\u91cd\u5b9a\u5411\u5230Router:1080\u3002<\/strong>\n<p>\u5148\u914d\u7f6ednsmasq\u75284\u4e2a8\u67e5\u8be2Evil-Domain: \u628a127.0.0.1#1080\u6539\u4e3a8.8.8.8#53<\/p>\n<p>\u7136\u540e\u518d\u7528iptables\u628a\u53d1\u5f808.8.8.8\u7684\u6570\u636e\u5305\u8f6c\u53d1\u7ed9ss-redir:<\/p>\n<p><code>iptables -t nat -A OUTPUT -p udp --dport 53 -d 8.8.8.8 -j REDIRECT --to-port 1080<\/code><\/p>\n<p>\u7136\u800c\u901a\u8fc7\u89c2\u5bdf\uff0c\u867d\u7136ss-server\u6536\u5230\u4e86udp\u6570\u636e\uff0c\u4f46\u662fudp\u7684\u76ee\u6807\u5730\u5740\u4ecd\u7136\u662f127.0.0.1#1080\u3002\u8fd9\u4e2a\u65b9\u6cd5\u5e76\u4e0d\u594f\u6548\u3002<\/p>\n<p>\u6dfb\u52a0\u4e00\u6761\u89c4\u5219\uff0c\u8bd5\u8bd5\u5982\u679c\u4f7f\u7528TCP\u67e5\u8be2DNS\uff0css-server\u80fd\u4e0d\u80fd\u8fdb\u884c\u6b63\u5e38\u7684DNS\u89e3\u6790:<\/p>\n<p><code>iptables -t nat -A OUTPUT -p tcp --dport 53 -d 8.8.8.8 -j REDIRECT --to-port 1080<\/code><\/p>\n<p>\u518d\u6b21\u901a\u8fc7nslookup\u53d1\u8d77\u67e5\u8be2\uff0c\u7ed3\u679c\u89c2\u5bdf\u5230ss-server\u6536\u5230\u6570\u636e\u540e\u6210\u529f\u54118.8.8.8\u53d1\u9001\u8bf7\u6c42\uff0c\u5e76\u5c06\u54cd\u5e94\u53d1\u56de\u4e86ss-redir\u3002\u89c2\u5bdf\u5230\u7684ss-server\u7684\u5c4f\u663e\u5982\u4e0b\uff1a<\/p>\n<blockquote><p>2015-12-24 02:21:54 INFO: accept a connection<\/p>\n<p>2015-12-24 02:21:54 INFO: connect to: 8.8.8.8:53<\/p><\/blockquote>\n<p>\u4e3a\u4ec0\u4e48ss-server\u6ca1\u80fd\u6309\u7167\u9884\u671f\u5c06udp\u7684\u67e5\u8be2\u6b63\u786e\u89e3\u5305\u5462\uff1f\u6216\u8bb8\u662fss-redir\u5c01\u5305\u7684\u65f6\u5019\u5c31\u6ca1\u80fd\u628a\u771f\u5b9e\u7684\u76ee\u6807\u5730\u5740\u5305\u8fdb\u53bb\u5427\uff1f\u8fd9\u4e2a\u8981\u5f04\u6e05\u695a\u611f\u89c9\u8981\u597d\u597d\u770b\u7f51\u7edc\u534f\u8bae\u4e86\uff0c\u6682\u4e14\u6316\u4e2a\u5751\u5427\uff0c\u6709\u4eba\u77e5\u9053\u4e5f\u8bf7\u7559\u8a00\u544a\u8bc9\u6211\u3002<\/li>\n<\/ul>\n<h4 id=\"toc_16\">&gt; \u7528ss-tunnel\u8f6c\u53d1UDP DNS\u67e5\u8be2<\/h4>\n<p>ss-tunnel\u53ef\u4ee5\u8f6c\u53d1udp\uff0c\u800c\u4e14\u51e0\u4e4e\u4e0d\u9700\u8981\u505a\u4ec0\u4e48\u914d\u7f6e\uff0c\u8981\u65b9\u4fbf\u591a\u4e86\u3002\u4f46\u662fss-redir\u5bf9\u4e86\u89e3\u539f\u7406\u66f4\u6709\u5e2e\u52a9\uff0c\u6240\u4ee5\u5148\u8bf4\u4e86\u66f4\u9ebb\u70e6\u7684ss-redir\u3002\u8fd0\u884css-tunnel<\/p>\n<p><code>\/usr\/bin\/ss-tunnel -c \/etc\/ching.json -b 0.0.0.0 -l 5353 -L 8.8.8.8:53 -u -v<\/code><\/p>\n<p>\u627e\u5230dnsmasq.conf\u91cc\u7684127.0.0.1#1080\uff0c\u628a\u7aef\u53e3\u53f7\u6539\u62105353<\/p>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u6ca1\u4ec0\u4e48\u597d\u8bf4\u7684\uff0c\u61d2\u5f97\u6298\u817e\u5176\u5b83\u65b9\u6cd5\u7684\u8bdd\u7528ss-tunnel\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u6211\u5728\u957f\u57ce\u5bbd\u5e26\u8fd9\u4e2a\u6e23\u7f51\u7edc\u4e0b\uff0cudp\u4e22\u5305\u5f02\u5e38\u5730\u9ad8\uff0c\u6d4f\u89c8\u5668\u7ecf\u5e38\u5361\u5728&#8221;Resoving host&#8230;&#8221;\u7684\u72b6\u6001\uff0c\u5f97\u4e0d\u5230\u89e3\u6790\u7ed3\u679c\u7f51\u9875\u90fd\u6253\u4e0d\u5f00\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.icocean.com\/blog\/wp-content\/uploads\/auto_save_image\/2016\/09\/122616UfQ.png\" alt=\"dns-fail\" \/><\/p>\n<p>\u8fd9\u79cd\u60c5\u51b5\u4e0b\u8981\u505a\u4e00\u70b9\u4f18\u5316\uff0c\u53ef\u4ee5\u770b\u6587\u7ae0\u7ed3\u5c3e\u5904\u6211\u7684\u8bbe\u7f6e\u3002<\/p>\n<h4 id=\"toc_17\">&gt; iptables + tproxy\u8f6c\u53d1UDP DNS\u67e5\u8be2<\/h4>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u6211\u6ca1\u770b\u660e\u767d\uff0c\u6240\u4ee5\u5c31\u6ca1\u6253\u7b97\u8bd5\u4e86\u3002\u4e0d\u61c2\u539f\u7406\u51fa\u4e86\u95ee\u9898\u7b80\u76f4\u5c31\u50cf\u50bb\u903c\u4f3c\u7684, \u6839\u672c\u5c31\u6ca1\u6cd5\u89e3\u51b3\u3002<br \/>\n<a href=\"https:\/\/github.com\/shadowsocks\/shadowsocks-libev\">Shadowsocks-libev\u5b98\u7f51<\/a><\/p>\n<h4 id=\"toc_18\">&gt; \u7528unbound\u505aTCP DNS\u67e5\u8be2<\/h4>\n<p>\u6839\u636e\u7f51\u4e0a\u4e00\u4e9b<a href=\"https:\/\/cokebar.info\/archives\/246\">\u535a\u5ba2<\/a>\u7684\u8bb0\u5f55\uff0cunbound\u7684\u5ef6\u65f6\u597d\u50cf\u5f88\u957f\u3002<\/p>\n<h4 id=\"toc_19\">&gt; \u7528pdnsd\u505aTCP DNS\u67e5\u8be2<\/h4>\n<p>\u4f18\u70b9\u662f\u53ef\u4ee5\u8bbe\u7f6e\u8d85\u957f\u7684DNS TTL\u3002<br \/>\n<a href=\"http:\/\/members.home.nl\/p.a.rombouts\/pdnsd\/doc.html\">pdnsd\u5b98\u7f51<\/a><\/p>\n<p><a href=\"https:\/\/cokebar.info\/archives\/1053\">\u6559\u7a0b<\/a><\/p>\n<p><a href=\"https:\/\/wido.me\/sunteya\/use-openwrt-resolve-gfw-dns-spoofing\">\u6559\u7a0b<\/a><\/p>\n<h2 id=\"toc_20\">\u4f0d.\u672b<\/h2>\n<p>\u76ee\u524d\u6211\u6682\u65f6\u4f7f\u7528\u7684\u65b9\u6848\u662f\u8ba9dnsmasq\u628aEvil-Domain\u53d1\u5230ss-redir\uff0c\u8ba9ss\u8f6c\u53d1UDP DNS\u67e5\u8be2\uff0c\u6682\u65f6\u6ca1\u6709\u5f15\u7528ss-tunnel\u3001unbound\u6216\u8005pdnsd\u5904\u7406DNS\u6295\u6bd2\u3002\u5f15\u8fdb\u8d8a\u591a\u7684\u7a0b\u5e8f\uff0c\u51fa\u4e86\u95ee\u9898Debug\u5c31\u8d8a\u9ebb\u70e6\uff0c\u6700\u7b80\u5355\u7684\u5c31\u662f\u6700\u672c\u8d28\u7684\u3002<\/p>\n<p>\u5982\u679c\u60f3\u4f18\u5316\u4ee5\u4e0b\u7f51\u7edc\u8bbf\u95ee\u901f\u5ea6\uff0c\u8fd8\u8981\u4e86\u89e3<a href=\"http:\/\/www.xiaoxiaozi.com\/2013\/04\/23\/2409\/\">TTL<\/a>\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cdnsmasq\u7684ttl\u662f\u7ee7\u627f\u81ea\u4e0a\u6e38DNS\u670d\u52a1\u5668\u7684\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.icocean.com\/blog\/wp-content\/uploads\/auto_save_image\/2016\/09\/122616rCC.png\" alt=\"dig300\" \/><\/p>\n<p>\u901a\u8fc7dig\u53ef\u4ee5\u770b\u5230google.com\u7684ttl\u662f300\uff0c\u4e5f\u5c31\u662f5\u5206\u949f\u4e4b\u5185\u5982\u679c\u91cd\u590d\u67e5\u8be2google.com\u7684IP\u5730\u5740\uff0cdnsmasq\u4e0d\u4f1a\u5411\u4e0a\u6e38\u670d\u52a1\u5668\u9012\u4ea4\u67e5\u8be2\uff0c\u800c\u662f\u76f4\u63a5\u4ece\u7f13\u5b58\u62ff\u8001\u7684\u503c\u7ed9\u4f60\u3002<br \/>\n\u6700\u65b0\u7684dnsmasq v2.73\u7248\u672c\u6dfb\u52a0\u4e86\u4e00\u4e2a&#8211;min-cache-ttl\u9009\u9879, \u53ef\u4ee5\u81ea\u5b9a\u4e49ttl\u7684\u503c\uff0c\u6839\u636e\u4f5c\u8005\u7684<a href=\"http:\/\/lists.thekelleys.org.uk\/pipermail\/dnsmasq-discuss\/2015q2\/009644.html\">\u8bf4\u660e<\/a>\uff0c\u6700\u957f\u4e5f\u4ec5\u80fd\u8bbe\u7f6e\u4e3a\u4e00\u4e2a\u5c0f\u65f6\u3002\u6709\u7684\u7f51\u7ad9\u51e0\u5341\u5e74\u4e0d\u6362IP\uff0c\u800c\u6709\u7684\u7f51\u7ad9IP\u7684\u8c03\u6574\u5f88\u9891\u7e41\uff0cTTL\u8bbe\u7f6e\u591a\u957f\u4e5f\u662f\u4ec1\u8005\u89c1\u4ec1\u667a\u8005\u89c1\u667a\u7684\u95ee\u9898\u3002\u5982\u679c\u4f60\u4e0d\u60f3\u82b1\u65f6\u95f4\u5728\u57df\u540d\u67e5\u8be2\u4e0a\uff0c\u51fa\u4e86\u95ee\u9898\u5b81\u613f\u91cd\u542fdnsmasq\uff0c\u90a3\u4e48TTL\u53ef\u4ee5\u8bbe\u7f6e\u957f\u4e00\u70b9\u3002\u6211\u6682\u65f6\u5148\u8bbe\u7f6e\u4e3a\u6700\u957f\u7684\u4e00\u4e2a\u5c0f\u65f6(min-cache-ttl=3600).<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.icocean.com\/blog\/wp-content\/uploads\/auto_save_image\/2016\/09\/122616Yo0.png\" alt=\"dig3600\" \/><\/p>\n<p>\u8fdb\u4e00\u6b65\u4f18\u5316\u7684\u8bdd\uff0c\u4ee5\u4e0b\u8fd9\u4e9b\u9009\u9879\u503c\u5f97\u5199\u8fdbdnsmasq.conf\uff1a<\/p>\n<ul>\n<li>cache-size=65536 #\u8bbe\u7f6e\u7f13\u5b58\u5927\u5c0f<\/li>\n<li>log-queries #\u8bb0\u5f55DNS\u67e5\u8be2\u4e8b\u4ef6\uff0c\u5728openwrt\u4e0a\u53ef\u4ee5\u901a\u8fc7logread\u67e5\u770b\u65e5\u5fd7\uff0c\u4fbf\u4e8e\u89c2\u5bdf\u5de5\u4f5c\u72b6\u6001<\/li>\n<li>neg-ttl=3600 #\u5982\u679c\u4e0a\u6d41DNS\u670d\u52a1\u5668\u6ca1\u6709\u8fd4\u56deTTL\uff0c\u5219\u7528\u8fd9\u4e2a\u4ee3\u66ff<\/li>\n<li>log-async #\u5982\u679c\u5199\u65e5\u5fd7\u65f6\u88ab\u963b\u585e\uff0c\u5f00\u542f\u8fd9\u4e2a\u9009\u9879\u540e\u53ef\u4ee5\u4fdd\u8bc1dnsmasq\u7684\u5176\u5b83\u529f\u80fd\u6b63\u5e38\u5de5\u4f5c<\/li>\n<li>server=114.114.114.114 #\u6dfb\u52a0114.114.114.114\u4f5c\u4e3a\u5907\u9009\u4e0a\u6d41DNS\u670d\u52a1\u5668<\/li>\n<li>server=119.29.29.29 #\u6dfb\u52a0DNSpod\u4f5c\u4e3a\u5907\u9009\u670d\u52a1\u5668<\/li>\n<li>all-servers #\u5411\u6240\u6709\u4e0a\u6d41\u670d\u52a1\u5668\u53d1\u9001\u67e5\u8be2\uff0c\u5148\u8fd4\u56de\u7684\u7ed3\u679c\u88ab\u91c7\u7528\u3002<\/li>\n<\/ul>\n<p>\u8981\u662f\u8fd8\u662f\u89c9\u5f97DNS\u67e5\u8be2\u6162\uff0c\u5c31\u6362pdnsd\u66ff\u4ee3dnsmasq\uff0c\u90a3\u73a9\u610f\u636e\u8bf4ttl\u8bbe\u4e3a\u4e00\u5468\u90fd\u884c\u3002\u8981\u4e0d\u6298\u817e\u7740\u81ea\u5df1\u7f16\u8bd1dnsmasq\uff0c\u628a\u4e00\u4e2a\u5c0f\u65f6\u7684ttl\u9650\u5236\u7ed9\u53bb\u6389\u3002<\/p>\n<p>min-cache-ttl\u662f\u57282.73\u7248\u672c\u52a0\u5165\u7684\u9009\u9879\uff0c\u53bb\u4f5c\u8005\u5b98\u7f51\u53ef\u4ee5\u6d4f\u89c8\u4ee3\u7801\u4ed3\u5e93\uff0c\u5728<a href=\"http:\/\/thekelleys.org.uk\/gitweb\/?p=dnsmasq.git;a=log;h=refs\/tags\/v2.73\">2.73\u7684\u4ed3\u5e93<\/a>\u641c\u7d22ttl\uff0c\u627e\u5230\u6dfb\u52a0min-cache-ttl\u7684<a href=\"http:\/\/thekelleys.org.uk\/gitweb\/?p=dnsmasq.git;a=commitdiff;h=28de38768e2c7d763b9aa5b7a4d251d5e56bab0b\">\u90a3\u6b21\u63d0\u4ea4<\/a>\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u63d0\u4ea4\u8005\u4fee\u6539\u4e86\u54ea\u4e9b\u4ee3\u7801\u4e86\uff0c3600\u9650\u5236\u5e94\u8be5\u662f\u5728src\/config.h\u91cc\uff1a<\/p>\n<blockquote><p>define TTL_FLOOR_LIMIT 3600 \/* don&#8217;t allow &#8211;min-cache-ttl to raise TTL above this under any circumstances *\/<\/p><\/blockquote>\n<p>\u6211\u505a\u4e86\u4e2a\u8865\u4e01\uff0c\u53ef\u4ee5\u5230<a href=\"https:\/\/github.com\/A-Unique-Pig\/openwrt-dnsmasq\">github<\/a>\u53c2\u8003\u7f16\u8bd1\u8fc7\u7a0b\u6216\u8005\u76f4\u63a5\u4e0b\u8f7d\u7f16\u8bd1\u597d\u7684ipk\u6587\u4ef6\u3002\u6700\u540e\u6211\u628attl\u6539\u6210\u4e86\u4e00\u5929\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.icocean.com\/blog\/wp-content\/uploads\/auto_save_image\/2016\/09\/122616kVa.png\" alt=\"dig1day\" \/><\/p>\n<\/div>\n<div class=\"info clearfix\"><span class=\"date\">2015-12-24<\/span><\/div>\n<p>\u6765\u6e90\uff1ahttp:\/\/h2byte.com\/post\/tech\/learn-from-gfw<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u90a3\u4e9b\u4ece\u5899\u4e0a\u5b66\u4f1a\u7684\u77e5\u8bc6 \u5e8f.\u62d3\u6251\u56fe \u58f9.Shadowsocks\u600e\u4e48\u7a7f\u5899\u7684 \u7aef\u53e3\u8f6c\u53d1 \u6570\u636e\u4f20\u9001 \u9a8c\u8bc1 \u573a\u666f\uff1a \u6dfb\u52a0 <a href='https:\/\/www.icocean.com\/blog\/?p=4609' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","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-4609","post","type-post","status-publish","format-standard","hentry","category-4","category-4-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4609"}],"version-history":[{"count":2,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4609\/revisions"}],"predecessor-version":[{"id":4617,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4609\/revisions\/4617"}],"wp:attachment":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}