ããã«ã¡ã¯ããã¯ãã«ã«ã°ã«ã¼ãã®æ³ç¬ã§ãã Amazonããã®ãã¼ã¸ã§ç´¹ä»ããã¦ããArticles & Tutorialsã¯å®æçã«èª¿ã¹ã¦åèã«ãã¦ããã®ã§ãããæè¿ã¿ã¤ãã«ã®è¨äºãç´¹ä»ããã¦ãããã¨ã«æ°ã¥ããã®ã§ãç´¹ä»ããã¦é ãã¾ãã
æ¦è¦
VPCä¸ã§ç°å¢ãæ§ç¯ããå ´åã«èãããã¤ã³ãã®ä¸ã¤ã¨ãã¦ãNATã¤ã³ã¹ã¿ã³ã¹ã®åé·åãããã¾ãã NATã¤ã³ã¹ã¿ã³ã¹ã®ãã¦ã³ããµã¼ãã¹ã«å½±é¿ããå ´åã¯ããã¡ãã¨åé·åããå¿ è¦ãããã¾ãã ä»åã®å ãã¿ã®è¨äºã§ã¯ä»¥ä¸ã®æµãã§æ¸ããã¦ãã¾ããã- Amazon VPCã«ã¤ãã¦
- NATã¤ã³ã¹ã¿ã³ã¹ã®ä½¿ãæ¹ã¨åä¸é害ç¹ã«ãªãçç±
- NATã¤ã³ã¹ã¿ã³ã¹ã®åé·åä¾ã¨æ§ç¯æ¹æ³
ç°å¢æ§æ
1.æ£å¸¸æã®æ§æ
以ä¸ã®å³ã«ããããã«ãããªãã¯ï¼ãã©ã¤ãã¼ããµããããããããã§2ã¤ã®AZã使ç¨ãã¦ãã¾ãã ãããªãã¯ãµããããã«ã¯AZæ¯ã«1å°ãã¤NATã¤ã³ã¹ã¿ã³ã¹ãé ç½®ããã¦ãã¦ããã©ã¤ãã¼ããµããããã®EC2ã¤ã³ã¹ã¿ã³ã¹ã¯èªåã¨åãAZã®ãããªãã¯ãµããããã«é ç½®ãããNATã¤ã³ã¹ã¿ã³ã¹ãçµç±ãã¦ã¤ã³ã¿ã¼ãããã«æ¥ç¶ãã¾ãã ãã®éãNATã¤ã³ã¹ã¿ã³ã¹ã¯ç£è¦ã¹ã¯ãªããã§ãäºããæ»æ´»ç£è¦ãã¦ããç¶æ ã«ãªãã¾ãã2.é害çºçæã®æ§æ
NATã¤ã³ã¹ã¿ã³ã¹ã«é害ãçºçããå ´åã¯ã¹ã¯ãªããã«ãã£ã¦ã«ã¼ããã¼ãã«ãæ¸ãæããããããçæ¹ã®NATã¤ã³ã¹ã¿ã³ã¹ãçµç±ãã¦ã¤ã³ã¿ã¼ãããã¸ã¢ã¯ã»ã¹ãã¾ãã3.復æ§æ¹æ³
NATã¤ã³ã¹ã¿ã³ã¹ã«é害ãçºçããå ´åã¯ãããçæ¹ã®NATã¤ã³ã¹ã¿ã³ã¹ãé害ãçºçããNATã¤ã³ã¹ã¿ã³ã¹ã«å¯¾ãã¦Stop/Startãå®è¡ãã¾ãã4.復æ§å®äº
NATã¤ã³ã¹ã¿ã³ã¹ãé害ãã復æ§ããããå度ã«ã¼ããã¼ãã«ãæ¸ãæãããæ£å¸¸ãªç¶æ ã¸ã¨æ»ãã¾ããç°å¢æ§ç¯æ¹æ³
NATã¤ã³ã¹ã¿ã³ã¹ã«å²ãå½ã¦ãIAM Roleãä½æ
2ã¤ã®NATã¤ã³ã¹ã¿ã³ã¹ã¯é害çºçæã«EC2ã®APIãå®è¡ãã¾ãã ã¨ã¯ããã¤ã³ã¹ã¿ã³ã¹å é¨ã«ã¢ã¯ã»ã¹ãã¼IDã¨ã·ã¼ã¯ã¬ãããã¼ã®æ å ±ãä¿åããããªãã®ã§ä»¥ä¸ã®ãããªIAM Roleãä½æãã¾ãã{ "Statement": [ { "Action": [ "ec2:DescribeInstances", "ec2:CreateRoute", "ec2:ReplaceRoute", "ec2:StartInstances", "ec2:StopInstances" ], "Effect": "Allow", "Resource": "*" } ] }
VPCç°å¢ã®ä½æ
æ§æå³ã®ãããªVPCãããã¯ã¼ã¯ãä½æãã¾ãã ãã©ã¤ãã¼ããµããããã®ã«ã¼ããã¼ãã«ã§ã¯ãããã©ã«ãã«ã¼ããåä¸AZã«åå¨ããNATã¤ã³ã¹ã¿ã³ã¹ã«è¨å®ãã¾ãã- ãããªãã¯ãµãããããAZæ¯ã«ä½æï¼åè¨2ã¤ï¼
- ãã©ã¤ãã¼ããµãããããAZæ¯ã«ä½æï¼åè¨2ã¤ï¼
- ãããªãã¯ãµããããã®ã«ã¼ããã¼ãã«ãä½æ
- ãã©ã¤ãã¼ããµããããã®ã«ã¼ããã¼ãã«ããµããããæ¯ã«ä½æï¼åè¨2ã¤ï¼
NATç¨ã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦Amazon Linuxãèµ·å
ä½æããIAM Roleãå²ãå½ã¦ãèµ·åå¾ã«Source/Dist CheckãDisableã«ãã¦ä¸ããã â»ãããªãã¯ãµããããå ã«èµ·åãã¾ããèµ·åããAmazon LinuxãNATã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦ã»ããã¢ãã
2å°ã®NATã¤ã³ã¹ã¿ã³ã¹ã«ä»¥ä¸ã®ãããªã³ãã³ããå®è¡ãã¦ããã¾ãã$ sudo -s # cd /root # yum update aws* # echo 1 > /proc/sys/net/ipv4/ip_forward # echo 0 > /proc/sys/net/ipv4/conf/eth0/send_redirects # /sbin/iptables -t nat -A POSTROUTING -o eth0 -s 0.0.0.0/0 -j MASQUERADE # /sbin/iptables-save > /etc/sysconfig/iptables # mkdir -p /etc/sysctl.d/ # cat < /etc/sysctl.d/nat.conf net.ipv4.ip_forward = 1 net.ipv4.conf.eth0.send_redirects = 0 EOF
ã¹ã¯ãªããããã¦ã³ãã¼ãããã¹ã¯ãªããã®è¨å®ãè¡ã
2å°ã®NATã¤ã³ã¹ã¿ã³ã¹ã§ä»¥ä¸ã®ããã«ã¹ã¯ãªããããã¦ã³ãã¼ãããå®è¡æ¨©éãå²ãå½ã¦ã¾ãã# wget http://media.amazonwebservices.com/articles/nat_monitor_files/nat_monitor.sh # chmod a+x nat_monitor.shã¹ã¯ãªããå ã«ä»¥ä¸ã®ãããªãã©ã¡ã¼ã¿ã®è¨å®ããã¾ãã
- NAT_ID=対åå´ã®NATã¤ã³ã¹ã¿ã³ã¹ID
- NAT_RT_ID=NATæã«å¯¾åã®NATã¤ã³ã¹ã¿ã³ã¹ãçµç±ããã«ã¼ãã£ã³ã°ãã¼ãã«
- My_RT_ID=NATæã«èªåèªèº«ãçµç±ããã«ã¼ãã£ã³ã°ãã¼ãã«
- EC2_URL=ãªã¼ã¸ã§ã³ãæå®ï¼ä¾ï¼https://ec2.us-east-1.amazonaws.comï¼
- Num_Pings
- Ping_Timeout
- Wait_Between_Pings
- Wait_for_Instance_Stop
- Wait_for_Instance_Start
ã¹ã¯ãªããã®éå§
èµ·åæã«å®è¡ããããã«cronç»é²ãã# echo '@reboot /root/nat_monitor.sh >> /tmp/nat_monitor.log' | crontabããã¯ã°ã©ã¦ã³ãã¸ã§ãã§ã¹ã¯ãªãããå®è¡ããã
# ./nat_monitor.sh >> /tmp/nat_monitor.log &
åä½ç¢ºèª
ã¤ã³ã¹ã¿ã³ã¹ã«é害ãçºçããã¦åãæ¿ã試é¨ããã¦ã¿ã¾ããã ãã©ã¤ãã¼ããµããããããpingãå®è¡ãã¦ããã¨ãicmp_seq=11ã21ãæãã¦ãã¾ãã ãã®å¾icmp_seq=22ããéä¿¡ã復æ§ãã¦ããäºãåããã¾ãã ã«ã¼ããã¼ãã«ãåãæ»ãããé¨åã«é¢ãã¦ã¯ç¹ã«pingããã¹ããäºã¯ããã¾ããã§ããã$ ping google.co.jp PING google.co.jp (74.125.228.87) 56(84) bytes of data. 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=1 ttl=52 time=3.21 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=2 ttl=52 time=3.11 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=3 ttl=52 time=3.18 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=4 ttl=52 time=3.49 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=5 ttl=52 time=3.16 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=6 ttl=52 time=3.15 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=7 ttl=52 time=3.13 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=8 ttl=52 time=3.36 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=9 ttl=52 time=3.25 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=10 ttl=52 time=3.74 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=22 ttl=54 time=12.3 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=23 ttl=54 time=42.3 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=24 ttl=54 time=4.15 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=25 ttl=54 time=4.14 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=26 ttl=54 time=4.36 ms ==ä¸ç¥== 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=145 ttl=54 time=4.21 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=146 ttl=54 time=4.69 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=147 ttl=54 time=4.23 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=148 ttl=54 time=4.25 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=149 ttl=54 time=4.41 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=150 ttl=54 time=19.5 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=151 ttl=54 time=5.67 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=152 ttl=54 time=4.45 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=153 ttl=54 time=4.36 ms 64 bytes from iad23s07-in-f23.1e100.net (74.125.228.87): icmp_seq=154 ttl=54 time=4.21 ms