{"id":389,"date":"2014-07-12T23:19:48","date_gmt":"2014-07-12T15:19:48","guid":{"rendered":"http:\/\/xiaoding.org\/?p=389"},"modified":"2014-07-12T23:19:48","modified_gmt":"2014-07-12T15:19:48","slug":"%e5%9c%a8-edgerouter-lite-%e4%b8%8a%e5%ae%9e%e7%8e%b0%e7%a7%91%e5%ad%a6%e4%b8%8a%e7%bd%91","status":"publish","type":"post","link":"https:\/\/xiaoding.org\/?p=389","title":{"rendered":"\u5728 EdgeRouter Lite \u4e0a\u5b9e\u73b0\u79d1\u5b66\u4e0a\u7f51"},"content":{"rendered":"<p>\u4ece\u6dd8\u5b9d\u4e0a\u4e70\u4e86\u4e00\u4e2a <a title=\"EdgeRouter Lite\" href=\"http:\/\/www.ubnt.com\/edgemax\/edgerouter-lite\/\" target=\"_blank\">Ubiquiti EdgeRouter Lite<\/a>\uff0cmips \u5e73\u53f0\u7684\u8def\u7531\u5668\uff0c\u63d0\u4f9b 3 \u4e2a 1000Mbps \u7f51\u7edc\u63a5\u53e3\u3001\u57fa\u4e8e Debian \u548c Vyatta \u7684 EdgeOS \u64cd\u4f5c\u5e73\u53f0\uff0c\u6700\u91cd\u8981\u7684\u662f\u6709 4GB \u7684\u5185\u7f6e\u5b58\u50a8\u4ee5\u53ca 512MB RAM\uff0c\u8fd9\u4f7f\u5f97\u6b64\u6b3e\u673a\u5668\u7684\u6027\u80fd\u8fdc\u8fdc\u8d85\u8fc7\u90a3\u4e9b\u5237\u4e86 OpenWRT \u7684\u5bb6\u7528\u65e0\u7ebf\u8def\u7531\u3002<\/p>\n<p>\u4e3a\u4e86\u8ba9\u8def\u7531\u6b63\u5e38\u8fd0\u8f6c\uff0c\u9996\u5148\u662f\u914d\u7f6e\u57fa\u672c\u7684\u7f51\u7edc\u670d\u52a1\uff0c\u8fd9\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u914d\u7f6e eth0 \u4e0a\u7684 PPPoE \u62e8\u53f7\u4e0a\u7f51<\/li>\n<li>\u914d\u7f6e eth1 \u548c eth2\uff0c\u6dfb\u52a0\u5230 bridge br0\uff0c\u5e76\u5728 br0 \u4e0a\u914d\u7f6e\u5c40\u57df\u7f51 IP<\/li>\n<li>\u914d\u7f6e br0 \u4e0a\u7684 DHCP \u670d\u52a1\uff0c\u5b9e\u73b0 LAN \u673a\u5668\u81ea\u52a8\u83b7\u53d6 IP<\/li>\n<li>\u914d\u7f6e br0 \u4e0a\u7684 DNS Forward\uff0c\u5728\u5c40\u57df\u7f51\u7f51\u5173\u4e0a\u8f6c\u53d1 DNS \u8bf7\u6c42<\/li>\n<li>\u5728 PPPoE \u63a5\u53e3\u4e0a\u914d\u7f6e NAT \u670d\u52a1\uff0c\u4f7f LAN \u673a\u5668\u80fd\u8bbf\u95ee\u5916\u7f51<\/li>\n<\/ul>\n<p>\u53e6\u5916\uff0c\u4e3a\u4e86\u652f\u6301\u65e0\u7ebf\u7f51\u7edc\uff0c\u9700\u8981\u63a5\u5165\u4e00\u4e2a\u65e0\u7ebf AP\uff0c\u4e00\u822c\u6765\u8bf4\u90fd\u662f\u7528\u5bb6\u7528\u65e0\u7ebf\u8def\u7531\u5668\u5b9e\u73b0\u7684\uff0c\u5177\u4f53\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ul>\n<li>\u5355\u72ec\u914d\u7f6e\u65e0\u7ebf\u8def\u7531\u5668\uff0c\u5173\u6389\u5c40\u57df\u7f51\u4e0a\u7684 DHCP \u670d\u52a1<\/li>\n<li>\u914d\u7f6e\u65e0\u7ebf\u8def\u7531\u5668\u7684 LAN \u7aef IP\uff0c\u4f7f\u4e4b\u4e0e EdgeRouter Lite \u7684 br0 \u4e0d\u5728\u4e00\u4e2a\u7f51\u6bb5\uff08\u5c3d\u91cf\u907f\u514d\u51b2\u7a81\uff09<\/li>\n<li>\u7528\u7f51\u7ebf\u8fde\u63a5 EdgeRouter Lite \u7684 LAN \u53e3\u548c\u65e0\u7ebf\u8def\u7531\u5668\u7684 LAN \u53e3<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u6b65\u9aa4\u7167\u7740\u8bf4\u660e\u548c\u7ecf\u9a8c\uff0c\u5f88\u5feb\u53ef\u4ee5\u5b8c\u6210\uff0c\u8fd9\u6837\u5c31\u5b9e\u73b0\u4e86\u6700\u57fa\u672c\u7684\u57fa\u4e8e NAT \u7684\u5bb6\u5ead\u7f51\u7edc\u670d\u52a1\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u4e3a\u4e86\u79d1\u5b66\u4e0a\u7f51\uff08*\u7ffb*\u5899*\uff09\uff0c\u9700\u8981\u914d\u7f6e tunnel \u548c\u989d\u5916\u7684\u8def\u7531\u3002<\/p>\n<p>\u5173\u4e8e tunnel\uff0c\u7ecf\u4ed4\u7ec6\u7814\u7a76\uff0c\u53d1\u73b0\u53ef\u4ee5\u7528\u4f20\u7edf\u7684 gre, sit \u6216\u8005 ipip \u96a7\u9053\uff0c\u4f46\u8fd9\u4e9b\u670d\u52a1\u6709\u4e00\u4e2a\u7f3a\u70b9\u5c31\u662f\u4e0d\u80fd\u5f88\u597d\u5730\u652f\u6301 PPPoE \u83b7\u53d6\u7684\u52a8\u6001 IP\uff0c\u867d\u7136\u7ecf\u8fc7\u641c\u7d22\uff0c\u6709\u4eba\u5df2\u7ecf\u63d0\u4f9b\u4e86\u5229<a title=\"\u642d\u5efa\u7f51\u5173\u7cfb\u5217 \u2014\u2014 \u96a7\u9053\u7bc7\" href=\"https:\/\/onebitbug.me\/2014\/06\/03\/building-a-gateway-tunnel\/\" target=\"_blank\">\u7528 SSH \u8fdc\u7a0b\u66f4\u65b0\u7684\u601d\u8def\u548c\u65b9\u6848<\/a>\uff0c\u4f46\u662f\u5728 EdgeOS \u7684 vbash shell \u91cc\u6ca1\u6709\u76f4\u63a5\u652f\u6301\uff0c\u5fc5\u987b\u7ed5\u8fc7\u4e0a\u5c42\u7684 EdgeOS \u76f4\u63a5\u5728 Linux OS \u91cc\u5199\u811a\u672c\uff0c\u8fd9\u6837\u672a\u514d\u663e\u5f97\u7565\u5fae\u9ebb\u70e6\u3002EdgeOS \u91cc\u5012\u662f\u76f4\u63a5\u63d0\u4f9b\u4e86 OpenVPN \u7684\u9009\u9879\uff0c\u8fd9\u6837\u4e00\u6765\u76f4\u63a5\u7528 OpenVPN \u5efa\u7acb site-to-site tunnel \u5012\u662f\u4e00\u4e2a\u5f88\u76f4\u63a5\u7684\u65b9\u6848\u3002<\/p>\n<p>\u670d\u52a1\u5668\u7aef\u662f\u4e00\u4e2a\u7c73\u56fd\u7684 VPS\uff0c\u8dd1\u7740 FreeBSD 9.2-RELEASE\uff0c\u5148\u7528 ports \u88c5\u4e0a security\/openvpn\uff0c\u7136\u540e\u5efa\u7acb\u670d\u52a1\u7aef\uff0c\u914d\u7f6e\u6587\u4ef6\u5982\u4e0b\uff0c\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n<pre># use tun device, for a layer-3 tunnel\r\ndev tun\r\n# tunnel over udp for better performance\r\nproto udp\r\n# config tunnel end-point ip for both local and remote\r\nifconfig 10.8.0.1 10.8.0.2\r\n# add route to remote network\r\nroute 10.10.112.0 255.255.255.0 10.8.0.2\r\n# use pre-shared static key since tls negotiation is interrupted\r\n# by the great firewall\r\nsecret static.key\r\n# avoid using default port\r\nport 31194\r\n\r\nverb 3\r\n# enable lzo compression\r\ncomp-lzo\r\n\r\nlog-append \/var\/log\/openvpn.log\r\n# persist tun device and key\r\npersist-tun\r\npersist-key\r\n# run as unprivileged user\r\nuser nobody\r\ngroup nogroup\r\n<\/pre>\n<p>\u63a5\u4e0b\u6765\u662f EdgeRouter Lite \u4e0a\u7684 OpenVPN \u914d\u7f6e\uff0c\u5982\u4e0b<\/p>\n<pre>set interfaces openvpn vtun0 local-address 10.8.0.2\r\nset interfaces openvpn vtun0 local-port 31194\r\nset interfaces openvpn vtun0 mode site-to-site\r\nset interfaces openvpn vtun0 openvpn-option '--comp-lzo '\r\nset interfaces openvpn vtun0 remote-address 10.8.0.1\r\nset interfaces openvpn vtun0 remote-host XXX.XXX.XXX.XXX\r\nset interfaces openvpn vtun0 remote-port 31194\r\nset interfaces openvpn vtun0 shared-secret-key-file \/config\/auth\/static.key\r\n<\/pre>\n<p>\u8fd9\u6837\u96a7\u9053\u5c31\u5efa\u597d\u4e86\uff0c\u901a\u8fc7 \u00a0show interfaces \u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u5230\uff0c\u4e5f\u53ef\u4ee5 ping \u901a tunnel \u7684\u8fdc\u7aef\u5730\u5740\uff0c\u8bf4\u660e\u96a7\u9053\u8fde\u63a5\u662f\u6210\u529f\u7684\u3002<\/p>\n<p>\u4e3a\u4e86\u628a\u96a7\u9053\u5f53\u505a\u51fa\u53e3\uff0c\u9700\u8981\u5728\u8fdc\u7aef\u914d\u7f6e NAT \u670d\u52a1\uff0c\u5bf9\u4e8e FreeBSD \u6765\u8bf4\uff0c\u7528 pf \u6216\u8005 ipfw \u90fd\u5f88\u5bb9\u6613\u505a\u5230\u3002\u4ee5 pf \u4e3a\u4f8b\uff0c\u53ea\u9700\u8981\u4e00\u53e5\u914d\u7f6e\u8bed\u53e5\uff1a<\/p>\n<pre>nat on $external_if from { tun0:peer, $remote_subnet } to any -> $external_if\r\n<\/pre>\n<p>\u968f\u540e\u5728 EdgeRouter Lite \u4e0a\u914d\u7f6e\u8def\u7531\uff0c\u4f7f\u5f97\u8bbf\u95ee Google \u548c Facebook \u7684\u5305\u901a\u8fc7\u96a7\u9053\u51fa\u53bb\u3002\u8fd9\u91cc\u53ef\u4ee5\u7528\u7b56\u7565\u8def\u7531\uff0c\u4e5f\u53ef\u4ee5\u7528\u7b80\u5355\u7684\u9759\u6001\u8def\u7531\u6765\u5b9e\u73b0\u3002\u5173\u952e\u662f\u627e\u5230 Google \u548c Facebook \u7684\u670d\u52a1\u5668 IP \u5730\u5740\u6bb5\u3002<\/p>\n<p>Google \u7684 IP \u5730\u5740\u6bb5\u975e\u5e38\u597d\u627e\uff0c\u5728 Google Help \u4e0a\u63d0\u5230\u4e86\u53ef\u4ee5\u901a\u8fc7 Google \u7684 SPF \u8bb0\u5f55\u6765\u67e5\u627e\u3002\u7b80\u5355\u5730\u5728 cmd \u91cc\u8fd0\u884c nslookup -type=txt _spf.google.com 8.8.4.4 \u00a0\uff0c\u53ef\u4ee5\u770b\u5230\u6709\u4e09\u4e2a netblock\uff0c\u518d\u7528 nslookup \u67e5\u8be2\u4e00\u4e0b\uff0cGoogle \u7684 IP \u5730\u5740\u6bb5\u5c31\u51fa\u6765\u4e86\u3002\uff08\u76ee\u524d\u7b2c\u4e00\u4e2a\u8bb0\u5f55\u662f ipv4 \u5730\u5740\uff0c\u7b2c\u4e8c\u4e2a\u662f ipv6 \u5730\u5740\uff0c\u7b2c\u4e09\u4e2a\u4e3a\u7a7a\uff09<\/p>\n<pre>C:\\Users\\Xiaoding>nslookup -type=txt _netblocks.google.com 8.8.4.4\r\nServer:  google-public-dns-b.google.com\r\nAddress:  8.8.4.4\r\n\r\nNon-authoritative answer:\r\n_netblocks.google.com   text =\r\n\r\n        \"v=spf1 ip4:216.239.32.0\/19 ip4:64.233.160.0\/19 ip4:66.249.80.0\/20 ip4:7\r\n2.14.192.0\/18 ip4:209.85.128.0\/17 ip4:66.102.0.0\/20 ip4:74.125.0.0\/16 ip4:64.18.\r\n0.0\/20 ip4:207.126.144.0\/20 ip4:173.194.0.0\/16 ~all\"\r\n<\/pre>\n<p>Facebook \u7684 IP \u5730\u5740\u6bb5\u5b98\u65b9\u4e5f\u63d0\u4f9b\u4e86\u76f8\u5e94\u7684\u5217\u8868\uff0c\u4e0d\u8fc7\u65b9\u5f0f\u4e0e Google \u7565\u6709\u4e0d\u540c\uff0c\u662f\u53d1\u5e03\u5728 Facebook developers \u7f51\u7ad9\u4e0a\u7684\uff0c\u5728 <a title=\"Facebook content sharing best practice\" href=\"https:\/\/developers.facebook.com\/docs\/opengraph\/howtos\/maximizing-distribution-media-content#crawl\" target=\"_blank\">Facebook content sharing best practice<\/a> \u8fd9\u7bc7\u6587\u7ae0\u4e2d\u76f4\u63a5\u5217\u51fa\u4e86\u5f53\u524d\u7684 IP \u5730\u5740\u6bb5\uff0c\u4e5f\u63d0\u4f9b\u4e86\u547d\u4ee4\u884c\u65b9\u5f0f\u901a\u8fc7\u67e5\u8be2 Facebook \u7684\u81ea\u6cbb\u7cfb\u7edf\uff08AS\uff09\u8def\u7531\u5e7f\u64ad\u6765\u67e5\u8be2\u3002<\/p>\n<blockquote><p>IP whitelisting<\/p>\n<p>Your engineers can allow the following IP addresses access to pages that would otherwise be inaccessible to the public.<\/p>\n<p>31.13.24.0\/21<br \/>\n31.13.64.0\/18<br \/>\n66.220.144.0\/20<br \/>\n69.63.176.0\/20<br \/>\n69.171.224.0\/19<br \/>\n74.119.76.0\/22<br \/>\n103.4.96.0\/22<br \/>\n173.252.64.0\/18<br \/>\n204.15.20.0\/22<br \/>\n2401:db00::\/32<br \/>\n2620:0:1c00::\/40<br \/>\n2a03:2880::\/32<br \/>\nPlease note that these IP ranges can and do change regularly, so you should periodically run the following command to receive an updated list<\/p>\n<p>whois -h whois.radb.net &#8212; &#8216;-i origin AS32934&#8217; | grep ^route<\/p><\/blockquote>\n<p>\u5728 EdgeRouter Lite \u4e0a\u914d\u7f6e\u597d\u8def\u7531\u540e\uff0c\u5c31\u53ef\u4ee5\u6210\u529f\u5730\u901a\u8fc7\u96a7\u9053\u5b9e\u73b0\u201c\u79d1\u5b66\u4e0a\u7f51\u201d\u4e86\u3002<\/p>\n<pre>ubnt@EdgeRouterLite:~$ show firewall modify   GOOGLE_ROUTE\r\n\r\nIPv4 Modify Firewall \"GOOGLE_ROUTE\":\r\n\r\n Active on (br0,IN)\r\n\r\nrule  action   proto     packets  bytes\r\n----  ------   -----     -------  -----\r\n1     modify   all       30128    1699704\r\n  condition - match-DST-NTWRK-GROUP Google\r\n\r\n2     modify   all       1119     175999\r\n  condition - match-DST-NTWRK-GROUP Facebook\r\n\r\n10000 accept   all       379763   22430120\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u6dd8\u5b9d\u4e0a\u4e70\u4e86\u4e00\u4e2a Ubiquiti EdgeRouter Lite\uff0cmips \u5e73\u53f0\u7684\u8def\u7531\u5668\uff0c\u63d0\u4f9b 3 \u4e2a 10 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/xiaoding.org\/?p=389\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u5728 EdgeRouter Lite \u4e0a\u5b9e\u73b0\u79d1\u5b66\u4e0a\u7f51\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[48,50,49],"class_list":["post-389","post","type-post","status-publish","format-standard","hentry","category-tech-misc","tag-edgerouter-lite","tag-vpn","tag-49"],"_links":{"self":[{"href":"https:\/\/xiaoding.org\/index.php?rest_route=\/wp\/v2\/posts\/389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xiaoding.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xiaoding.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xiaoding.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xiaoding.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=389"}],"version-history":[{"count":0,"href":"https:\/\/xiaoding.org\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions"}],"wp:attachment":[{"href":"https:\/\/xiaoding.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xiaoding.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xiaoding.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}