1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

InterNet GatewayとNat GateWayの動作を比べてみる

Last updated at Posted at 2025-07-12

はじめに

AWSのネットワーク設定をしている時に疑問に思った内容をまとめました。
Publicサブネットは外部からアクセス可能。Privateサブネットはアクセス不可能だから安全
という理解はあったのですが、Natゲートウェイあたりから、外にアクセスできるなら外からもアクセスできて危険なんじゃ?という感じに混乱したので、それぞれの仕組みを調べることにしました。

Public subnetが危険な理由

配置したリソースに対して以下が行われる

  • グローバルIP(パブリックIP)が付与される(実際はinternet gatewayが対応表を作成)
  • 外部からアクセス可能になる
  • Internet Gateway → routing tables参照 → nat変換
    ※ InterNetwork Gatewayは転送先の決定とNAT変換の両方を行う
    routing teble: 0.0.0.0/0 → igw-12345678 「このパケットはInternet Gatewayで処理する」
    NAT変換: 18.xxx.xxx.xxx:80 → 10.0.1.100:80 private IPに変換

private subnetが安全な理由

  • パブリックIPが付与されない
  • 外部から直接アクセス不可能

nat gatewayを通じたprivate subnetからの外部通知が安全な理由

内部から外部へ

  • nat gatewayがprivate ipをglobal ip変換
  • NATテーブルを作成 (10.0.1.100:3000 ⇔ 18.xxx.xxx.xxx:12345)
    ※ 外部へアクセスした際のResponseはNATテーブルに基づいて適切なリソースへ返される

外部から内部へ

  • 対応するNATテーブルエントリが存在しない

InterNet GateWayとNAT GateWayの違い

InterNet GateWay → Routing Table
Nat GateWay → NatTable

終わりに

NAT GateWayを利用すると安全に外部通信できる理由は、NATテーブルの存在にありました。
リソースをprivateに隠しながら、外へのアクセス方法だけ確立することが可能です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?