{"id":1951,"date":"2023-10-18T16:29:22","date_gmt":"2023-10-18T07:29:22","guid":{"rendered":"https:\/\/www.kwonline.org\/memo2\/?p=1951"},"modified":"2025-10-20T11:53:18","modified_gmt":"2025-10-20T02:53:18","slug":"create-aws-ec2-nat-instance-with-ubuntu","status":"publish","type":"post","link":"https:\/\/www.kwonline.org\/memo2\/2023\/10\/18\/create-aws-ec2-nat-instance-with-ubuntu\/","title":{"rendered":"Ubuntu \u3067 AWS EC2 \u306e NAT \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u308b"},"content":{"rendered":"<p>&nbsp;<br \/>\nVPC NAT Gateway \u306e\u5229\u7528\u8cbb\u304c\u6bce\u6708 USD 50 \u30c9\u30eb\u304f\u3089\u3044\u639b\u304b\u3063\u3066\u30ef\u30ed\u30a8\u306a\u3044\u306e\u3067\u30e1\u30e2\u3002<br \/>\nt2-nano \u306e Ubuntu \u3067 NAT Instance \u3092\u4f5c\u3063\u3066\u7bc0\u7d04\u3059\u308b\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# Enable IP forwarding\r\nsudo sysctl -w net.ipv4.ip_forward=1\r\n\r\n# Make IP forwarding permanent\r\necho &quot;net.ipv4.ip_forward=1&quot; | sudo tee -a \/etc\/sysctl.conf\r\n\r\n# Configure iptables for NAT\r\n# Replace 'ens5' with your network interface name\r\nsudo iptables -t nat -A POSTROUTING -o ens5 -j MASQUERADE\r\nsudo iptables -A FORWARD -i ens5 -o ens5 -m state --state RELATED,ESTABLISHED -j ACCEPT\r\nsudo iptables -A FORWARD -i ens5 -o ens5 -j ACCEPT\r\n\r\n# Save iptables rules to persist after reboot\r\nsudo apt-get update\r\nsudo apt-get install -y iptables-persistent\r\n# During installation, select 'Yes' to save current rules\r\n\r\n# Or manually save rules\r\nsudo netfilter-persistent save\r\n<\/pre>\n<p>\u6700\u5f8c\u306b\u4e0b\u8a18\u306e\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u8a18\u8f09\u306e <strong>Disable source\/destination checks<\/strong> \u3068\u3001<strong>Update the route table<\/strong> \u3092 AWS \u30b3\u30f3\u30bd\u30fc\u30eb\u4e0a\u3067\u5b9f\u884c\u3059\u308c\u3070 OK.<br \/>\n&nbsp;<br \/>\n<a href=\"https:\/\/docs.aws.amazon.com\/vpc\/latest\/userguide\/VPC_NAT_Instance.html\" rel=\"noopener\" target=\"_blank\">NAT instances &#8211; Amazon Virtual Private Cloud<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; VPC NAT Gateway \u306e\u5229\u7528\u8cbb\u304c\u6bce\u6708 USD 50 \u30c9\u30eb\u304f\u3089\u3044\u639b\u304b\u3063\u3066\u30ef\u30ed\u30a8\u306a\u3044\u306e\u3067\u30e1\u30e2\u3002 t2-nano \u306e Ubuntu \u3067 NAT Instance \u3092\u4f5c\u3063\u3066\u7bc0\u7d04\u3059\u308b\u3002 # Enable I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,8],"tags":[],"class_list":["post-1951","post","type-post","status-publish","format-standard","hentry","category-aws","category-linux"],"_links":{"self":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/comments?post=1951"}],"version-history":[{"count":12,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1951\/revisions"}],"predecessor-version":[{"id":2304,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1951\/revisions\/2304"}],"wp:attachment":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/media?parent=1951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/categories?post=1951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/tags?post=1951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}