{"id":1542,"date":"2020-07-07T09:08:41","date_gmt":"2020-07-07T01:08:41","guid":{"rendered":"https:\/\/0.mnihyc.com\/blog\/?p=1542"},"modified":"2020-07-07T14:22:48","modified_gmt":"2020-07-07T06:22:48","slug":"wireguard-network-chaining-and-routing","status":"publish","type":"post","link":"https:\/\/0.mnihyc.com\/blog\/archives\/1542","title":{"rendered":"Wireguard Network, Chaining and Routing"},"content":{"rendered":"<p>\u6700\u8fd1\u81ea\u5200\u4e86\u4e00\u4e2a\u6df1\u6e2f IPLC<span style=\"color: #ffffff;\">\uff08\u5403\u4e0d\u8d77\u996d\u5566\uff09<\/span>\uff0c\u5206\u6709\u6df1\u5733\u7aef\u548c\u9999\u6e2f\u7aef\u4e24\u516c\u7f51 IP \u548c\u4e24\u5185\u7f51 IP\uff0c\u5185\u7f51\u8d70\u7684\u662f IPLC\u3002\u5982\u679c\u53ea\u7528 NAT \/ Port Forwarding \u7684\u8bdd\u672a\u514d\u4e5f\u592a\u900a\u4e86\u70b9\uff0c\u5bf9\u4e0d\u8d77\u6211\u8fd9\u4e2a\u94b1\u554a\uff08\u4e0dx\uff09\uff01\u4e8e\u662f\u5c31\u5c1d\u8bd5\u901a\u8fc7\u4e00\u4e9b\u5947\u5999\u7684\u64cd\u4f5c\u60f3\u628a\u5b83\u4eec \u201c\u4e32\u201d \u8d77\u6765\uff0c\u7136\u800c\u8fc7\u7a0b\u53ef\u60f3\u800c\u77e5\u5e76\u4e0d\u662f\u90a3\u4e48\u7684\u987a\u5229&#8230;&#8230;\uff08<\/p>\n<p>&nbsp;<\/p>\n<p><!--more--><\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<ul>\n<li>\n<h2>\u76ee\u5f55<\/h2>\n<ul>\n<li>\n<p><a href=\"#nat_pf\"><strong>NAT<\/strong> \/ <strong>Port Forwarding<\/strong> with <strong>iptables<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#i_c_w\"><strong>Installation<\/strong> and <strong>configuration<\/strong> of <strong>Wireguard<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#r_o_r\"><strong>Route<\/strong> on your <strong>own<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#c_w\"><strong>Chained<\/strong> <strong>Wireguard Network (Policy Routing)<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#s_r\"><strong>Selective Routing<\/strong> (<strong>Policy Routing<\/strong> 1)<\/a><\/p>\n<\/li>\n<li><a href=\"#end\">\u6700\u540e<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><a id=\"nat_pf\"><\/a>\u00a0<\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>NAT<\/strong> \/ <strong>Port Forwarding<\/strong> with <strong>iptables<\/strong><\/li>\n<\/ul>\n<p>\u8fd9\u91cc\u662f\u5bf9 NAT \u7684\u57fa\u7840\u8bb2\u89e3\uff0c\u6bd4\u8f83\u7b80\u5355\uff08<\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Network_address_translation\"><span style=\"color: #0000ff;\"><strong>NAT<\/strong><\/span><\/a>, or <strong>Network Address Translation<\/strong>, which is one of the most basic ways allowing a <strong>gateway<\/strong> to <strong>forward packets<\/strong>, enables <strong>LAN<\/strong> (Local Area Network) users to access <strong>WAN<\/strong> (Wide Area Network) normally.<\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/OSI_model\"><strong><span style=\"color: #0000ff;\">OSI model<\/span><\/strong><\/a> (Open Systems Interconnection model) includes 7 layers labelled from 1 to 7: Physical, Data link, Network, Transport, Session, Presentation, Application. <strong>NAT<\/strong> works in <strong>Layer 3 &#8220;Network&#8221;<\/strong>, where also the ordinary <strong>routing tables<\/strong> take effect. The packet transmitted in this layer are called <strong>IP Packet<\/strong>, which is composed of a <a href=\"https:\/\/en.wikipedia.org\/wiki\/IPv4#Header\"><span style=\"color: #0000ff;\"><strong>IP Header<\/strong><\/span><\/a> and data inside, such as <strong>TCP, UDP, ICMP, OSPF<\/strong> and some other <strong>IP protocols,<\/strong> which represents <strong>Layer 4 &#8220;Transport&#8221;<\/strong>.<\/p>\n<p>A IP Header consists of <strong>TTL<\/strong> (<strong>Time to Live<\/strong>), Protocol numbers, <strong>Source IP Address<\/strong>, <strong>Destination IP Address<\/strong> and many other important messages, therefore that&#8217;s the reason why <strong>NAT<\/strong> relies on it.<\/p>\n<p>Now let&#8217;s have a detailed look at how exactly <strong>NAT<\/strong> works.<\/p>\n<p>Assuming that you are a LAN user with an internal IP 192.168.1.2, and the router, or gateway, is at 192.168.1.1. When accessing, for example, 1.1.1.1, the system constructs a packet with all necessary messages including the <strong>Destination IP<\/strong> 1.1.1.1 and the <strong>Source IP<\/strong> 192.168.1.2, and then send it to the directly connected gateway at 192.168.1.1. What if the gateway only transmit the packet without any modifications? Putting aside the filters of <strong>IP spoofing<\/strong>, assuming that the packet eventually arrive at the target, safe. Then the target will &#8220;exchange&#8221; the packet&#8217;s <strong>Source IP<\/strong> with <strong>Destination IP<\/strong>, getting ready to send back its response. But, how is it able to send to 192.168.1.2 in WAN? There may be millions of &#8220;192.168.1.2&#8221; available, and in fact, the target have <strong>no route<\/strong> to this private IP address. So you will never get any response from the target, because the target doesn&#8217;t know how to send it back to you. All of this is due to your private network in LAN, and the gateway just transmit the packet without modifications.<\/p>\n<p>So here comes the <strong>NAT<\/strong>! Commonly, <strong>NAT<\/strong> modifies the <strong>Source IP Address<\/strong> in a <strong>IP Packet<\/strong>. For instance, when your gateway happens to have a well-routed public IP address and you&#8217;re sending packets to it via the LAN subnet, the gateway changes the packet&#8217;s <strong>Source IP Address<\/strong> (from 192.168.1.2 to its public IP address) and then forward it to the WAN. In this situation, the target knows how to reply since the <strong>Source IP Address<\/strong> (for it it&#8217;s the <strong>Destination IP Address<\/strong>) is now <strong>reachable<\/strong>. Once the gateway receives the response, it will be matched with the marks in the kernel, then modifying the <strong>Destination IP Address<\/strong> (from its public IP address to 192.168.1.2), sending back to your system at 192.168.1.2.<\/p>\n<p>This process is so called <strong>IP masquerading<\/strong>. It can be done using <strong>iptables<\/strong> with the following command:<\/p>\n<pre class=\"lang:sh decode:true \">sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE<\/pre>\n<p>&#8220;<strong>nat<\/strong>&#8221; is the table name, &#8220;<strong>POSTROUTING<\/strong>&#8221; is the chain name, &#8220;<strong>eth0<\/strong>&#8221; is the interface where this rule will have effect.<\/p>\n<p>Meanwhile, port forwarding is almost the same. The gateway changes its <strong>Destination IP Address<\/strong> when a packet arrives at the certain port of the gateway. This can be done using <strong>iptables<\/strong> with the following commands:<\/p>\n<pre class=\"lang:sh decode:true\">sudo iptables -t nat -I PREROUTING -p tcp --dport 443 -j DNAT --to 1.1.1.1\r\nsudo iptables -t nat -I POSTROUTING -p tcp --dport 443 -j MASQUERADE<\/pre>\n<p>or<\/p>\n<pre class=\"lang:sh decode:true\">sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 1.1.1.1:443\r\nsudo iptables -t nat -A POSTROUTING -p tcp -d 1.1.1.1 --dport 443 -j SNAT --to-source 1.2.3.4<\/pre>\n<p>which means forwarding packets from 192.168.1.1:443 to 1.1.1.1:443, <strong>SNA<\/strong>T and <strong>DNAT<\/strong> represents two types of modifications of <strong>Source IP Address<\/strong> and <strong>Destination IP Address<\/strong> respectively, 1.2.3.4 is your public IP address (maybe private if under more NATs).<\/p>\n<p>* Yes here we&#8217;re talking about <strong>IPv4<\/strong>, not IPv6.<\/p>\n<p><del>\uff08\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u662f\u5168\u82f1\u6587\uff0c\u56e0\u4e3a\u6211\u611f\u89c9\u534a\u4e2d\u6587\u534a\u82f1\u6587\u592a\u4e11\u4e86\u554a\uff08\uff0c\u867d\u7136\u5e95\u4e0b\u4e5f\u662f\u8fd9\u6837<\/del><\/p>\n<p><a id=\"i_c_w\"><\/a>\u00a0<\/p>\n<hr \/>\n<ul>\n<li><strong>Installation<\/strong> and <strong>configuration<\/strong> of <strong>Wireguard<\/strong><\/li>\n<\/ul>\n<p>\u5728 Ubuntu 18.04 amd64 \u4e0a\uff0cWireguard \u53ef\u4ee5\u901a\u8fc7\u51e0\u4e2a\u7b80\u5355\u7684\u6b65\u9aa4\u5b89\u88c5\u3002<\/p>\n<p>\u5982\u679c\u6ca1\u6709 add-apt-repository \u7684\u8bdd\uff0c\u53ef\u4ee5\u5148 <span class=\"lang:sh decode:true  crayon-inline \">sudo apt install software-properties-common<\/span>\u00a0<\/p>\n<pre class=\"lang:sh decode:true\">sudo add-apt-repository ppa:wireguard\/wireguard\r\nsudo apt install wireguard wireguard-dkms<\/pre>\n<p>\u5982\u679c dkms \u5b89\u88c5\u5931\u8d25\u7684\u8bdd\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u5347\u7ea7 kernel \u6216\u8005\u91cd\u542f\uff08\uff09<\/p>\n<p>\u7136\u540e Wireguard \u7684\u57fa\u672c\u914d\u7f6e\u4e5f\u5f88\u7b80\u5355\uff1a<\/p>\n<p style=\"padding-left: 40px;\">1\uff0cWireguard \u4e3a Peer \u578b VPN\uff0c\u56e0\u6b64\u6bcf\u4e2a Peer \u90fd\u8981\u6709\u5b83\u7684 Public\/Prvate Key\uff0c\u53ef\u4ee5\u901a\u8fc7 <span class=\"lang:default decode:true  crayon-inline\">wg genkey<\/span> \u53ca <span class=\"lang:default decode:true  crayon-inline\">wg pubkey<\/span> \u751f\u6210\u3002<\/p>\n<p style=\"padding-left: 40px;\">2\uff0c\u4e00\u5bf9 Peer \u95f4\u81f3\u5c11\u8981\u6709\u4e00\u65b9\u6307\u5b9a Endpoint \uff08\u633a\u663e\u7136\u5427www\uff09<\/p>\n<p style=\"padding-left: 40px;\">3\uff0cWireguard \u4ec5\u5141\u8bb8 AllowedIPs \u91cc\u6307\u5b9a\u7684 IP \u901a\u8fc7\u5b83\u7684 Interface\uff0c\u8fd9\u4e3a\u4e4b\u540e\u7684\u624b\u52a8 Routing \u57cb\u4e0b\u4e86\u4f0f\u7b14\uff09<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u5047\u5b9a\u7684 Server \u7aef\uff08Gateway \u7aef\uff09\uff1a<\/p>\n<pre class=\"lang:default decode:true\">[Interface]\r\nAddress = 10.1.1.1\/24\r\nListenPort = 12345\r\nPrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nPostUp = iptables -t nat -A POSTROUTING -o wg -j MASQUERADE\r\nPostDown = iptables -t nat -D POSTROUTING -o wg -j MASQUERADE\r\n\r\n[Peer]\r\nPublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nAllowedIPs = 10.1.1.2\/32\r\n<\/pre>\n<p>\u5176\u4e2d PostUp \u548c PostDown \u5373\u5728 Interface Brought Up \u4e4b\u540e\u548c Taken Down \u4e4b\u540e\u6267\u884c\u7684\u547d\u4ee4\uff0c\u5229\u7528 MASQUERADE \u8fdb\u884c NAT \u4f7f\u5f97\u6d41\u91cf\u53ef\u4ee5\u6b63\u5e38\u7ecf\u8fc7 Server \u7aef\u5e76\u4ece\u53e6\u4e00\u4e2a Interface \u51fa\u53bb\u3002<\/p>\n<p>Client \u7aef\uff1a<\/p>\n<pre class=\"lang:default decode:true\">[Interface]\r\nPrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nAddress = 10.1.1.2\/32\r\nListenPort = 12345\r\n\r\n[Peer] PublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nEndpoint = xx.xx.xx.xx:12345\r\nAllowedIPs = 10.1.1.0\/24\r\nPersistentKeepalive = 25\r\n<\/pre>\n<p>\u7136\u540e\u4f7f\u7528 <span class=\"lang:sh decode:true  crayon-inline \">wg-quick up wg<\/span> \u542f\u52a8\u653e\u5728 <span class=\"lang:default decode:true  crayon-inline\">\/etc\/wireguard\/wg.conf<\/span> \u91cc\u7684\u914d\u7f6e\uff0c<span class=\"lang:sh decode:true  crayon-inline \">sudo systemctl enable wg-quick@wg<\/span> \u6765\u5f00\u673a\u542f\u52a8\uff0c\u5c31\u5b8c\u6210\u4e86\u6700\u57fa\u672c\u7684\u914d\u7f6e\u5566\u3002<\/p>\n<p>\u8bd5\u8bd5\u5728 Client \u4e0a <span class=\"lang:sh decode:true  crayon-inline \">ping 10.1.1.1<\/span> \u4f1a\u53d1\u73b0\u901a\u4e86\uff0c\u800c\u4e14\u53ea\u6709\u4e00\u8df3\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u628a Multi-hop \u8f6c\u6362\u4e3a Direct \u4e86\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><a id=\"r_o_r\"><\/a>\u00a0<\/p>\n<hr \/>\n<ul>\n<li><strong>Route<\/strong> on your <strong>own<\/strong><\/li>\n<\/ul>\n<p>\u7531\u4e8e\u6211\u4eec\u5728 Client \u7aef\u7684 AllowedIPs \u90a3\u91cc\u586b\u5165\u4e86 10.1.1.0\/24 \u8fd9\u4e2a\u5b50\u7f51\uff0c\u6240\u4ee5\u82e5\u4f7f\u7528 <span class=\"lang:sh decode:true  crayon-inline\">ip route show<\/span> \u67e5\u770b\u8def\u7531\u4fe1\u606f\u7684\u8bdd\uff0c\u4f1a\u53d1\u73b0\u786e\u5b9e\u4e5f\u53ea\u6709 10.1.1.0\/24 \u8fd9\u4e2a\u5b50\u7f51\u4f1a\u901a\u8fc7 Wireguard \u7684 Interface \u8d70\u5230 Server \u7aef\u3002<\/p>\n<p>\u7136\u800c\uff0c\u5982\u679c\u6211\u4eec\u81ea\u5df1 <span class=\"lang:sh decode:true  crayon-inline\">sudo ip route add 1.1.1.1\/32 dev wg<\/span> \u5e0c\u671b\u8ba9 1.1.1.1\/32 \u4e5f\u901a\u8fc7 Server \u7aef\u8d70\u51fa\u53bb\u7684\u8bdd\uff0c\u4f1a\u53d1\u73b0\u7adf\u7136\u8fde Gateway 10.1.1.1\/32 \u90fd\u8d70\u4e0d\u5230\uff1f\uff01\u8fd9\u662f Wireguard \u7684\u4e00\u4e2a\u7279\u6027\uff1a\u7531\u4e8e\u6211\u4eec\u5e76\u6ca1\u6709\u5728 AllowedIPs \u91cc\u9762\u52a0\u5165 1.1.1.1\/32\uff0c\u6240\u4ee5 Wireguard \u81ea\u52a8\u628a\u5b83\u5f53\u6210 Invalid \u8fc7\u6ee4\u6389\u4e86\uff01\u6240\u4ee5\u5982\u679c\u6211\u4eec\u60f3\u81ea\u7531\u5730 Route\uff0c\u5c31\u5fc5\u987b\u628a Client \u5199\u6210\u8fd9\u6837\uff1a<\/p>\n<pre class=\"lang:default decode:true\">[Interface]\r\nPrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nAddress = 10.1.1.2\/32\r\nListenPort = 12345\r\nTable = off\r\nPostUp = ip route add 10.1.1.0\/24 dev wg\r\n\r\n[Peer]\r\nPublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nEndpoint = xx.xx.xx.xx:12345\r\nAllowedIPs = 0.0.0.0\/0\r\nPersistentKeepalive = 25\r\n<\/pre>\n<p>Table = off \u5c31\u662f\u4e0d\u8ba9 Wireguard \uff08\u51c6\u786e\u5730\u6765\u8bf4\u662f wg-quick\uff09\u81ea\u52a8\u6dfb\u52a0\u8def\u7531\uff0c\u6240\u4ee5\u8981\u5728 PostUp \u90a3\u91cc\u624b\u52a8\u52a0\u8fdb\u53bb\uff0c\u7531\u4e8e Interface \u5220\u9664\u65f6 Route \u4f1a\u81ea\u52a8\u6d88\u5931\uff0c\u6240\u4ee5\u4e0d\u7528\u5728 PostDown \u91cc\u8fdb\u884c\u5220\u9664\u5904\u7406<\/p>\n<p>\u5f00\u59cb\u624b\u52a8 Route \u4e86\uff08\u7b11\uff0c\u7136\u540e\u518d <span class=\"lang:sh decode:true  crayon-inline\">sudo ip route add 1.1.1.1\/32 dev wg<\/span> \u5e76\u4e14\u5c1d\u8bd5 <span class=\"lang:sh decode:true crayon-inline\">mtr 1.1.1.1<\/span> \uff0c\u5c31\u4f1a\u53d1\u73b0\u771f\u7684\u4ece Server \u7aef\u8d70\u51fa\u53bb\u4e86\uff01<\/p>\n<p>&nbsp;<\/p>\n<p><a id=\"c_w\"><\/a>\u00a0<\/p>\n<hr \/>\n<ul>\n<li><strong>Chained Wireguard<\/strong> Network (<strong>Policy Routing<\/strong>)<\/li>\n<\/ul>\n<p>\u90a3\u4e48\u73b0\u5728\u7684\u8bbe\u60f3\u662f\uff0c\u5728\u6df1\u5733\u7aef\u4e0a\u8d77\u4e00\u4e2a Server\uff0c\u7528\u4e8e\u8fde\u63a5\u56fd\u5185\u5ba2\u6237\u7aef\uff1b\u5e76\u4e14\u5728\u6df1\u5733\u7aef\u548c\u9999\u6e2f\u7aef\u5185\u7f51\uff08\u8d70 IPLC\uff09\u4e5f\u8d77\u4e00\u4e2a Wireguard Tunnel \u7528\u4e8e\u6570\u636e\u4ea4\u6362\u3002\u90a3\u4e48\u8be5\u600e\u4e48\u628a\u6df1\u5733\u7aef\u90a3\u91cc\u7684\u6d41\u91cf\u5168\u90e8\u00a0 Forward \u5230\u9999\u6e2f\u7aef\u5462\uff1f<\/p>\n<p>\u6df1\u5733\u7aef Server wgs \u7f51\u6bb5 10.66.224.1\/19\uff0c\u9999\u6e2f\u7aef Server wgp \u7f51\u6bb5 10.66.220.200\/24\uff0c\u6df1\u5733\u7aef Client \u5206\u914d 10.66.220.1\/32<\/p>\n<p>\u7531\u4e8e\u6211\u4eec\u8fde\u63a5\u5230\u7684\u662f\u6df1\u5733\u7aef\u7684 Server\uff0c\u6240\u4ee5\u4ece\u6df1\u5733\u7aef wgs \u91cc\u53d1\u9001\u51fa\u53bb\u5305\u7684 Source IP Address \u80af\u5b9a\u5c5e\u4e8e 10.66.224.0\/19\u3002<\/p>\n<p>\u6240\u4ee5\u8fd9\u5176\u5b9e\u662f\u4e00\u4e2a Source-based routing\uff0c\u5373\u5982\u679c\u5305\u7684 Source IP Address \u4e3a 10.66.224.0\/19\uff0c\u90a3\u4e48\u5c31\u628a\u5b83 Route \u5230 wgp \u4e0a\uff0c\u5426\u5219\u6309\u7167\u9ed8\u8ba4\u7684 Routing table \u8d70\u3002<\/p>\n<p>\u90a3\u4e48\u9996\u5148\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49 Routing table\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">sudo su -c 'echo 1 t-1-2 &gt;&gt; \/etc\/iproute2\/rt_tables'<\/pre>\n<p>\u7136\u540e\u518d\u5f80\u91cc\u9762\u52a0\u5339\u914d\u89c4\u5219\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">sudo ip rule add from 10.66.224.0\/19 lookup t-1-2<\/pre>\n<p>\u6700\u540e\u5f80\u91cc\u9762\u52a0\u8def\u7531\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">sudo ip route add 0.0.0.0\/0 dev wgp table t-1-2\r\nsudo ip route add 10.66.224.0\/19 dev wgs table t-1-2<\/pre>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f\u8fd9\u91cc\u9700\u8981\u52a0\u4e24\u6761\u8def\u7531\uff0c\u5426\u5219\u5728\u8bbf\u95ee 10.66.224.0\/19 \u4e2d\u7684\u5176\u4ed6 Client \u7684\u65f6\u5019\u5c31\u4f1a\u88ab\u987a\u5e26\u4e00\u8d77 Forward \u5230\u9999\u6e2f\u7aef\u53bb\uff0c\u8fd9\u4e0d\u662f\u6211\u4eec\u60f3\u8981\u7684\u6548\u679c<\/p>\n<p>\u6700\u540e\u6d4b\u6d4b\u6548\u679c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1547\" src=\"https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png\" alt=\"\" width=\"374\" height=\"88\" srcset=\"https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png 374w, https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB-300x71.png 300w, https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB-150x35.png 150w\" sizes=\"auto, (max-width: 374px) 100vw, 374px\" \/><\/p>\n<p>\u5b8c\u7f8e\uff01\u53ef\u4ee5\u770b\u5230\u6d41\u91cf\u987a\u5229\u5730\u4ece\u6df1\u5733\u7aef Server 10.66.224.1 \u901a\u8fc7 IPLC \u91cc\u8d77\u7684\u5185\u7f51\u96a7\u9053 \u6d41\u5230\u4e86\u9999\u6e2f\u7aef Server 10.66.220.200<\/p>\n<p>\u540c\u6837\u5730\uff0c\u7ee7\u7eed\u5728 GCP HK \u4e0a\u8d77\u4e00\u4e2a Server 10.66.6.6\/24\uff0c\u5e76\u4e14\u5206\u914d\u7ed9\u9999\u6e2f\u7aef 10.66.6.250\/32\uff0c\u6309\u7167\u4e0a\u9762\u7684\u65b9\u6cd5\uff0c\u4f7f\u5f97 Source IP Address \u4e3a 10.66.220.0\/24 \u7684\u5305\uff08\u56e0\u4e3a\u4ece wgp \u91cc\u51fa\u6765\u540e\u7ecf\u8fc7\u4e86 NAT \u5904\u7406\uff0c\u6e90 IP \u88ab\u6539\u53d8\uff09\u5168\u90e8\u8d70 wg6 \u5230 10.66.6.6\uff0c\u4ece GCP HK \u91cc\u51fa\u53bb\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1548\" src=\"https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/90J0C1361DEO9JVDA87AN.png\" alt=\"\" width=\"368\" height=\"176\" srcset=\"https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/90J0C1361DEO9JVDA87AN.png 368w, https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/90J0C1361DEO9JVDA87AN-300x143.png 300w, https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/90J0C1361DEO9JVDA87AN-150x72.png 150w\" sizes=\"auto, (max-width: 368px) 100vw, 368px\" \/><\/p>\n<p>\u592a\u5b8c\u7f8e\u4e86\uff01<\/p>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u5df2\u7ecf\u6210\u529f\u5730\u628a\u4e09\u4e2a Wireguard \u4e32\u8d77\u6765\u4e86\uff0c\u4f5c\u4e3a\u53c2\u8003\uff0c\u4ee5\u4e0b\u4e3a\u5b8c\u6574\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<p>\u6df1\u5733\u7aef Server wgs<\/p>\n<pre class=\"lang:default decode:true\">[Interface]\r\nAddress = 10.66.224.1\/19\r\nPostUp = ip route add 10.66.224.0\/19 dev wgs table t-1-2\r\nListenPort = 12345\r\nPrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n[Peer]\r\nPublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nAllowedIPs = 10.66.224.2\/32<\/pre>\n<p>\u6df1\u5733\u7aef Client wgp<\/p>\n<pre class=\"lang:default decode:true\">[Interface]\r\nAddress = 10.66.220.1\/32\r\nPostUp = ip rule add from 10.66.224.0\/19 lookup t-1-2; ip route add 0.0.0.0\/0 dev wgp table t-1-2; iptables -t nat -A POSTROUTING -o wgp -j MASQUERADE\r\nPostDown = ip rule del from 10.66.224.0\/19 lookup t-1-2; iptables -t nat -D POSTROUTING -o wgp -j MASQUERADE\r\nPrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nTable = off\r\n[Peer]\r\nEndpoint = 10.xx.xx.xx:12345\r\nPublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nAllowedIPs = 0.0.0.0\/0<\/pre>\n<p>\u9999\u6e2f\u7aef Server wgp<\/p>\n<pre class=\"lang:default decode:true \">[Interface]\r\nAddress = 10.66.220.200\/24\r\nPostUp = ip rule add from 10.66.220.0\/24 lookup t-2-6; ip route add 10.66.220.0\/24 dev wgp table t-2-6\r\nPostDown = ip rule del from 10.66.220.0\/24 lookup t-2-6\r\nListenPort = 12345\r\nPrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n[Peer]\r\nPublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nAllowedIPs = 10.66.220.1\/32\r\n<\/pre>\n<p>\u6ce8\u610f\u5230 \u540c\u6837\u5730\uff0c\u8fd9\u91cc\u6dfb\u52a0\u4e86\u4e00\u4e2a 10.66.220.0\/24 \u7684\u76f4\u8fde Route\uff0c\u5426\u5219\u5230 10.66.220.0\/24 \u7684\u6d41\u91cf\u5c31\u5168\u90e8\u88ab Forward \u5230 GCP HK 10.66.6.6 \u4e0a\uff0c\u8fd9\u4e0d\u662f\u6211\u4eec\u60f3\u8981\u7684\u6548\u679c<\/p>\n<p>\u9999\u6e2f\u7aef Client wg6<\/p>\n<pre class=\"lang:default decode:true\">[Interface]\r\nPrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nAddress = 10.66.6.250\/32\r\nListenPort = 12345\r\nPostUp = ip route add 10.66.6.0\/24 dev wg6; ip route add 0.0.0.0\/0 dev wg6 table t-2-6; iptables -t nat -A POSTROUTING -o wg6 -j MASQUERADE\r\nPostDown = iptables -t nat -D POSTROUTING -o wg6 -j MASQUERADE\r\nTable = off\r\n[Peer]\r\nPublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nEndpoint = GCP.HK:12345\r\nAllowedIPs = 0.0.0.0\/0\r\nPersistentKeepalive = 25\r\n<\/pre>\n<p>GCP HK Server wg6<\/p>\n<pre class=\"lang:default decode:true \">[Interface]\r\nAddress = 10.66.6.6\/24\r\nPostUp = iptables -t nat -A POSTROUTING -o ens4 -j MASQUERADE\r\nPostDown = iptables -t nat -D POSTROUTING -o ens4 -j MASQUERADE\r\nListenPort = 12345\r\nPrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nMTU = 1420\r\n[Peer]\r\nPublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nAllowedIPs = 10.66.6.250\/32\r\n<\/pre>\n<p>\uff08\u503c\u5f97\u6ce8\u610f\u7684\u662f GCP Network Interface \u7684\u9ed8\u8ba4 MTU \u90fd\u504f\u5c0f\uff0c\u6240\u4ee5\u9700\u8981\u624b\u52a8\u6307\u5b9a<\/p>\n<p>&nbsp;<\/p>\n<p><a id=\"s_r\"><\/a>\u00a0<\/p>\n<hr \/>\n<ul>\n<li><strong>Selective Routing<\/strong> (<strong>Policy Routing<\/strong> 1)<\/li>\n<\/ul>\n<p>\u73b0\u5728\u6211\u8fd8\u6709\u4e00\u53f0 HKT\uff0c\u4e5f\u60f3\u628a\u5b83\u52a0\u5165\u8fd9\u4e2a Wireguard Network\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1550\" src=\"https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/HIILJRBYTN5T@52KZ3IE2.png\" alt=\"\" width=\"375\" height=\"226\" srcset=\"https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/HIILJRBYTN5T@52KZ3IE2.png 375w, https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/HIILJRBYTN5T@52KZ3IE2-300x181.png 300w, https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/HIILJRBYTN5T@52KZ3IE2-150x90.png 150w\" sizes=\"auto, (max-width: 375px) 100vw, 375px\" \/><\/p>\n<p>\u7136\u800c\u8fd9\u6837\u5c31\u51fa\u73b0\u4e86\u4e00\u4e2a\u95ee\u9898\uff1a\u5728\u9999\u6e2f\u7aef\u4e0a\uff0c\u5982\u4f55\u51b3\u5b9a\u8d70 GCP HK \u8fd8\u662f HKT\uff1f<\/p>\n<p><del>iBGP\uff1f\u52a8\u6001\uff1f\u968f\u673a\uff1f\uff1f\uff1f\uff1f<\/del><\/p>\n<p>\u8fd8\u662f\u56de\u5230\u6700\u539f\u59cb\u7684\u65b9\u6cd5 Source-based routing<\/p>\n<p>\u5982\u679c\u6211\u4eec\u80fd\u5728 Client wgs \u4e0a\u76d1\u542c\u4e0d\u540c\u7684 IP \u5730\u5740\uff0c\u5e76\u4e14\u8fde\u5230\u4e0d\u540c\u7684\u51fa\u53e3\uff0c\u90a3\u5c31\u597d\u4e86\uff01<\/p>\n<p>\u4f46\u662f\u6709\u4e00\u4e2a\u95ee\u9898\uff1a\u7ecf\u8fc7\u6df1\u5733\u7aef\u7684 Client wgp \u5230\u8fbe\u9999\u6e2f\u7aef Server wgp \u540e\uff0c\u8fd9\u4e2a\u6570\u636e\u5305\u662f\u7ecf\u8fc7 NAT \u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u4e22\u5931\u4e86\u6211 Client wgs \u8fde\u5230\u6df1\u5733\u7aef Server wgs \u6240\u5e26\u6709\u7684 Source IP Address \u4fe1\u606f\uff01<\/p>\n<p>\u6240\u4ee5\u9996\u5148\u8981\u628a\u6df1\u5733\u7aef\u4e0a\u7684 Routing policy \u505a\u4e00\u4e9b\u4fee\u6539\uff1a\u4e0d\u80fd\u76f4\u63a5\u4e00\u9505\u7aef\u5230\u540c\u4e00\u4e2a Routing table \u91cc\u3002\u56e0\u4e3a\u6211\u4eec\u60f3\u5728\u4f20\u8f93\u7684\u8fc7\u7a0b\u4e2d\u4fdd\u7559\u4e00\u4e9b\u539f\u6765 Source IP Address \u7684\u4fe1\u606f\uff0c\u800c\u8fd9\u4e9b\u4fe1\u606f\u53c8\u4f1a\u5728 NAT \u4e2d\u88ab\u66ff\u6362\u4e3a\u81ea\u5df1\u7684 Source IP Address\uff0c\u6240\u4ee5\u53ea\u9700\u539f\u6765\u7684 Source IP Address \u4e00\u4e00\u5bf9\u5e94 NAT \u540e\u7684 Source IP Address\uff0c\u4e0d\u5c31\u53ef\u4ee5\u8fbe\u5230 Selective \u7684\u6548\u679c\u4e86\u5417\uff1f<\/p>\n<p>\u6240\u4ee5\u5728\u6df1\u5733\u7aef Server wgs \u4e0a\u66f4\u6539 AllowedIPs \u4e3a 10.66.224.2\/32 \u548c 10.66.225.2\/32\uff0c\u524d\u8005\u8d70 GCP HK\uff0c\u540e\u8005\u8d70 HKT\u3002<\/p>\n<p>\u63a5\u7740\u9700\u8981\u628a\u8fd9\u4e24\u5206\u8fdb\u4e0d\u540c\u7684 Routing table \u91cc<\/p>\n<pre class=\"lang:sh decode:true\">sudo ip rule add from 10.66.224.0\/24 lookup t-1-6\r\nsudo ip rule add from 10.66.225.0\/24 lookup t-1-10<\/pre>\n<p>\u7531\u4e8e\u8981\u4f7f NAT \u540e\u7684 Source IP Address \u4ecd\u5e26\u6709\u6211\u4eec\u7684\u4fe1\u606f\uff0c\u56e0\u6b64\u76f4\u63a5\u628a\u9999\u6e2f\u7aef Server wgp \u7684 AllowedIPs \u6539\u4e3a\u6574\u4e2a 10.66.220.0\/24\uff0c\u5e76\u4e14\u5728\u6df1\u5733\u7aef Client wgp \u540c\u65f6\u76d1\u542c 10.66.220.224 \u548c 10.66.220.225\u3002<\/p>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cMASQUERADE \u64cd\u4f5c\u4f1a\u81ea\u52a8\u9009\u62e9\u9002\u5408\u7684 Source IP Address \u8fdb\u884c NAT\uff08\u5728 ip route \u91cc\u6dfb\u52a0 src \u5173\u952e\u5b57\u662f\u65e0\u7528\u7684\uff09\uff0c\u8fd9\u6837\u5c31\u8fbe\u4e0d\u5230\u6211\u4eec\u60f3\u8981\u7684\u6548\u679c\u4e86\uff0c\u56e0\u6b64\u6539\u4e3a SNAT \u624b\u52a8\u6307\u5b9a Source IP Address<\/p>\n<pre class=\"lang:sh decode:true\">sudo iptables -t nat -A POSTROUTING -o wgp -s 10.66.224.0\/24 -j SNAT --to-source 10.66.220.224\r\nsudo iptables -t nat -A POSTROUTING -o wgp -s 10.66.225.0\/24 -j SNAT --to-source 10.66.220.225<\/pre>\n<p>\u81f3\u6b64\uff0c\u5df2\u7ecf\u6210\u529f\u7684\u628a\u4ece\u6df1\u5733\u7aef Client wgp \u53d1\u51fa\u53bb\u7684\u5305\u4e2d Source IP Address \u6807\u8bb0\u597d\u4e86\u3002\u5269\u4e0b\u8981\u505a\u7684\u53ea\u662f\u5728\u9999\u6e2f\u7aef Server wgp \u8fdb\u884c\u5206\u6d41\u5373\u53ef\u3002<\/p>\n<pre class=\"lang:sh decode:true \">sudo ip rule add from 10.66.220.224\/32 lookup t-2-6\r\nsudo ip rule add from 10.66.220.225\/32 lookup t-2-10<\/pre>\n<p>\u4e4b\u540e\u7684\u6b65\u9aa4\u5982\u51fa\u4e00\u8f99\uff0c\u90e8\u5206\u5173\u952e PostUp \u548c PostDown \u8bed\u53e5\u9644\u5728\u4e0b\u65b9<\/p>\n<p>\u6df1\u5733\u7aef Server wgs<\/p>\n<pre class=\"lang:sh decode:true\">#!\/bin\/bash\r\n\r\npostup()\r\n{\r\n        ip route add 10.66.224.0\/19 dev wgs table t-1-6\r\n        ip route add 10.66.224.0\/19 dev wgs table t-1-10\r\n}\r\n\r\npostdown()\r\n{\r\n}\r\n<\/pre>\n<p>\u6df1\u5733\u7aef Client wgp<\/p>\n<pre class=\"lang:sh decode:true \">#!\/bin\/bash\r\n\r\npostup()\r\n{\r\n        iptables -t nat -A POSTROUTING -o wgp -s 10.66.224.0\/24 -j SNAT --to-source 10.66.220.224\r\n        iptables -t nat -A POSTROUTING -o wgp -s 10.66.225.0\/24 -j SNAT --to-source 10.66.220.225\r\n        ip rule add from 10.66.224.0\/24 lookup t-1-6\r\n        ip rule add from 10.66.225.0\/24 lookup t-1-10\r\n        ip route add 10.66.220.0\/24 dev wgp\r\n        ip route add 0.0.0.0\/0 dev wgp table t-1-6\r\n        ip route add 0.0.0.0\/0 dev wgp table t-1-10\r\n}\r\npostdown()\r\n{\r\n        iptables -t nat -D POSTROUTING -o wgp -s 10.66.224.0\/24 -j SNAT --to-source 10.66.220.224\r\n        iptables -t nat -D POSTROUTING -o wgp -s 10.66.225.0\/24 -j SNAT --to-source 10.66.220.225\r\n        ip rule del from 10.66.224.0\/24 lookup t-1-6\r\n        ip rule del from 10.66.225.0\/24 lookup t-1-10\r\n}<\/pre>\n<p>\u9999\u6e2f\u7aef Server wgp<\/p>\n<pre class=\"lang:default decode:true \">#!\/bin\/bash\r\n\r\npostup()\r\n{\r\n        ip rule add from 10.66.220.224\/32 lookup t-2-6\r\n        ip rule add from 10.66.220.225\/32 lookup t-2-10\r\n        ip route add 10.66.220.0\/24 dev wgp table t-2-6\r\n        ip route add 10.66.220.0\/24 dev wgp table t-2-10\r\n}\r\npostdown()\r\n{\r\n        ip rule del from 10.66.220.224\/32 lookup t-2-6\r\n        ip rule del from 10.66.220.225\/32 lookup t-2-10\r\n}\r\n<\/pre>\n<p>\u9999\u6e2f\u7aef Client wg6<\/p>\n<pre class=\"lang:sh decode:true \">#!\/bin\/bash\r\n\r\npostup()\r\n{\r\n        ip route add 10.66.6.0\/24 dev wg6\r\n        iptables -t nat -A POSTROUTING -o wg6 -j MASQUERADE\r\n        ip route add 0.0.0.0\/0 dev wg6 table t-2-6\r\n}\r\npostdown()\r\n{\r\n        iptables -t nat -D POSTROUTING -o wg6 -j MASQUERADE\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><a id=\"end\"><\/a>\u00a0<\/p>\n<hr \/>\n<ul>\n<li>\u6700\u540e<\/li>\n<\/ul>\n<p>UDP \u7684 QoS \u7b49\u7ea7\u591a\u4f4e\u6211\u4e5f\u6e05\u695a\uff0c\u6240\u4ee5\u6211\u81ea\u5df1\u5e73\u5e38\u90fd\u7528\u7684 TCP \u800c\u4e0d\u662f\u8d70 \u7ec4\u597d\u7684 Wireguard Network \u6765\u756a\u8304<\/p>\n<p>\u90a3\u7ec4\u8fd9\u4e2a Wireguard Network \u5230\u5e95\u6709\u5565\u7528\u5462&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n<p><span style=\"color: #ffffff;\">\u800c\u4e14wtm\u4f5c\u4e1a\u4e0d\u662f\u8fd8\u6ca1\u5199\u5b8c\u5417\uff0c\u6b63\u503cnmd\u9ad8\u8003\u4e4b\u9645<\/span><\/p>\n<p>\u554a\uff0c\u53ef\u80fd\u5c31\u662f\u7ec4\u7740\u5f00\u5fc3\u5427<\/p>\n<p><span style=\"color: #ffffff;\">\u6df1\u6e2f 3.4ms\uff0c<del>\u503e\u5bb6\u8361\u4ea7<\/del><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1551 size-full\" src=\"https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/B6GO3RAVK_8FPWSVXMVNF-e1594102933252.png\" alt=\"\" width=\"549\" height=\"184\" srcset=\"https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/B6GO3RAVK_8FPWSVXMVNF-e1594102933252.png 549w, https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/B6GO3RAVK_8FPWSVXMVNF-e1594102933252-300x101.png 300w, https:\/\/0.mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/B6GO3RAVK_8FPWSVXMVNF-e1594102933252-150x50.png 150w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u81ea\u5200\u4e86\u4e00\u4e2a\u6df1\u6e2f IPLC\uff08\u5403\u4e0d\u8d77\u996d\u5566\uff09\uff0c\u5206\u6709\u6df1\u5733\u7aef\u548c\u9999\u6e2f\u7aef\u4e24\u516c\u7f51 IP \u548c\u4e24\u5185\u7f51 IP\uff0c\u5185\u7f51\u8d70\u7684\u662f IPL &hellip; <a href=\"https:\/\/0.mnihyc.com\/blog\/archives\/1542\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">Wireguard Network, Chaining and Routing<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,21],"tags":[],"class_list":["post-1542","post","type-post","status-publish","format-standard","hentry","category-other","category-tools"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Wireguard Network, Chaining and Routing - mnihyc&#039;s Blog<\/title>\n<meta name=\"description\" content=\"\u6700\u8fd1\u81ea\u5200\u4e86\u4e00\u4e2a\u6df1\u6e2f IPLC\uff08\u5403\u4e0d\u8d77\u996d\u5566\uff09\uff0c\u5206\u6709\u6df1\u5733\u7aef\u548c\u9999\u6e2f\u7aef\u4e24\u516c\u7f51 IP \u548c\u4e24\u5185\u7f51 IP\uff0c\u5185\u7f51\u8d70\u7684\u662f IPLC\u3002\u5982\u679c\u53ea\u7528 NAT \/ Port Forwarding \u7684\u8bdd\u672a\u514d\u4e5f\u592a\u900a\u4e86\u70b9\uff0c\u5bf9\u4e0d\u8d77\u6211\u8fd9\u4e2a\u94b1\u554a\uff08\u4e0dx\uff09\uff01\u4e8e\u662f\u5c31\u5c1d\u8bd5\u901a\u8fc7\u4e00\u4e9b\u5947\u5999\u7684\u64cd\u4f5c\u60f3\u628a\u5b83\u4eec \u201c\u4e32\u201d\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/0.mnihyc.com\/blog\/archives\/1542\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Wireguard Network, Chaining and Routing - mnihyc&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"\u6700\u8fd1\u81ea\u5200\u4e86\u4e00\u4e2a\u6df1\u6e2f IPLC\uff08\u5403\u4e0d\u8d77\u996d\u5566\uff09\uff0c\u5206\u6709\u6df1\u5733\u7aef\u548c\u9999\u6e2f\u7aef\u4e24\u516c\u7f51 IP \u548c\u4e24\u5185\u7f51 IP\uff0c\u5185\u7f51\u8d70\u7684\u662f IPLC\u3002\u5982\u679c\u53ea\u7528 NAT \/ Port Forwarding \u7684\u8bdd\u672a\u514d\u4e5f\u592a\u900a\u4e86\u70b9\uff0c\u5bf9\u4e0d\u8d77\u6211\u8fd9\u4e2a\u94b1\u554a\uff08\u4e0dx\uff09\uff01\u4e8e\u662f\u5c31\u5c1d\u8bd5\u901a\u8fc7\u4e00\u4e9b\u5947\u5999\u7684\u64cd\u4f5c\u60f3\u628a\u5b83\u4eec \u201c\u4e32\u201d\" \/>\n<meta property=\"og:url\" content=\"https:\/\/0.mnihyc.com\/blog\/archives\/1542\" \/>\n<meta property=\"og:site_name\" content=\"mnihyc&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-07T01:08:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-07T06:22:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png\" \/>\n<meta name=\"author\" content=\"mnihyc\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mnihyc\" \/>\n<meta name=\"twitter:site\" content=\"@mnihyc\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"mnihyc\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542#article\",\"isPartOf\":{\"@id\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542\"},\"author\":{\"name\":\"mnihyc\",\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751\"},\"headline\":\"Wireguard Network, Chaining and Routing\",\"datePublished\":\"2020-07-07T01:08:41+00:00\",\"dateModified\":\"2020-07-07T06:22:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542\"},\"wordCount\":873,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751\"},\"image\":{\"@id\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png\",\"articleSection\":[\"\u5176\u5b83\",\"\u5de5\u5177\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/0.mnihyc.com\/blog\/archives\/1542#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542\",\"url\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542\",\"name\":\"Wireguard Network, Chaining and Routing - mnihyc&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542#primaryimage\"},\"image\":{\"@id\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png\",\"datePublished\":\"2020-07-07T01:08:41+00:00\",\"dateModified\":\"2020-07-07T06:22:48+00:00\",\"description\":\"\u6700\u8fd1\u81ea\u5200\u4e86\u4e00\u4e2a\u6df1\u6e2f IPLC\uff08\u5403\u4e0d\u8d77\u996d\u5566\uff09\uff0c\u5206\u6709\u6df1\u5733\u7aef\u548c\u9999\u6e2f\u7aef\u4e24\u516c\u7f51 IP \u548c\u4e24\u5185\u7f51 IP\uff0c\u5185\u7f51\u8d70\u7684\u662f IPLC\u3002\u5982\u679c\u53ea\u7528 NAT \/ Port Forwarding \u7684\u8bdd\u672a\u514d\u4e5f\u592a\u900a\u4e86\u70b9\uff0c\u5bf9\u4e0d\u8d77\u6211\u8fd9\u4e2a\u94b1\u554a\uff08\u4e0dx\uff09\uff01\u4e8e\u662f\u5c31\u5c1d\u8bd5\u901a\u8fc7\u4e00\u4e9b\u5947\u5999\u7684\u64cd\u4f5c\u60f3\u628a\u5b83\u4eec \u201c\u4e32\u201d\",\"breadcrumb\":{\"@id\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/0.mnihyc.com\/blog\/archives\/1542\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542#primaryimage\",\"url\":\"https:\/\/mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png\",\"contentUrl\":\"https:\/\/mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/0.mnihyc.com\/blog\/archives\/1542#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/mnihyc.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Wireguard Network, Chaining and Routing\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mnihyc.com\/blog\/#website\",\"url\":\"https:\/\/mnihyc.com\/blog\/\",\"name\":\"mnihyc&#039;s Blog\",\"description\":\"Welcome!\",\"publisher\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mnihyc.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751\",\"name\":\"mnihyc\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8d111f863afc3f98816bc96220f97077d470a96f41088de9f19530fc480f8e72?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8d111f863afc3f98816bc96220f97077d470a96f41088de9f19530fc480f8e72?s=96&d=mm&r=g\",\"caption\":\"mnihyc\"},\"logo\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Wireguard Network, Chaining and Routing - mnihyc&#039;s Blog","description":"\u6700\u8fd1\u81ea\u5200\u4e86\u4e00\u4e2a\u6df1\u6e2f IPLC\uff08\u5403\u4e0d\u8d77\u996d\u5566\uff09\uff0c\u5206\u6709\u6df1\u5733\u7aef\u548c\u9999\u6e2f\u7aef\u4e24\u516c\u7f51 IP \u548c\u4e24\u5185\u7f51 IP\uff0c\u5185\u7f51\u8d70\u7684\u662f IPLC\u3002\u5982\u679c\u53ea\u7528 NAT \/ Port Forwarding \u7684\u8bdd\u672a\u514d\u4e5f\u592a\u900a\u4e86\u70b9\uff0c\u5bf9\u4e0d\u8d77\u6211\u8fd9\u4e2a\u94b1\u554a\uff08\u4e0dx\uff09\uff01\u4e8e\u662f\u5c31\u5c1d\u8bd5\u901a\u8fc7\u4e00\u4e9b\u5947\u5999\u7684\u64cd\u4f5c\u60f3\u628a\u5b83\u4eec \u201c\u4e32\u201d","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/0.mnihyc.com\/blog\/archives\/1542","og_locale":"zh_CN","og_type":"article","og_title":"Wireguard Network, Chaining and Routing - mnihyc&#039;s Blog","og_description":"\u6700\u8fd1\u81ea\u5200\u4e86\u4e00\u4e2a\u6df1\u6e2f IPLC\uff08\u5403\u4e0d\u8d77\u996d\u5566\uff09\uff0c\u5206\u6709\u6df1\u5733\u7aef\u548c\u9999\u6e2f\u7aef\u4e24\u516c\u7f51 IP \u548c\u4e24\u5185\u7f51 IP\uff0c\u5185\u7f51\u8d70\u7684\u662f IPLC\u3002\u5982\u679c\u53ea\u7528 NAT \/ Port Forwarding \u7684\u8bdd\u672a\u514d\u4e5f\u592a\u900a\u4e86\u70b9\uff0c\u5bf9\u4e0d\u8d77\u6211\u8fd9\u4e2a\u94b1\u554a\uff08\u4e0dx\uff09\uff01\u4e8e\u662f\u5c31\u5c1d\u8bd5\u901a\u8fc7\u4e00\u4e9b\u5947\u5999\u7684\u64cd\u4f5c\u60f3\u628a\u5b83\u4eec \u201c\u4e32\u201d","og_url":"https:\/\/0.mnihyc.com\/blog\/archives\/1542","og_site_name":"mnihyc&#039;s Blog","article_published_time":"2020-07-07T01:08:41+00:00","article_modified_time":"2020-07-07T06:22:48+00:00","og_image":[{"url":"https:\/\/mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png","type":"","width":"","height":""}],"author":"mnihyc","twitter_card":"summary_large_image","twitter_creator":"@mnihyc","twitter_site":"@mnihyc","twitter_misc":{"\u4f5c\u8005":"mnihyc","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/0.mnihyc.com\/blog\/archives\/1542#article","isPartOf":{"@id":"https:\/\/0.mnihyc.com\/blog\/archives\/1542"},"author":{"name":"mnihyc","@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751"},"headline":"Wireguard Network, Chaining and Routing","datePublished":"2020-07-07T01:08:41+00:00","dateModified":"2020-07-07T06:22:48+00:00","mainEntityOfPage":{"@id":"https:\/\/0.mnihyc.com\/blog\/archives\/1542"},"wordCount":873,"commentCount":0,"publisher":{"@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751"},"image":{"@id":"https:\/\/0.mnihyc.com\/blog\/archives\/1542#primaryimage"},"thumbnailUrl":"https:\/\/mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png","articleSection":["\u5176\u5b83","\u5de5\u5177"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/0.mnihyc.com\/blog\/archives\/1542#respond"]}]},{"@type":"WebPage","@id":"https:\/\/0.mnihyc.com\/blog\/archives\/1542","url":"https:\/\/0.mnihyc.com\/blog\/archives\/1542","name":"Wireguard Network, Chaining and Routing - mnihyc&#039;s Blog","isPartOf":{"@id":"https:\/\/mnihyc.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/0.mnihyc.com\/blog\/archives\/1542#primaryimage"},"image":{"@id":"https:\/\/0.mnihyc.com\/blog\/archives\/1542#primaryimage"},"thumbnailUrl":"https:\/\/mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png","datePublished":"2020-07-07T01:08:41+00:00","dateModified":"2020-07-07T06:22:48+00:00","description":"\u6700\u8fd1\u81ea\u5200\u4e86\u4e00\u4e2a\u6df1\u6e2f IPLC\uff08\u5403\u4e0d\u8d77\u996d\u5566\uff09\uff0c\u5206\u6709\u6df1\u5733\u7aef\u548c\u9999\u6e2f\u7aef\u4e24\u516c\u7f51 IP \u548c\u4e24\u5185\u7f51 IP\uff0c\u5185\u7f51\u8d70\u7684\u662f IPLC\u3002\u5982\u679c\u53ea\u7528 NAT \/ Port Forwarding \u7684\u8bdd\u672a\u514d\u4e5f\u592a\u900a\u4e86\u70b9\uff0c\u5bf9\u4e0d\u8d77\u6211\u8fd9\u4e2a\u94b1\u554a\uff08\u4e0dx\uff09\uff01\u4e8e\u662f\u5c31\u5c1d\u8bd5\u901a\u8fc7\u4e00\u4e9b\u5947\u5999\u7684\u64cd\u4f5c\u60f3\u628a\u5b83\u4eec \u201c\u4e32\u201d","breadcrumb":{"@id":"https:\/\/0.mnihyc.com\/blog\/archives\/1542#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/0.mnihyc.com\/blog\/archives\/1542"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/0.mnihyc.com\/blog\/archives\/1542#primaryimage","url":"https:\/\/mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png","contentUrl":"https:\/\/mnihyc.com\/blog\/wp-content\/uploads\/2020\/07\/GTHU7FBYZDLSZKHB.png"},{"@type":"BreadcrumbList","@id":"https:\/\/0.mnihyc.com\/blog\/archives\/1542#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/mnihyc.com\/blog"},{"@type":"ListItem","position":2,"name":"Wireguard Network, Chaining and Routing"}]},{"@type":"WebSite","@id":"https:\/\/mnihyc.com\/blog\/#website","url":"https:\/\/mnihyc.com\/blog\/","name":"mnihyc&#039;s Blog","description":"Welcome!","publisher":{"@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mnihyc.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751","name":"mnihyc","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8d111f863afc3f98816bc96220f97077d470a96f41088de9f19530fc480f8e72?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8d111f863afc3f98816bc96220f97077d470a96f41088de9f19530fc480f8e72?s=96&d=mm&r=g","caption":"mnihyc"},"logo":{"@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/0.mnihyc.com\/blog\/wp-json\/wp\/v2\/posts\/1542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/0.mnihyc.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/0.mnihyc.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/0.mnihyc.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/0.mnihyc.com\/blog\/wp-json\/wp\/v2\/comments?post=1542"}],"version-history":[{"count":0,"href":"https:\/\/0.mnihyc.com\/blog\/wp-json\/wp\/v2\/posts\/1542\/revisions"}],"wp:attachment":[{"href":"https:\/\/0.mnihyc.com\/blog\/wp-json\/wp\/v2\/media?parent=1542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/0.mnihyc.com\/blog\/wp-json\/wp\/v2\/categories?post=1542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/0.mnihyc.com\/blog\/wp-json\/wp\/v2\/tags?post=1542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}