配置 NAT 以從專用網路存取網際網路
本指導教學說明 標準基礎架構的用法。 大部分工作量都可以使用 IBM Cloud® Virtual Private Cloud 資源來實作。 使用 IBM Cloud VPC 在共用公用雲端基礎架構上建立您自己的專用雲端型運算環境。 VPC 可讓企業定義及控制邏輯上與所有其他公用雲端租戶隔離的虛擬網路,在公用雲端上建立專用且安全的位置。 具體而言,虛擬伺服器實例、 安全群組、網路 ACL 及 公用閘道。
本指導教學可能會產生成本。 使用 成本估算器 根據您的預計使用情況產生成本估算。
在如今以 Web 為基礎的 IT 應用程式和服務世界,幾乎沒有應用程式是孤立存在的。 開發人員開始預期在網際網路上存取服務,無論服務是開放程式碼應用程式碼和更新,還是透過 REST API 提供應用程式功能的「協力廠商」服務。 為了保護從專用網路對網際網路管理之服務的存取,一種常用的方法是網址轉換 (NAT) 假冒。 在 NAT 偽裝中,私人 IP 位址以多對一的關係轉換為出站公共介面的 IP 位址,從而使私人 IP 位址不被公眾看到。
本指導教學顯示如何在虛擬路由器應用裝置 (VRA) 上設定網址轉換 (NAT) masquerade,以連接至 IBM Cloud 專用網路上的安全子網路。 它 以使用安全專用網路隔離工作負載 教程為基礎,添加了來源 NAT (SNAT) 配置,其中來源位址被混淆,並使用防火牆規則來保護出站流量。 更複雜的 NAT 配置可以在補充 VRA 文件中找到。
目標
- 在虛擬路由器應用裝置 (VRA) 上設定來源網址轉換 (SNAT)
- 針對網際網路存取設定防火牆規則

- 記錄必要的網際網路服務。
- 設定 NAT。
- 建立網際網路防火牆區域和規則。
開始之前
本指導教學在透過使用安全專用網路隔離工作負載指導教學建立的安全專用網路隔離區中啟用主機,以存取公用網際網路服務。 必須先完成該指導教學。
記錄網際網路服務
第一步是確定將在公用網際網路上存取的服務,並記錄必須為來自網際網路的出埠和相應入埠資料流量啟用的埠。 在稍後的步驟中,防火牆規則將需要此埠清單。
在此範例中,僅已啟用了 http 和 https 埠,因為這兩種埠可滿足大多數需求。 DNS 和 NTP 服務透過 IBM Cloud 專用網路提供。 如果需要這兩種服務及其他服務,例如 SMTP(埠 25)或 MySQL(埠 3306),需要其他防火牆規則。 兩個基本埠規則如下:
- 埠 80 (http)
- 埠 443 (https)
請驗證協力廠商服務是否支援定義容許的來源端位址清單。 如果支援,將需要 VRA 的公用 IP 位址來配置協力廠商服務,以限制對服務的存取。
透過 NAT 假冒存取網際網路
按照這裡的指示,使用 NAT 假冒為 APP 區域中的主機配置外部網際網路存取。
-
透過 SSH 連接到 VRA,然後進入 [編輯](配置)模式。
SSH vyatta@<VRA Private IP Address> configure
-
在 VRA 上建立 SNAT 規則,指定與先前 VRA 設定教學中為 APP 區域子網路/VLAN 所確定的相同的 <子閘道 IP>/
。 set service nat source rule 1000 description 'pass traffic to the Internet' set service nat source rule 1000 outbound-interface 'dp0bond1' set service nat source rule 1000 source address <Subnet Gateway IP>/<CIDR> set service nat source rule 1000 translation address masquerade commit
建立防火牆
-
建立 APP-TO-EXTERS 的防火牆規則
set security firewall name APP-TO-OUTSIDE default-action drop set security firewall name APP-TO-OUTSIDE description 'APP traffic to the Internet' set security firewall name APP-TO-OUTSIDE default-log set security firewall name APP-TO-OUTSIDE rule 90 protocol tcp set security firewall name APP-TO-OUTSIDE rule 90 action accept set security firewall name APP-TO-OUTSIDE rule 90 destination port 80 set security firewall name APP-TO-OUTSIDE rule 100 protocol tcp set security firewall name APP-TO-OUTSIDE rule 100 action accept set security firewall name APP-TO-OUTSIDE rule 100 destination port 443 set security firewall name APP-TO-OUTSIDE rule 200 protocol icmp set security firewall name APP-TO-OUTSIDE rule 200 icmp type 8 set security firewall name APP-TO-OUTSIDE rule 200 action accept commit
-
建立防火牆規則 EXTERS-TO-APP
set security firewall name OUTSIDE-TO-APP default-action drop set security firewall name OUTSIDE-TO-APP description 'Internet traffic to APP' set security firewall name OUTSIDE-TO-APP default-log set security firewall name OUTSIDE-TO-APP rule 100 protocol tcp set security firewall name OUTSIDE-TO-APP rule 100 action accept set security firewall name OUTSIDE-TO-APP rule 100 destination port 443 set security firewall name OUTSIDE-TO-APP rule 90 protocol tcp set security firewall name OUTSIDE-TO-APP rule 90 action accept set security firewall name OUTSIDE-TO-APP rule 90 destination port 80 set security firewall name OUTSIDE-TO-APP rule 200 protocol icmp set security firewall name OUTSIDE-TO-APP rule 200 icmp type 8 set security firewall name OUTSIDE-TO-APP rule 200 action accept commit
建立區域並套用規則
-
建立區域 OUTSIDE 來控制對外部網際網路的存取。
set security zone-policy zone OUTSIDE default-action drop set security zone-policy zone OUTSIDE interface dp0bond1 set security zone-policy zone OUTSIDE description 'External Internet'
-
指派防火牆以控制進出網際網路的資料流量。
set security zone-policy zone APP to OUTSIDE firewall APP-TO-OUTSIDE set security zone-policy zone OUTSIDE to APP firewall OUTSIDE-TO-APP commit
-
驗證 APP 區域中的 VSI 現在是否可以存取網際網路上的服務。 使用 SSH 登入本端 VSI:
ssh root@<VSI Private IP>
使用 ping 及 curl 來驗證網際網路上網站的 icmp 及 tcp 存取權:
ping 8.8.8.8 curl www.google.com
移除資源
移除本指導教學所建立資源時要採取的步驟。
VRA 屬於按月付費方案。 取消不會退款。 建議只有在下個月不會再度需要此 VRA 時才取消。 如果需要雙 VRA 高可用性叢集,這個單一 VRA 可以在閘道詳細資料頁面上升級。
- 取消全部虛擬伺服器或裸機伺服器
- 取消 VRA
- 取消任何 VLAN