ããã«ã¡ã¯AWSãã¼ã ã®æ³ç¬ã§ãã 12æã«ãªã£ã¦æè¡ç³»ã®Advent Calendarãçãä¸ãã£ã¦ããã¾ãããç§ãAWS Advent Calendar 2012ã®6æ¥ç®ãæ å½ãã¦ããã®ã§ããã¡ãã§æ´æ°ããã¦é ãã¾ãï¼ æè¿ãããã®ããã°ã¨ã³ããªã¼ã®æ§åãå¤ãªã®ã§ãããç§ã¯æ°ã®å©ããããã°ãã¿ã¤ãã«ãã¤ããäºã¯è¦æãªã®ã§ããã¤ãã©ããæ¸ãããã¨æãã¾ãã å ãã¿ã¯ãã¡ãã¨ãªã£ã¦ããã以ä¸ã«ã¾ã¨ããå 容ãè¨è¼ãã¦ããã¾ãã
ãããã¯ã¹
- æ¦è¦
- Amazon VPCã®æ§æè¦ç´
- VPCã®è¨å®ä¾
- ãã®ä»ã®ãã¤ã³ã
- æ§æãã¥ã¼ããªã¢ã«
- EC2ã¤ã³ã¹ã¿ã³ã¹ã®èµ·åæ¹æ³
- EC2ä¸ã§VPNãµã¼ããæ§æããæ¹æ³
- æ¥ç¶ãã¹ã
- ããã«ä»ã®VPCã¨æ¥ç¶ããå ´å
- ä»é² VPNã®ã¤ã³ã¹ã¿ã³ã¹ã®HAã¢ã¼ããã¯ãã£
- VPNã¨VPNã¤ã³ã¹ã¿ã³ã¹ã®ç£è¦
- ã¾ã¨ã
æ¦è¦
Amazon Virtual Private Cloud ï¼Amazon VPCï¼ã¯é¡§å®¢ã«é©ç°çã«æè»ãªã«ã¼ãã£ã³ã°ãæä¾ãã¾ãã ãã®ããã¥ã¡ã³ãã¯VPCå ã®ã¤ã³ã¹ã¿ã³ã¹ãã·ã¼ã ã¬ã¹ã«ãã©ã¤ãã¼ãIPã¢ãã¬ã¹ã使ã£ã¦ç¸äºã«æ¥ç¶ããäºãã§ãããã大ããªä»®æ³ãã©ã¤ãã¼ããããã¯ã¼ã¯ã«è¤æ°ã®VPCãæ¥ç¶ããããã®å®å ¨ãªSSLãã³ãã«ï¼Open VPNã使ç¨ãã¾ãï¼ãä½ãæ¹æ³ã示ãã¾ãã
Amazon VPCã®æ§æè¦ç´
Amazon VPCã®ããã¥ã¢ã«ã«ã¤ãã¦ã¯Amazon Virtual Private Cloud管çè ã¬ã¤ããåç §ãã¦ä¸ããã ã¨ã¯ããä¸è¨ã®å®ç¾©ãæ§æä¾ãå³ãªã©ã管çè ã¬ã¤ãã®å 容ãç解ããããã«åèã«ãªãã¨æãã¾ãã Internet Gateway (IGW) IGWã¯Elastic IPã¨VPCã¤ã³ã¹ã¿ã³ã¹ããããã³ã°åºæ¥ãããã«ããããã«å¿ è¦ãªãVPCããã®åºå£ã¨ãªãã¾ãã IGWã¯åVPCã¤ã³ã¹ã¿ã³ã¹ãäºãã«éä¿¡ã§ããããã«ããã«ããããªãã¯ã¢ãã¬ã¹ã¸ã®ãããã³ã°ãæä¾ããå½¹å²ãæã¡ã¾ãã ç°ãªãAWSãªã¼ã¸ã§ã³éã§VPCå士ãéä¿¡ããæã«ãIGWã¯ã¤ã³ã¿ã¼ãããã使ç¨ãã¦éä¿¡ãã«ã¼ãã£ã³ã°ãã¾ãã ããããåä¸AWSãªã¼ã¸ã§ã³ã§VPCå士ãéä¿¡ããæã«ã¯ãIGWã¯AWSå ã®ãããã¯ã¼ã¯ã§éä¿¡ãã«ã¼ãã£ã³ã°ãã¾ãã SSL Connection 2ã¤ã®VPCãããã¯ã¼ã¯ã®æ¥ç¶ã«ã¯ãEC2ã¤ã³ã¹ã¿ã³ã¹ã使ç¨ããOpenVPNã«ããSSLéä¿¡ã使ããã¾ãã ãã®ã¬ã¤ãã§ã¯ä¾ã¨ãã¦ä»¥ä¸ã®è¨å®ã使ç¨ãã¾ãã
VPCã®è¨å®ä¾
ãã®ã¬ã¤ãã¯è¨å®ä¾ã¨ãã¦ä»¥ä¸ã®ãã®ã使ç¨ãã¾ãã
VPN Component | VPC #1 | VPC #2 |
---|---|---|
CIDR | 10.0.0.0/16 | 172.16.0.0/16 |
Public Subnet | 10.0.0.0/24 | 172.16.0.0/24 |
Private Subnet | 10.0.1.0/24 | 172.16.1.0/24 |
VPN Instance Private IP | 10.0.0.5 | 172.16.0.5 |
VPN Instance EIP | EIP #1 | EIP #2 |
ãã®ä»ã®ãã¤ã³ã
- SSLéä¿¡ãããåVPCã¤ã³ã¹ã¿ã³ã¹ã¯Publicãµããããã«é ç½®ããEIPãä»ä¸ãã¾ãã
- VPNã¤ã³ã¹ã¿ã³ã¹ãåä¸é害ç¹ã«ãªãã¾ããåé·åããå ´åã¯ä»é²ãåç §ãã¦ä¸ããã
- æ¬ã¬ã¤ãã§ã¯Amazon Linuxã¨ãã®ããã±ã¼ã¸ã使ç¨ããä¾ã§ç´¹ä»ãã¾ãã
- æ¢ã«2ã¤ã®VPCãä½æãã¦ããäºãåæã§ããVPCã®ä½ææé ã¯ã¹ã¿ã¼ãã¬ã¤ããã覧ãã ããã
- AWSãIGWã管çããã¦ã¼ã¶ã¼ã¯èµ·åããEC2ã¤ã³ã¹ã¿ã³ã¹ã¨ã®VPNæ¥ç¶ã管çãã¾ãã
æ§æã®ãã¥ã¼ããªã¢ã«
ãã®ãã¥ã¼ããªã¢ã«ã§ã¯ä»¥ä¸ã®ã¹ãããã§å®è¡ãã¦ããã¾ãã
- EC2ã§VPNç¨ã¤ã³ã¹ã¿ã³ã¹ãèµ·å
- VPNãµã¼ãã½ããã¦ã§ã¢ãEC2ã¤ã³ã¹ã¿ã³ã¹ã«è¨å®
- å¿ è¦ã«å¿ãã¦ããã«ä»ã®VPCã¨æ¥ç¶
EC2ã§VPNç¨ã¤ã³ã¹ã¿ã³ã¹ãèµ·å
- åVPCã®Public Subnetã«ä»¥ä¸ã®ããã«Amazon Linuxã®EC2ã¤ã³ã¹ã¿ã³ã¹ãèµ·åãã¾ã
- VPNã¤ã³ã¹ã¿ã³ã¹ã«éçã«ãã©ã¤ãã¼ãIPã¢ãã¬ã¹ãå²ãå½ã¦ã¾ãã
- 2ã¤ã®EIPãèµ·åããåVPNã¤ã³ã¹ã¿ã³ã¹ã«å²ãå½ã¦ã¾ãã
- EIPéã®UDP1194ãã¼ãã®éä¿¡ã許å¯ããããã«ã»ãã¥ãªãã£ã°ã«ã¼ãã®è¨å®ããã¾ãã
- VPNã¤ã³ã¹ã¿ã³ã¹ãå³ã¯ãªãã¯ãã¦Change Source/Dest. Checkãdisableã«ãã¾ãã
- ããä¸æ¹ã®VPCã¨éä¿¡ããå ´åã¯VPNã¤ã³ã¹ã¿ã³ã¹ãçµç±ããããã«ã«ã¼ãã£ã³ã°ããã¾ãã
EC2ã¤ã³ã¹ã¿ã³ã¹ã«VPNãµã¼ããè¨å®
VPNãµã¼ã #1 1. VPNã¤ã³ã¹ã¿ã³ã¹ã«æ¥ç¶ãã¦openvpnãã¤ã³ã¹ãã¼ã«
$ sudo yum install openvpn
2 OpenVPNç¨ã®éµãä½æ
$ cd /etc/openvpn/ $ sudo openvpn --genkey --secret ovpn.key
- vpc1-to-vpc2.confã以ä¸ã®ããã«ä½æãã
$ sudo vi /etc/openvpn/vpc1-to-vpc2.conf
# Sample OpenVPN configuration file using a pre-shared static key # Port to use: 1194 is the official IANA port number port 1194 # Use a dynamic tun device. dev tun # Remote peer and network remote EIP #2 route 172.16.0.0 255.255.0.0 # Configure local and remote VPN endpoints ifconfig 169.254.255.1 169.254.255.2 # The pre-shared static key secret ovpn.key
VPNãµã¼ã #2 1. VPNãµã¼ã #1ã§ä½æãã/etc/openvpn/ovpn.keyãå®å ¨ã«ã³ãã¼ãã¦ããã¾ã 2. VPNã¤ã³ã¹ã¿ã³ã¹ã«æ¥ç¶ãã¦openvpnãã¤ã³ã¹ãã¼ã«
$ sudo yum install openvpn
- vpc2-to-vpc1.confã以ä¸ã®ããã«ä½æãã
$ sudo vi /etc/openvpn/vpc2-to-vpc1.conf
# Sample OpenVPN configuration file using a pre-shared static key # Port to use: 1194 is the official IANA port number port 1194 # Use a dynamic tun device. dev tun # Remote peer and network remote EIP #1 route 10.0.0.0 255.255.0.0 # Configure local and remote VPN endpoints ifconfig 169.254.255.2 169.254.255.1 # The pre-shared static key secret ovpn.key
両æ¹ã®VPNã¤ã³ã¹ã¿ã³ã¹ã§ä»¥ä¸ã®è¨å®ãè¡ãã¾ãã 1. OpenVPNãèµ·åãã¾ã
$ sudo service openvpn start
- OpenVPNã®èªåèµ·åè¨å®ããã¾ã
$ sudo chkconfig openvpn on
- /etc/sysctl.confã®net.ipv4.ip_forwardã0ãã1ã«å¤æ´ãã¾ã
$ sudo cp -R /etc/sysctl.conf /etc/sysctl.conf-org $ sudo vi /etc/sysctl.conf
$ diff -u /etc/sysctl.conf-org /etc/sysctl.conf --- /etc/sysctl.conf-org 2012-11-21 07:14:26.399544018 +0000 +++ /etc/sysctl.conf 2012-11-21 07:14:48.546369761 +0000 @@ -4,7 +4,7 @@ # sysctl.conf(5) for more details. # Controls IP packet forwarding -net.ipv4.ip_forward = 0 +net.ipv4.ip_forward = 1 # Controls source route verification net.ipv4.conf.default.rp_filter = 1
- ãããã¯ã¼ã¯ãåèµ·åãã¦è¨å®ãåæ ããã¾ã
$ sudo service network restart
æ¥ç¶ãã¹ã
VPCéã®æ¥ç¶ãã¹ããããã¨ãã«ã¯é©åãªã»ãã¥ãªãã£ã°ã«ã¼ãã®ã«ã¼ã«ãè¨å®ãã¦ä¸ããã ã¾ããVPNã¤ã³ã¹ã¿ã³ã¹ãããã³ãã«ãä»ãã¦æ¥ç¶ãã¹ããããå ´åã«ãVPNã¤ã³ã¹ã¿ã³ã¹ã¯ãã®éä¿¡å ã¢ãã¬ã¹ã¨ãã¦ãã³ãã«ã®IPã¢ãã¬ã¹ã使ç¨ããäºã«æ³¨æãã¦ä¸ããã ããã«ãããã³ãã«ãããã¯ã¼ã¯ã§ã«ã¼ããã¼ãã«ãæ´æ°ããäºãªããªã¢ã¼ããã¼ãã¨ã®ãã¹ããããäºãåºæ¥ã¾ãã ãåèã¾ã§ã«VPNãµã¼ãã®ãããã¯ã¼ã¯æ å ±ã¯ä»¥ä¸ã®ããã«ãªãã¨æãã¾ãã
$ ifconfig eth0 Link encap:Ethernet HWaddr 02:BD:B1:21:81:C9 inet addr:10.0.0.5 Bcast:10.0.0.255 Mask:255.255.255.0 inet6 addr: fe80::bd:b1ff:fe21:81c9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:36718 errors:0 dropped:0 overruns:0 frame:0 TX packets:34122 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:6093487 (5.8 MiB) TX bytes:3051189 (2.9 MiB) Interrupt:26 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:169.254.255.1 P-t-P:169.254.255.2 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:19 errors:0 dropped:0 overruns:0 frame:0 TX packets:40 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:1596 (1.5 KiB) TX bytes:3288 (3.2 KiB)
$ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 10.0.0.1 0.0.0.0 UG 0 0 0 eth0 10.0.0.0 * 255.255.255.0 U 0 0 0 eth0 169.254.169.254 * 255.255.255.255 UH 0 0 0 eth0 169.254.255.2 * 255.255.255.255 UH 0 0 0 tun0 172.16.0.0 169.254.255.2 255.255.0.0 UG 0 0 0 tun0
ããã«ä»ã®VPCã¨æ¥ç¶ããå ´å
ããã«ä»ã®VPCã¨æ¥ç¶ãããå ´åã¯ãåæ¥ç¶æ¯ã«ç°ãªããã¼ããæå®ããå½¢ã§/etc/openvpn以ä¸ã®è¨å®ãã¡ã¤ã«ãä½æãããã¨ã§è¿½å ãåºæ¥ã¾ãã ä¾ãã°ãVPC1ä¸ã«åå¨ããEIP1ãå²ãå½ã¦ãããVPNã¤ã³ã¹ã¿ã³ã¹ãVPC3ãVPC4ã¨æ¥ç¶ããå ´åã¯/etc/openvpn以ä¸ã«æ¬¡ã®ãããªãã¡ã¤ã«ãè¨ç½®ãã¾ãã
vpc1-to-vpc2.conf vpc1-to-vpc3.conf vpc1-to-vpc4.conf
ããã追å ã®VPNã¤ã³ã¹ã¿ã³ã¹ãæ¥ç¶ãããå ´åã¯ãovpn.keyãã¡ã¤ã«ã®ã³ãã¼ã ãã§ã¯ãªãä¸è¨#2ã«è©²å½ãããã¡ã¤ã«ãå¿ è¦ï¼ãã¼ãçªå·ã¯å¤æ´ãã¾ãï¼ã¨ãªãã¾ãã ããã«OpenVPNã¯åä¸ã®ããã»ã¹ã使ç¨ãã¦è¤æ°ã®ãã³ãã«æ¥ç¶ãåºæ¥ããµã¼ã/ã¯ã©ã¤ã¢ã³ãã»ã¢ãã«ãæã£ã¦ãã¾ãã ãã®æ§æã«ããå ´åã¯OpenVPNã®ãµã¼ãã¨ã¯ã©ã¤ã¢ã³ããè¨å®ããããã«ãªãã¾ãããããã¥ã¡ã³ãã®ç¯å²ãè¶ ãã¦ããã®ã§å²æãã¾ãã
ä»é²Aï¼VPNã¤ã³ã¹ã¿ã³ã¹ã«ä½¿ç¨ããHAã¢ã¼ããã¯ãã£
2ã¤ã®VPCä¸ã§å®å
¨ãªåé·æ§æãä½æããã¨ãªãã¨ã4å°ã®VPNã¤ã³ã¹ã¿ã³ã¹ã¨VPNæ¥ç¶ããã§ãã¯ããç£è¦ã¤ã³ã¹ã¿ã³ã¹ãæ§ç¯ããå¿
è¦ãããã¾ãã
åä¸AZå
ã«ãããµããããããã®ãã©ãã£ãã¯ã¯ãåä¸AZå
ã§ç¨¼åãããVPNã¤ã³ã¹ã¿ã³ã¹ã«ã«ã¼ãã£ã³ã°ãã¦å
¨ã¦ã®VPNã¤ã³ã¹ã¿ã³ã¹ãåæã«æ´»ç¨ããäºãæ¨å¥¨ãã¾ãã åVPNã¤ã³ã¹ã¿ã³ã¹ã¯åãAZãå
±æããããã«ãVPCãã¯ãã¹ãããããªæ¥ç¶ãæä¾ãã¾ãã æ§æå³ã§ã¯EC2ãå
¨ã¦Public Subnetã§ç¨¼åãã¦ãã¾ããããã¡ããPrivate Subnetã§ç¨¼åãããäºãå¯è½ã§ãã
VPNç£è¦ã¤ã³ã¹ã¿ã³ã¹
VPNã¢ãã¿ç¨ã¤ã³ã¹ã¿ã³ã¹ã¯ç£è¦ã¹ã¯ãªãããä½æãã¦å®è¡ãããã¤ã³ã¹ã¿ã³ã¹ã¨ãªãã¾ãã ãã®ã¤ã³ã¹ã¿ã³ã¹ã®ç¨éã¯VPNã®æ¥ç¶ç£è¦ã¨VPNã¤ã³ã¹ã¿ã³ã¹ã®ç¨¼åç£è¦ã§ãã VPNã¤ã³ã¹ã¿ã³ã¹ãVPNæ¥ç¶ããã¦ã³ããå ´åã復æ§ããã¾ã§ã¯ãã©ãã£ãã¯ãããä¸æ¹ã®VPNã¤ã³ã¹ã¿ã³ã¹ã«ã«ã¼ãã£ã³ã°ããããã«ãã¤ã¤ãVPNã¤ã³ã¹ã¿ã³ã¹ãåèµ·åããããã«ãã¾ãã é害æã«éç¥ãããèªå復æ§ããããã¸ãã¯ãéçºããå¿ è¦ããããã¯ãµã¼ãã¹ã«ããã¾ãã®ã§ãAWSå´ã§ç£è¦ã¤ã³ã¹ã¿ã³ã¹ã«å¿ è¦ãªããã¥ã¡ã³ããã¹ã¯ãªããçã¯æä¾ãããã¾ããã
ã¾ã¨ã
ããããç°ãªãVPCä¸ã§ç¨¼åãã¦ãã¤ã³ã¹ã¿ã³ã¹å士ã§éä¿¡ããè¦ä»¶ãçºçããå ´åãªã©ãæ軽ã«VPCå士ã§éä¿¡ãããäºãåºæ¥ãã®ã§åèã«ãªãã¾ããã ã¾ããè¦ä»¶ã«ãã£ã¦ã¯åé·æ§æãçµãã§éä¿¡ãæé©åãã¤ã¤èé害æ§ãé«ãã¦ã¿ãã®ãé¢ç½ããã§ãã