Ch02 NAT, Port Forwarding and VPN === * NAT * private ip address * 需要 NAT 轉到 public network * 10.0.0.0/8 * 172.16.0.0/12 * 192.168.0.0/16 * 改寫 src/dest ip, port * 功能 * 減緩 ipv4 的 address 數量少太多 * firewall * load balancing * fail over :::warning Q: 這什麼? A: 1. 內部有多台 server 拿 Private IP addr,透過 Public IP addr 存取時 NAT 會導向狀態正常的服務 [name=Sean] 2. 對外接兩家以上的 ISP,內部上網經過 NAT 時如果某家壞了,那就改走另一家網路 [name=Sean] ::: * 種類 * static NAT: 一對一對應 local 和 global address * Dynamic NAT: 從 public ip address pool 中取用 ip * NAT overloading * 透過 port 對應多個 private ip 到一個 public ip * SNAT: 把 private ip 轉到外面 * DNAT: 從外面轉到 private ip * port forwarding: 一個 DNAT 的應用 * 優點 * security * load balance * high availability * 缺點 * NAT traversal problem: 外部的 host 沒辦法開啟對在 NAT 後面的 host,所以開發者需要考量 NAT 的可能性 * VPN(Virtual Private Network) * 用途 * 從遠端連入內網 * 內網連內網 * 從內網中連入更裡面的內網 * tunneling * VPN key enable * 可能會遇到 ipv6 的 network 要傳封包給另一個 ipv6 的 network,但是途中的 router 是 ipv4,所以就會需要 IP-in-IP tunnel ![](https://i.imgur.com/L50l9HX.png) * GRE(Generic Route Encapsulation) Tunnel: 比 IP-in-IP 多了一層 GRE header 在 inner ip header 和 outer ip header 之間。PPTP。用途包含將 inner ip 做處理,再包裝成 outer ip。常見的 portocol 是 IP、PPTP、NHRP。 ![](https://i.imgur.com/0mf4tBG.png) :::warning Q: GRE 是對 inner ip 做了什麼處理? ::: * VXLAN(Virtual Extensible LAN) Tunnel ![](https://i.imgur.com/7Exop9e.png) * Layer 2 VPN * PPTP: Point-to-Point Tunneling Protocol,在 GRE Header 前塞 PPP Header,用來將 inner IP 加密 1. Encapsulation 2. link control protocol 3. network control portocol * Layer 3 VPN * IPsec: Internet Protocol Security * Layer 4 VPN * SSL: Secured Socket Layer :::warning Q: 這些不同的 layer 的 VPN 的定義是什麼,處理 VPN header 的 layer,例如加解密的位置? :::