﻿{"id":2627,"date":"2024-03-25T13:00:48","date_gmt":"2024-03-25T05:00:48","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=2627"},"modified":"2024-03-25T13:00:48","modified_gmt":"2024-03-25T05:00:48","slug":"iptables-%e8%bd%ac%e5%8f%91%e5%85%a8%e5%b1%80%e6%b5%81%e9%87%8f%e5%88%b0socks5","status":"publish","type":"post","link":"https:\/\/nick.txtcc.com\/index.php\/linux\/2627","title":{"rendered":"iptables \u8f6c\u53d1\u5168\u5c40\u6d41\u91cf\u5230Socks5"},"content":{"rendered":"<p>\u8981\u5c06 iptables \u914d\u7f6e\u4e3a\u5c06\u5168\u5c40\u6d41\u91cf\u8f6c\u53d1\u5230 Socks5\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<ol>\n    <li>\u9996\u5148\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86 iptables \u5de5\u5177\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/li>\n<\/ol>\n<pre class=\"hljs language-routeros\">sudo apt-<span class=\"hljs-built_in\">get<\/span> install iptables<\/pre>\n<ol start=\"2\">\n    <li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 iptables \u89c4\u5219\u96c6\u5e76\u8bbe\u7f6e\u9ed8\u8ba4\u52a8\u4f5c\u4e3a ACCEPT\uff08\u63a5\u53d7\uff09\u6240\u6709\u4f20\u5165\u8fde\u63a5\uff1a<\/li>\n<\/ol>\n<pre class=\"hljs language-css\">sudo iptables -F <span class=\"hljs-selector-tag\">INPUT<\/span>\nsudo iptables -<span class=\"hljs-selector-tag\">P<\/span> <span class=\"hljs-selector-tag\">INPUT<\/span> ACCEPT<\/pre>\n<ol start=\"3\">\n    <li>\u6dfb\u52a0\u4e00\u6761\u89c4\u5219\uff0c\u5c06\u6240\u6709\u4f20\u5165\u8fde\u63a5\u91cd\u5b9a\u5411\u5230\u672c\u5730\u7684 Socks5 \u670d\u52a1\u5668\u4e0a\uff1a<\/li>\n<\/ol>\n<pre class=\"hljs language-css\">sudo iptables -t nat -<span class=\"hljs-selector-tag\">A<\/span> PREROUTING -<span class=\"hljs-selector-tag\">p<\/span> tcp <span class=\"hljs-attr\">--dport<\/span> <span class=\"hljs-number\">80<\/span> -j REDIRECT <span class=\"hljs-attr\">--to-ports<\/span> <socks5_server_port><\/pre>\n<p>\u5176\u4e2d <socks5_server_port> \u9700\u8981\u66ff\u6362\u6210\u4f60\u7684 Socks5 \u670d\u52a1\u5668\u6b63\u5728\u8fd0\u884c\u7684\u7aef\u53e3\u53f7\u3002<\/p>\n<ol start=\"4\">\n    <li>\u6700\u540e\uff0c\u4fdd\u5b58\u8fd9\u4e9b\u89c4\u5219\u5e76\u5e94\u7528\u66f4\u6539\uff1a\n<pre class=\"hljs language-dos\">sudo sh -c \"<span class=\"hljs-built_in\">echo<\/span> '<span class=\"hljs-built_in\">net<\/span>.ipv4.ip_forward=<span class=\"hljs-number\">1<\/span>' >> \/etc\/sysctl.conf\"\nsudo sysctl -p<\/pre>\n\u73b0\u5728\uff0c\u5f53\u6709\u4efb\u4f55 TCP \u6570\u636e\u5305\u901a\u8fc7\u7f51\u7edc\u65f6\uff0c\u90fd\u4f1a\u88ab\u91cd\u5b9a\u5411\u5230\u6307\u5b9a\u7684 Socks5 \u670d\u52a1\u5668\u4e0a\u3002<\/li>\n<\/ol>\n<h3 id=\"item-1\">\u65b9\u6cd52<\/h3>\n<ol>\n    <li>\u540c\u4e0a\uff0c \u5b89\u88c5iptables<\/li>\n    <li>\u521b\u5efaiptables_forward\u6587\u4ef6\n<code>vim \/etc\/network\/if-up.d\/iptables_forward<\/code>\n\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\n<pre class=\"hljs language-tcl\"><span class=\"hljs-comment\">#!\/bin\/sh<\/span>\necho <span class=\"hljs-string\">\"1\"<\/span> > \/<span class=\"hljs-keyword\">proc<\/span>\/sys\/net\/ipv4\/ip_forward<span class=\"hljs-title\">\niptables<\/span> -t<span class=\"hljs-title\"> nat<\/span> -A<span class=\"hljs-title\"> PREROUTING<\/span> -p<span class=\"hljs-title\"> tcp<\/span> --dport 80 -j<span class=\"hljs-title\"> REDIRECT<\/span> --to <socks5_server>:80<span class=\"hljs-title\">\niptables<\/span> -t<span class=\"hljs-title\"> nat<\/span> -A<span class=\"hljs-title\"> PREROUTING<\/span> -p<span class=\"hljs-title\"> udp<\/span> --dport 80 -j<span class=\"hljs-title\"> REDIRECT<\/span> --to <socks5_server>:80<span class=\"hljs-title\">\niptables<\/span> -t<span class=\"hljs-title\"> nat<\/span> -A<span class=\"hljs-title\"> POSTROUTING<\/span> -o<span class=\"hljs-title\"> eth0<\/span> -j<span class=\"hljs-title\"> MASQUERADE<\/span><\/pre>\n<\/li>\n    <li>\u8bbe\u7f6e\u6587\u4ef6\u53ef\u6267\u884c\u6743\u9650\n<code>chmod +x \/etc\/network\/if-up.d\/iptables_forward<\/code><\/li>\n    <li>\u6700\u540e\uff0c\u91cd\u65b0\u52a0\u8f7d\u7f51\u7edc\u914d\u7f6e\u4ee5\u5e94\u7528\u66f4\u6539\n<code>sudo service networking restart<\/code><\/li>\n<\/ol>\n<p>\u73b0\u5728\uff0c\u6240\u6709\u4ece Debian \u4e3b\u673a\u4f20\u51fa\u7684 TCP \u6216 UDP \u8fde\u63a5\u90fd\u4f1a\u88ab\u81ea\u52a8\u8f6c\u53d1\u5230\u6307\u5b9a\u7684 Socks5 \u670d\u52a1\u5668\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u8981\u5c06 iptables \u914d\u7f6e\u4e3a\u5c06\u5168\u5c40\u6d41\u91cf\u8f6c\u53d1\u5230 Socks5\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\u3002 \u9996\u5148\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86 iptables \u5de5\u5177\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a sudo apt-get &#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2627","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=2627"}],"version-history":[{"count":1,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2627\/revisions"}],"predecessor-version":[{"id":2628,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2627\/revisions\/2628"}],"wp:attachment":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=2627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=2627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=2627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}