{"id":231,"date":"2022-02-28T13:14:34","date_gmt":"2022-02-28T05:14:34","guid":{"rendered":"https:\/\/www.osvlabs.com\/blog\/?p=231"},"modified":"2022-02-28T14:29:11","modified_gmt":"2022-02-28T06:29:11","slug":"aws%e7%b3%bb%e5%88%97-%e5%88%9b%e5%bb%bavpc%e7%bd%91%e7%bb%9c","status":"publish","type":"post","link":"https:\/\/blog.osvlabs.com\/?p=231","title":{"rendered":"AWS\u5b66\u4e60\u7cfb\u5217-\u57fa\u7840\u6982\u5ff5\u548cVPC\u7f51\u7edc"},"content":{"rendered":"<p>\u4e9a\u9a6c\u900a AWS(Amazon Web Service) \u5360\u636e\u5168\u7403\u56db\u6210\u516c\u6709\u4e91\u5e02\u573a\u4efd\u989d(2021\u5e74\u7edf\u8ba1)\uff0c\u6392\u540d\u7b2c\u4e00<\/p>\n<p>\u5305\u542b\u7684\u4ea7\u54c1\u591a\u4f59\u725b\u6bdb<\/p>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220228110738.png\" alt=\"\" \/><\/p>\n<p>\u5f88\u591a\u56fd\u5916\u7528\u6237\u90fd\u5728\u4f7f\u7528AWS\u7684\u4ea7\u54c1\uff0c\u8457\u540d\u7684\u6709S3\uff0cEC2\uff0c\u6240\u6709\u6709\u5fc5\u8981\u4e86\u89e3\u4e00\u4e0b\u3002<\/p>\n<p>\u8fd9\u91cc\u4ecb\u7ecd\u6700\u57fa\u7840\u7684\u4ea7\u54c1\uff0cVPC(Virtual Private Cloud)\uff0c\u865a\u62df\u79c1\u6709\u4e91\u3002<\/p>\n<p>\u5148\u770b\u4e0b\u4e00\u4e9b\u57fa\u7840\u6982\u5ff5<\/p>\n<h2>\u5730\u57df Region<\/h2>\n<p>AWS \u5728\u4e16\u754c\u5404\u5730\u6709\u5f88\u591a\u6570\u636e\u4e2d\u5fc3\uff0c\u4e00\u4e2a Region \u5c31\u662f\u591a\u4e2a\u6570\u636e\u4e2d\u5fc3\u7684\u96c6\u7fa4<\/p>\n<p>\u76ee\u524d\u5728\u4e2d\u56fd\u5927\u9646\u5730\u533a\u6709\u5317\u4eac\u548c\u5b81\u590f\u4e24\u4e2a Region<\/p>\n<h2>\u53ef\u7528\u533a AZ\uff08Availability Zone\uff09<\/h2>\n<p>\u6bcf\u4e2a Region \u4e2d\u5305\u542b\u6570\u4e2a\u72ec\u7acb\u7684\uff0c\u7269\u7406\u5206\u9694\u5f00\u7684 AZ\uff08Availability Zone\uff09\uff0c\u6bcf\u4e2a AZ \u6709\u72ec\u7acb\u7684\u4f9b\u7535\uff0c\u5236\u51b7\uff0c\u5b89\u4fdd\u3002<\/p>\n<p>\u540c\u4e00 Region \u5185 AZ \u4e4b\u95f4\u7531\u9ad8\u5e26\u5bbd\uff0c\u6781\u4f4e\u5ef6\u65f6\u7684\u5149\u7ea4\u7f51\u7edc\u76f8\u8fde\uff0c\u6570\u636e\u4ee5\u52a0\u5bc6\u5f62\u5f0f\u4f20\u8f93\u3002\u5f7c\u6b64\u90fd\u5728 100 \u516c\u91cc\uff0860 \u82f1\u91cc\uff09\u4ee5\u5185\u3002<a href=\"https:\/\/aws.amazon.com\/cn\/about-aws\/global-infrastructure\/regions_az\/?p=ngi&amp;loc=2\">\u53c2\u8003<\/a><\/p>\n<p>\u4f60\u53ef\u4ee5\u7406\u89e3\u4e3a\u5317\u4eac\u662f\u4e00\u4e2aRegion: cn-north-1\uff0c\u5176\u4e2d\u671d\u9633\u533a\u6709\u4e2aAZ:cn-north-1c\uff0c\u6d77\u6dc0\u533a\u6709\u4e2aAZ:cn-north-1d<\/p>\n<p>\u5bb9\u707e\u5907\u4efd\u65f6\uff0c\u91cd\u8981\u7684\u6570\u636e\u53ef\u4ee5\u653e\u5230\u591aAZ\u91cc\uff0c\u5047\u5982\u671d\u9633\u533a\u673a\u623f\u505c\u7535\u6216\u5931\u706b\uff0c\u4e1a\u52a1\u7acb\u9a6c\u8f6c\u5230\u6d77\u6dc0\u533a\u7684\u3002<\/p>\n<h2>\u865a\u62df\u79c1\u6709\u7f51\u7edc VPC<\/h2>\n<p>VPC\uff08Amazon Virtual Private Cloud\uff09\u662f\u7528\u6237\u5728 Region \u4e2d\u81ea\u5b9a\u4e49\u7684\u865a\u62df\u7f51\u7edc\uff0c\u662f\u4e00\u4e2a\u6574\u4f53\u6982\u5ff5\u3002<\/p>\n<p>\u7528\u6237\u53ef\u4ee5\u5728\u4e00\u4e2a Region \u4e2d\u521b\u5efa\u591a\u4e2a VPC\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5728 VPC \u4e2d\u9009\u62e9 IP \u7f51\u6bb5\uff0c\u521b\u5efa Subnet\uff0c\u6307\u5b9a Route Table\uff0c\u63a7\u5236 ACL\uff08Access Control list\uff09\uff0c\u8bbe\u7f6e\u7f51\u5173\u7b49\u3002<\/p>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220228124658.png\" alt=\"\" \/><\/p>\n<p>\u5982\u4e0a\u56fe\uff0c\u6307\u5b9a VPC \u7684IP\u6bb5\u4e3a 172.16.0.0\/16, \u5176\u4e2d\u53c8\u5212\u5206\u4e86\u4e24\u4e2a\u7f51\u6bb5, 172.16.10.10\/32\u4e3a\u516c\u5f00\u7f51\u6bb5\uff0c\u5141\u8bb8\u5916\u90e8\u8bbf\u95ee\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u6211\u4eec\u7684web\u670d\u52a1\uff0c 172.16.20.10\/32 \u4e3a\u79c1\u6709\u7f51\u6bb5\uff0c\u53ef\u4ee5\u90e8\u7f72\u6211\u4eec\u7684\u6570\u636e\u5e93\u7b49\u670d\u52a1\uff0c\u4fdd\u62a4\u6211\u4eec\u7684\u6570\u636e\u3002<\/p>\n<p>\u5176\u4e2d\uff0cIP\u6bb5\u7528CIDR\u8868\u793a\u6cd5<\/p>\n<h2>CIDR<\/h2>\n<p>\u65e0\u7c7b\u522b\u57df\u95f4\u8def\u7531\uff08Classless Inter-Domain Routing\u3001CIDR\uff09\u662f\u4e00\u4e2a\u7528\u4e8e\u7ed9\u7528\u6237\u5206\u914dIP\u5730\u5740\u4ee5\u53ca\u5728\u4e92\u8054\u7f51\u4e0a\u6709\u6548\u5730\u8def\u7531IP\u6570\u636e\u5305\u7684\u5bf9IP\u5730\u5740\u8fdb\u884c\u5f52\u7c7b\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u9075\u4eceCIDR\u89c4\u5219\u7684\u5730\u5740\u6709\u4e00\u4e2a\u540e\u7f00\u8bf4\u660e\u524d\u7f00\u7684\u4f4d\u6570\uff0c\u4f8b\u5982\uff1a192.168.0.0\/16\u3002\u8fd9\u4f7f\u5f97\u5bf9\u65e5\u76ca\u7f3a\u4e4f\u7684IPv4\u5730\u5740\u7684\u4f7f\u7528\u66f4\u52a0\u6709\u6548\u3002<\/p>\n<p>\u521b\u5efa\u5b50\u7f51\u65f6\u8981\u8003\u8651\u4f60\u9700\u8981\u7684\u8d44\u6e90\u6570\u548c\u5177\u4f53\u4e1a\u52a1\uff0c\u6bd4\u5982\u4e0d\u540c\u90e8\u95e8\u4f7f\u7528\u4e0d\u540c\u7684\u7f51\u6bb5\uff0c\u4e0d\u540c\u5206\u516c\u53f8\u4f7f\u7528\u4e0d\u540c\u7684\u7f51\u6bb5\u3002\u8bbe\u7f6e\u4e0d\u540c\u5e94\u7528\u4f7f\u7528\u4e0d\u540c\u7f51\u6bb5\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">IP\/CIDR<\/th>\n<th style=\"text-align: left;\">\u63a9\u7801<\/th>\n<th style=\"text-align: center;\">\u4e3b\u673a\u6570<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">a.b.c.d\/32<\/td>\n<td style=\"text-align: left;\">255.255.255.255<\/td>\n<td style=\"text-align: center;\">1<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">a.b.c.0\/28<\/td>\n<td style=\"text-align: left;\">255.255.255.240<\/td>\n<td style=\"text-align: center;\">16<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">a.b.c.0\/24<\/td>\n<td style=\"text-align: left;\">255.255.255.000<\/td>\n<td style=\"text-align: center;\">256<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">a.b.0.0\/16<\/td>\n<td style=\"text-align: left;\">255.255.000.000<\/td>\n<td style=\"text-align: center;\">65,536<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Subnet<\/h2>\n<p>\u5b50\u7f51\u662f VPC \u4e2d\u7684 IP \u5730\u5740\u8303\u56f4\u3002\u5728\u521b\u5efa VPC \u4e4b\u540e\uff0c\u53ef\u4ee5\u5728\u6bcf\u4e2a\u53ef\u7528\u533a\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u6216\u591a\u4e2a\u5b50\u7f51\u3002<\/p>\n<p>\u5b50\u7f51 Subnet \u5206\u4e3a\u4e24\u79cd Private Subnet \u548c Public Subnet\u3002<\/p>\n<p>\u7b80\u5355\u6765\u8bf4\uff0c\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee internet \u7684 Subnet \u5c31\u662f Private Subnet\uff0c\u80fd\u76f4\u63a5\u8bbf\u95ee internet \u7684\u5c31\u662f Public Subnet\u3002<\/p>\n<p>Private Subnet \u4e5f\u53ef\u4ee5\u901a\u8fc7 NAT \u7684\u65b9\u5f0f\u8bbf\u95ee internet<\/p>\n<p>\u5f53\u6211\u4eec\u5728\u4e00\u4e2a VPC \u4e2d\u521b\u5efa Subnet \u65f6\u9700\u8981\u7ed9 Subnet \u9009\u62e9\u4e00\u4e2a AZ\uff08Availability Zone\uff09\uff0c\u4e00\u4e2a Subnet \u53ea\u80fd\u9009\u62e9\u5efa\u5728\u4e00\u4e2a AZ \u4e2d\u3002<\/p>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220124180035.png\" alt=\"\" \/><\/p>\n<h2>\u5b9e\u6218<\/h2>\n<p>AWS \u8d26\u53f7\u53ef\u4ee5\u7528\u4fe1\u7528\u5361\u514d\u8d39\u7533\u8bf7\uff0c\u5e76\u4e14\u63d0\u4f9b\u4e86\u5f88\u591a\u514d\u8d39\u670d\u52a1\uff0c\u6709\u6548\u671f\u4e00\u5e74<\/p>\n<blockquote>\n<p>\u9700\u8981\u8bf4\u660e\u5927\u9646 Region \u662f\u72ec\u7acb\u7684\uff0c\u653f\u7b56\u539f\u56e0\uff0c\u6570\u636e\u548c\u56fd\u9645\u7ad9\u70b9\u4e0d\u4e92\u901a\uff0c\u53ef\u4ee5\u7528\u4eba\u6c11\u5e01\u652f\u4ed8\uff0c\u4f7f\u7528 <a href=\"https:\/\/aws.amazon.com\/cn\/\">https:\/\/aws.amazon.com\/cn\/<\/a> \u6ce8\u518c\uff0c\u800c\u901a\u8fc7 <a href=\"https:\/\/aws.amazon.com\/\">https:\/\/aws.amazon.com\/<\/a> \u6ce8\u518c\u7684\u9009\u4e0d\u4e86\u4e2d\u56fd\u5927\u9646\u7684Region\uff0c\u4ea7\u751f\u8d39\u7528\u9700\u8981\u7528\u7f8e\u5143\u652f\u4ed8<\/p>\n<\/blockquote>\n<p>\u521b\u5efa\u4e24\u4e2a\u5b50\u7f51<\/p>\n<p>\u4e00\u4e2a\u662f Public Subnet\uff0c\u53ef\u4ee5\u8bbf\u95ee\u56e0\u7279\u7f51\uff0c\u53e6\u4e00\u4e2a\u662f Private Subnet<\/p>\n<p>\u4e00\u4e2a\u662f Private Subnet\uff0c\u4e0d\u80fd\u8bbf\u95ee\u56e0\u7279\u7f51\uff0c\u4f46\u53ef\u4ee5\u8bbf\u95ee\u5185\u7f51 Public Subnet \u4e2d\u7684\u5b9e\u4f8b<\/p>\n<h3>\u521b\u5efaVPC<\/h3>\n<p>\u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u521b\u5efaEC2\u5b9e\u4f8b\u540e\uff0c\u9ed8\u8ba4\u53ef\u4ee5\u8bbf\u95ee\u5916\u7f51\uff0c\u8fd9\u662f\u56e0\u4e3aAWS\u5df2\u7ecf\u4e3a\u6211\u4eec\u521b\u5efa\u4e86\u9ed8\u8ba4\u7684VPC\u548c\u5b50\u7f51\u3002<a href=\"https:\/\/docs.aws.amazon.com\/zh_cn\/vpc\/latest\/userguide\/default-vpc.html\">\u53c2\u8003<\/a>\u3002<\/p>\n<p>\u8fd9\u91cc\u51fa\u4e8e\u5b66\u4e60\u76ee\u7684\uff0c\u65b0\u5efa\u4e00\u4e2aVPC<\/p>\n<p>region: \u4e9a\u592a\u5730\u533a (\u4e1c\u4eac) ap-northeast-1<\/p>\n<p>IPv4 CIDR: 192.168.0.0\/16<\/p>\n<p>name: finley-vpc<\/p>\n<h3>\u521b\u5efa\u4e92\u8054\u7f51\u7f51\u5173<\/h3>\n<p>name: finley-internet-gateway<\/p>\n<p>\u5e76 attach \u5230 finley-vpc \u4e0a<\/p>\n<p>\u8bb0\u4e0b\u8fd9\u4e2aigw\u5f00\u5934\u7684id\uff0c\u7528\u4e8e\u540e\u9762\u914d\u7f6e\u516c\u6709\u5b50\u7f51\u8bbf\u95ee\u5916\u7f51<\/p>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220228131116.png\" alt=\"\" \/><\/p>\n<h3>\u521b\u5efa\u4e09\u4e2a\u5b50\u7f51<\/h3>\n<p>\u5206\u522b\u4e3a public, private, public&amp;private\uff08\u79c1\u7f51\u901a\u8fc7NAT\u8bbf\u95ee\u516c\u7f51\uff09<\/p>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220124205316.png\" alt=\"\" \/><\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">subnet id<\/th>\n<th style=\"text-align: left;\">IPV4 CIDR<\/th>\n<th style=\"text-align: left;\">AZ<\/th>\n<th style=\"text-align: left;\">\u7528\u9014<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">finley-public<\/td>\n<td style=\"text-align: left;\">192.168.0.0\/24<\/td>\n<td style=\"text-align: left;\">ap-northeast-1a<\/td>\n<td style=\"text-align: left;\">\u90e8\u7f72web\u670d\u52a1\u5668<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">finley-private<\/td>\n<td style=\"text-align: left;\">192.168.2.0\/24<\/td>\n<td style=\"text-align: left;\">ap-northeast-1d<\/td>\n<td style=\"text-align: left;\">\u90e8\u7f72\u6570\u636e\u5e93<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">finley-private&amp;public<\/td>\n<td style=\"text-align: left;\">192.168.1.0\/24<\/td>\n<td style=\"text-align: left;\">ap-northeast-1c<\/td>\n<td style=\"text-align: left;\">\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220124210016.png\" alt=\"\" \/><\/p>\n<h3>\u521b\u5efa\u4e24\u4e2a\u8def\u7531\u8868<\/h3>\n<p>\u8def\u7531\u8868\u5305\u542b\u4e00\u7ec4\u79f0\u4e3a\u8def\u7531\u7684\u89c4\u5219\uff0c\u7528\u4e8e\u786e\u5b9a\u6765\u81ea\u5b50\u7f51\u6216\u7f51\u5173\u7684\u7f51\u7edc\u6d41\u91cf\u5b9a\u5411\u5230\u4f55\u5904\u3002<\/p>\n<p>\u8def\u7531\u8868\u5fc5\u987b\u5c5e\u4e8e\u67d0VPC<\/p>\n<p>\u8fd9\u91cc\u521b\u5efa\u4e00\u4e2a\u516c\u6709\u5b50\u7f51\uff0c\u4e00\u4e2a\u79c1\u6709\u5b50\u7f51\u4f46\u53ef\u901a\u8fc7NAT\u8bbf\u95ee\u516c\u7f51<\/p>\n<p>name: finley-public<\/p>\n<p>\u7f16\u8f91\u8def\u7531\u8868<\/p>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220124212059.png\" alt=\"\" \/><\/p>\n<pre><code># \u7b2c\u4e00\u6761\u8868\u793a\u5230192.168.*.*\u7684\u8bf7\u6c42\u4f1a\u53d1\u9001\u81f3VPC\u4e2d\n192.168.0.0\/16  local\n\n# \u7b2c\u4e8c\u6761\u8868\u793a\u5230\u5176\u5b83IP\u7684\u8bf7\u6c42\u4f1a\u53d1\u9001\u81f3IGW\n0.0.0.0\/0   igw-0d1092780f692f46f <\/code><\/pre>\n<p>\u7f16\u8f91\u5b50\u7f51\u5173\u8054<\/p>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220124212211.png\" alt=\"\" \/><\/p>\n<p>\u521b\u5efa\u7b2c\u4e8c\u4e2a\u8def\u7531<\/p>\n<p>name: finley-private<\/p>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220124212410.png\" alt=\"\" \/><\/p>\n<p>\u7f16\u8f91\u5b50\u7f51\u5173\u8054\uff0c\u9009\u62e9finley-private&amp;public<\/p>\n<h3>\u521b\u5efa EC2<\/h3>\n<p>EC2\u5c31\u662f\u5b9e\u4f8b\uff0c\u865a\u62df\u5316\u7684\u670d\u52a1\u5668<\/p>\n<p>EC2\u6709CPU\uff0c\u5185\u5b58\uff0c\u786c\u76d8\u4e0d\u540c\u7684\u914d\u7f6e\u89c4\u683c\uff0c\u521b\u5efaEC2\u65f6\u53ef\u4ee5\u9009\u62e9\u751f\u6210\u4e00\u4e2a\u516c\u7f51IP\u5730\u5740<\/p>\n<p>\u521b\u5efa\u4e24\u4e2a EC2 \uff0c\u5206\u522b\u540d\u4e3a finley-public-ec2\uff0c finley-private-ec2<\/p>\n<p>VPC \u9009\u62e9 finley-vpc<\/p>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220124213225.png\" alt=\"\" \/><\/p>\n<p>\u7533\u8bf7\u5f39\u6027IP\uff0c\u5f97\u5230\u516c\u7f51IP\uff1a52.197.152.165 \u5e76\u5173\u8054\u7ed9 finley-public-ec2<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u5b9e\u4f8b\u540d<\/th>\n<th style=\"text-align: left;\">\u516c\u6709 IPv4 \u5730\u5740<\/th>\n<th style=\"text-align: left;\">\u79c1\u6709 IPv4 \u5730\u5740<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">finley-public-ec2<\/td>\n<td style=\"text-align: left;\">52.197.152.165<\/td>\n<td style=\"text-align: left;\">192.168.0.107<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">finley-private-ec2<\/td>\n<td style=\"text-align: left;\">\u65e0<\/td>\n<td style=\"text-align: left;\">192.168.2.197<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote>\n<p>EIP\uff08Elastic IP\uff09\u662fAWS\u63d0\u4f9b\u7684\u9759\u6001\u516c\u5171IP\u3002\u5b9e\u4f8b\u5373\u4fbf\u88ab\u5220\u9664IP\u4e5f\u4f1a\u4fdd\u7559\uff0c\u56e0\u4e3aIP\u5730\u5740\u4e5f\u662f\u8d44\u6e90\uff0c\u5982\u679cEIP\u6ca1\u6709\u7ed1\u5b9a\u5b9e\u4f8b\u4f1a\u6309\u5c0f\u65f6\u6536\u8d39\uff0c\u4e0d\u7528\u7684\u65f6\u5019\u53ef\u4ee5\u91ca\u653e\u6389<\/p>\n<\/blockquote>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220124214203.png\" alt=\"\" \/><\/p>\n<p>SSH <code>ssh -i &quot;aws-ty-2022.pem&quot; ubuntu@52.197.152.165<\/code> \u767b\u5f55\u5b9e\u4f8b<\/p>\n<blockquote>\n<p>aws-ty-2022.pem \u79c1\u94a5\u662f\u4e4b\u524d\u7533\u8bf7\u8fc7\u7684<\/p>\n<\/blockquote>\n<p>\u68c0\u67e5\u7f51\u7edc\u914d\u7f6e\uff0c\u5b89\u88c5 nginx \u6216 httpd \u5e76\u542f\u52a8\uff0c\u6d4f\u89c8\u5668\u6253\u5f00 52.197.152.165\uff0c\u8bbf\u95ee\u6210\u529f<\/p>\n<pre><code class=\"language-bash\">ubuntu@ip-192-168-0-93:~$ ifconfig\neth0: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 9001\n        inet 192.168.0.93  netmask 255.255.255.0  broadcast 192.168.0.255\n        inet6 fe80::4c3:76ff:feef:971  prefixlen 64  scopeid 0x20&lt;link&gt;\n        ether 06:c3:76:ef:09:71  txqueuelen 1000  (Ethernet)\n        RX packets 2795  bytes 2887062 (2.8 MB)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 1519  bytes 178671 (178.6 KB)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions<\/code><\/pre>\n<p>finley-private-ec2  \u53ea\u6709\u4e00\u4e2a\u79c1\u7f51\u5730\u5740\uff0c\u7531\u4e8e\u6211\u4eec\u9009\u62e9 private \u5b50\u7f51<\/p>\n<p>\u4f1a\u5f97\u5230\u4e00\u4e2a\u79c1\u7f51\u5730\u5740\uff0c\u5982192.168.2.197\uff0c\u5373\u4f7f\u6709\u516c\u7f51IP\uff0c\u4e5f\u65e0\u6cd5\u901a\u8fc7\u4e92\u8054\u7f51\u8bbf\u95ee<\/p>\n<p>\u53ef\u4ee5\u5148\u767b\u5f55 finley-public-ec2 \u5b9e\u4f8b\u518d\u767b\u5f55\u5230\u8fd9\u4e2a\u5185\u7f51\u7684\u5b9e\u4f8b<\/p>\n<pre><code># \u5728\u672c\u673a\u6267\u884c\n## \u4e0a\u4f20\u79c1\u94a5\u5230public ec2\nscp ~\/.ssh\/aws.pem 52.197.152.165:~\n## \u767b\u5f55public ec2\nssh -i ~\/.ssh\/aws.pem 52.197.152.165\n# \u5728 public ec2 \u4e0a\u6267\u884c\nchmod 400 aws.pem\n## \u767b\u5f55private-ec2\nssh -i ~\/.ssh\/aws.pem 192.168.2.197\n# \u8fdb\u5230\u79c1\u7f51\u5b9e\u4f8b\uff0c\u786e\u5b9e\u65e0\u6cd5\u8bbf\u95ee\u4e92\u8054\u7f51\nwget www.baidu.com<\/code><\/pre>\n<h3>\u901a\u8fc7NAT\u7f51\u5173\u4f7f\u79c1\u6709\u5b50\u7f51\u8bbf\u95ee\u4e92\u8054\u7f51<\/h3>\n<p>\u5047\u5982\u6709\u5929\u8fd9\u4e2a\u5185\u7f51\u5b9e\u4f8b\u9700\u8981\u8bbf\u95ee\u516c\u7f51\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ed1\u5b9aNAT\u7684\u65b9\u5f0f<\/p>\n<blockquote>\n<p>\u6ce8\u610f: NAT\u662f\u6309\u5c0f\u65f6\u6536\u8d39\u7684\uff0c\u4e0d\u7528\u65f6\u5019\u53ca\u65f6\u91ca\u653e<\/p>\n<\/blockquote>\n<p>NAT \u7f51\u5173\u662f\u4e00\u79cd\u7f51\u7edc\u5730\u5740\u8f6c\u6362 (NAT) \u670d\u52a1\u3002\u53ef\u4ee5\u4f7f\u7528 NAT \u7f51\u5173\uff0c\u4ee5\u4fbf\u79c1\u6709\u5b50\u7f51\u4e2d\u7684\u5b9e\u4f8b\u53ef\u4ee5\u8fde\u63a5\u5230 VPC \u5916\u90e8\u7684\u670d\u52a1\uff0c\u4f46\u5916\u90e8\u670d\u52a1\u65e0\u6cd5\u542f\u52a8\u4e0e\u8fd9\u4e9b\u5b9e\u4f8b\u7684\u8fde\u63a5\u3002<\/p>\n<p>\u8def\u7531\u5668\u5c06\u4e92\u8054\u7f51\u6d41\u91cf\u4ece\u79c1\u6709\u5b50\u7f51\u4e2d\u7684\u5b9e\u4f8b\u53d1\u9001\u5230 NAT \u7f51\u5173\u3002NAT \u7f51\u5173\u901a\u8fc7\u4f7f\u7528\u81ea\u8eab\u7684\u5f39\u6027 IP \u5730\u5740\u4f5c\u4e3a\u6e90 IP \u5730\u5740\uff0c\u5c06\u6d41\u91cf\u53d1\u9001\u5230\u4e92\u8054\u7f51\u7f51\u5173\u3002<\/p>\n<p>\u9009\u62e9\u4e00\u4e2a\u516c\u6709\u5b50\u7f51\u3002\u8fd9\u91cc\u9009\u62e9\u4e86 finley-public<\/p>\n<p>\u7b49\u72b6\u6001\u53d8\u4e3a available<\/p>\n<p>\u4fee\u6539\u8def\u7531\u8868<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u76ee\u7684\u5730<\/th>\n<th style=\"text-align: left;\">\u76ee\u6807<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">192.168.0.0\/16<\/td>\n<td style=\"text-align: left;\">\u672c\u5730<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">0.0.0.0\/02<\/td>\n<td style=\"text-align: left;\">nat-gateway-id<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6b64\u65f6 finley-private-ec2 \u53ef\u4ee5\u8bbf\u95ee\u4e92\u8054\u7f51\u4e86<\/p>\n<p><img src=\"http:\/\/pek3b.qingstor.com\/hexo-blog\/20220124211624.png\" alt=\"\" \/><\/p>\n<h2>\u603b\u7ed3<\/h2>\n<ul>\n<li>\u9996\u5148\u6211\u4eec\u9009\u62e9Region\uff0c\u968f\u540e\u6240\u6709\u521b\u5efa\u7684\u8d44\u6e90\u90fd\u662f\u5b58\u5728\u6b64Region\u4e2d<\/li>\n<li>\u521b\u5efaVPC\uff0c\u4e00\u4e2a\u865a\u62df\u7f51\u7edc\uff0c\u5728\u91cc\u9762\u8bbe\u7f6eIP\u6bb5\uff0cVPC\u662f\u4e00\u4e2a\u903b\u8f91\u7ed3\u6784\uff0c\u5e76\u4e0d\u548cAZ\uff08Availability Zone\uff09\u76f4\u63a5\u76f8\u5173<\/li>\n<li>\u5728VPC\u4e2d\u521b\u5efaSubnet\uff0c\u9700\u6307\u5b9aIP\u6bb5\uff0c\u5e76\u4e14\u6307\u5b9a\u6240\u5728\u7684AZ\uff0c\u4e00\u4e2aSubnet\u53ea\u80fd\u6307\u5b9a\u4e00\u4e2aAZ\uff0c\u4e00\u4e2aAZ\u53ef\u4ee5\u5bb9\u7eb3\u591a\u4e2aSubnet<\/li>\n<li>VPC\u4e2dSubnet\u9ed8\u8ba4\u662f\u53ef\u4ee5\u76f8\u4e92\u8bbf\u95ee\u7684<\/li>\n<li>\u65b0\u5efa\u7684Subnet\u9ed8\u8ba4\u5c31\u662fPrivate Subnet<\/li>\n<li>IGW(Internet gate way)\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u7ec4\u4ef6\u914d\u7f6e\u5728VPC\u4e0a\uff0c\u4f7f\u5f97VPC\u53ef\u4ee5\u8bbf\u95eeinternet<\/li>\n<li>\u5728Private Subnet\u4e2d\u914d\u7f6e\u4e86\u5230IGW\u7684\u8def\u7531\u540e\uff0c\u5c31\u53d8\u6210Public Subnet<\/li>\n<li>Public Subnet\u4e2d\u7684EC2\u8fd8\u8981\u518d\u914d\u7f6e\u4e00\u4e2aPublic IP\u6216\u8005EIP\u5c31\u53ef\u4ee5\u8bbf\u95eeInternet<\/li>\n<li>\u5982\u679cEC2\u53ef\u4ee5\u8bbf\u95eeinternet\uff0c\u5176\u5173\u8054\u7684Security Group\u5165\u7ad9\u89c4\u5219\u5982\u679c\u5141\u8bb8\u4eceinternet\u8bbf\u95ee\uff0c\u90a3\u4e48\u8fd9\u4e2aEC2\u5c31\u53ef\u4ee5\u4eceinternet\u4e2d\u76f4\u63a5\u8bbf\u95ee\u5230<\/li>\n<li>\u5b9e\u8df5\u4e2d\u6211\u4eec\u628a\u5e94\u7528\u7a0b\u5e8f\uff0c\u6570\u636e\u5e93\u653e\u5728Private Subnet\u4e2d\uff0c\u963b\u6b62\u4eceinternet\u8bbf\u95ee\u3002\u628a\u5821\u5792\u673a\u548cALB\uff08Application Load balancer\uff09\u653e\u5728Public Subnet\uff0c\u5141\u8bb8\u4eceinternet\u8bbf\u95ee<\/li>\n<li>\u914d\u7f6e\u4e86NAT\u8def\u7531\u7684Private Subnet\u4e2dEC2\u53ef\u4ee5\u8bbf\u95eeinternet\uff0c\u4f46\u4e0d\u80fd\u88abinternet\u8bbf\u95ee\u5230,\u56e0\u4e3a\u8fd9\u4e2aEC2\u5e76\u6ca1\u6709IP\uff0c\u6d41\u91cf\u662f\u901a\u8fc7NAT\u8f6c\u6362\u4e86\uff0cNAT\u6709IP<\/li>\n<li>NAT gateway\u9700\u8981\u4e00\u4e2aEIP\uff08Elastic IP\uff09\u5e76\u4e14\u628aNAT\u914d\u7f6e\u5728Public Subnet\u4e2d<\/li>\n<li>\u6709\u65f6\u5019Private Subnet\u4e2d\u7684EC2\u867d\u7136\u4e0d\u80fd\u8bbf\u95ee\u5916\u90e8internet\uff0c\u4e5f\u9700\u8981\u8bbf\u95ee\u7279\u5b9a\u670d\u52a1\u5982S3\uff0cRDS\uff0c\u8fd9\u65f6\u5019\u53ef\u4ee5\u521b\u5efaEnd Point<\/li>\n<li>\u521b\u5efaEnd Point\u9700\u8981\u9009\u62e9Service\u79cd\u7c7b\uff0cVPC,\u8def\u7531\u8868\uff0c\u5b9e\u9645\u4e0a\u4f1a\u5728\u9009\u62e9\u7684\u8def\u7531\u8868\u4e0a\u6dfb\u52a0\u4e00\u6761\u8bb0\u5f55\uff0c\u524d\u7f00\u662fvpce-<\/li>\n<li>\u6bcf\u4e2aSubnet\u90fd\u5fc5\u987b\u5173\u8054\u4e00\u4e2a\u8def\u7531\u8868\uff0c\u521b\u5efa\u7684\u6bcf\u4e2aSubnet\u90fd\u4f1a\u81ea\u52a8\u5173\u8054 VPC \u7684\u4e3b\u8def\u7531\u8868<\/li>\n<li>\u521b\u5efaSecurity Group\u65f6\uff0c\u53ea\u9700\u6307\u5b9aVPC\u3002\u4e4b\u540e\u53ef\u4ee5\u628aSG\u4e0eEC2\uff0c RDS, VPC Endpoint\u76f8\u5173\u8fde\uff0c\u7528\u6765\u63a7\u5236\u8fd9\u4e9b\u670d\u52a1\u7684\u51fa\u5165\u7ad9IP\u548c\u7aef\u53e3<\/li>\n<li>\u6240\u6709 IPv4 \u6d41\u91cf (0.0.0.0\/0)\uff0cIPv6 \u6d41\u91cf (::\/0)<\/li>\n<\/ul>\n<h2>\u53c2\u8003<\/h2>\n<p><a href=\"https:\/\/aws.amazon.com\/cn\/vpc\/faqs\/\">https:\/\/aws.amazon.com\/cn\/vpc\/faqs\/<\/a><\/p>\n<p><a href=\"https:\/\/help.aliyun.com\/document_detail\/54095.html\">https:\/\/help.aliyun.com\/document_detail\/54095.html<\/a><\/p>\n<p><a href=\"https:\/\/docs.aws.amazon.com\/zh_cn\/vpc\/latest\/userguide\/VPC_Subnets.html\">https:\/\/docs.aws.amazon.com\/zh_cn\/vpc\/latest\/userguide\/VPC_Subnets.html<\/a><\/p>\n<p><a href=\"https:\/\/www.bilibili.com\/video\/BV1wk4y1r7gX\">https:\/\/www.bilibili.com\/video\/BV1wk4y1r7gX<\/a><\/p>\n<p><a href=\"https:\/\/www.iloveaws.cn\/3707.html\">https:\/\/www.iloveaws.cn\/3707.html<\/a><\/p>\n<p><a href=\"https:\/\/zh.wikipedia.org\/zh-hans\/%E6%97%A0%E7%B1%BB%E5%88%AB%E5%9F%9F%E9%97%B4%E8%B7%AF%E7%94%B1\">https:\/\/zh.wikipedia.org\/zh-hans\/%E6%97%A0%E7%B1%BB%E5%88%AB%E5%9F%9F%E9%97%B4%E8%B7%AF%E7%94%B1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e9a\u9a6c\u900a AWS(Amazon Web Service) \u5360\u636e\u5168\u7403\u56db\u6210\u516c\u6709\u4e91\u5e02\u573a\u4efd\u989d(2021\u5e74\u7edf\u8ba1)\uff0c\u6392\u540d\u7b2c\u4e00 \u5305\u542b\u7684\u4ea7\u54c1\u591a\u4f59\u725b\u6bdb \u5f88\u591a\u56fd\u5916\u7528\u6237\u90fd\u5728\u4f7f\u7528AWS\u7684\u4ea7\u54c1\uff0c\u8457\u540d\u7684\u6709S3\uff0cEC2\uff0c\u6240\u6709\u6709\u5fc5\u8981\u4e86\u2026<\/p>\n","protected":false},"author":1,"featured_media":233,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":5}},"_links":{"self":[{"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/posts\/231"}],"collection":[{"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=231"}],"version-history":[{"count":6,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/posts\/231\/revisions"}],"predecessor-version":[{"id":238,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/posts\/231\/revisions\/238"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/media\/233"}],"wp:attachment":[{"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}