[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Internal passthrough Network Load Balancer forwarding rules that use a common IP address\n\nInternal passthrough Network Load Balancers are regional load balancers that enable\nyou to run and scale your services behind an internal IP address\nthat is accessible only to your internal virtual machine (VM) instances.\n\nThis page discusses using multiple forwarding rules with\nthe same IP address. For general information about internal passthrough Network Load Balancers, see the\n[Internal passthrough Network Load Balancer overview](/load-balancing/docs/internal).\n\nUsing internal forwarding rules, you can use a shared internal IP address across\nup to ten forwarding rules. To share an IP address, you set the purpose of the\nIP address to `SHARED_LOADBALANCER_VIP`. You can use `TCP`or `UDP` for the\nforwarding rule protocol and assign up to five ports to the forwarding rule, or\nspecify `--ports=ALL` to use all ports. If you want to use the `L3_DEFAULT`\nprotocol, you must use all ports with the `--ports=ALL` option.\n\nWith unique combinations of protocol and ports, you can do the following:\n\n- Create 50 unique TCP ports with each forwarding rule using the `TCP`\n protocol.\n\n If a forwarding rule is configured to use the `TCP` protocol and all ports, no\n other forwarding rule using the `TCP` protocol can use the same shared IP\n address.\n- Create 50 unique UDP ports with each forwarding rule using the `UDP`\n protocol.\n\n If a forwarding rule is configured to use the `UDP` protocol and all ports, no\n other forwarding rule using the `UDP` protocol can use the same shared IP\n address.\n- Create 50 unique combinations of TCP and UDP ports, with each forwarding\n rule using either the `TCP` or `UDP` protocol.\n\n- Reference a common backend service (a single load balancer) or multiple\n backend services (multiple load balancers that share the same IP address).\n\n- Use all ports when configuring a forwarding rule with the `L3_DEFAULT`\n protocol. There can be only one `L3_DEFAULT` forwarding rule for an IP\n address, which can be shared with other TCP and UDP forwarding rules, if\n necessary.\n\nWhen your forwarding rules have different protocols, you must have two different\nbackend services as well. A single internal passthrough Network Load Balancer works for either TCP or\nUDP traffic---not both---because it has a single backend service that uses only\none of these protocols.\n\nDecision matrices for forwarding rules\n--------------------------------------\n\nUse the following tables to design your deployment.\n\n### Single internal passthrough Network Load Balancer\n\nA single backend service supports TCP or UDP, not both.\n\nWhen you need multiple forwarding rules, calculate the number of forwarding\nrules that you need by using the formula\n`⌈total number of ports / 5⌉`, where `⌈⌉` is the\nceiling (least integer) function, and means *round up* to the nearest\nwhole number.\n\nFor example, suppose you need 26 TCP ports on one IP address of your load\nbalancer. If you don't want to create a single forwarding rule by using\n`--ports=ALL`, you must create six forwarding rules because `26 / 5 = 5 with a remainder of 1`.\n\n### Two internal passthrough Network Load Balancers\n\nWhen you have two internal passthrough Network Load Balancers, you can have two backend services, where\none backend service is for TCP traffic, and the other backend service is for UDP\ntraffic.\n\nWhen you need multiple forwarding rules, calculate the number of forwarding\nrules that you need by using the following formula, where\n`⌈⌉` is the ceiling (least integer) function, and means *round up*\nto the nearest whole number: \n\n```\n ⌈total number of TCP ports / 5⌉\n\n ⌈total number of UDP ports / 5⌉\n```\n\nFor example, suppose you need 26 TCP ports and 12 UDP ports.\nYou must create nine forwarding rules:\n\n- `26 / 5 = 5 with a remainder of 1`, so you need six forwarding rules for your TCP ports.\n- `12 / 5 = 2 with a remainder of 2`, so you need three forwarding rules for your UDP ports.\n\n| **Note:** You cannot share a static internal IPv6 address across multiple forwarding rules.\n\n#### Limitations\n\n- Two or more forwarding rules with the same IP address and protocol cannot have overlapping ports. For example:\n - When you configure the forwarding rule with protocol TCP and port `80`, you cannot configure another forwarding rule to serve that protocol and port. For example, you cannot create another forwarding rule to serve TCP ports `80`, `81`, and `90`.\n - When you configure the forwarding rule for TCP and ports `80`, `8080`, and `90`, you cannot configure another forwarding rule for TCP that would use all ports.\n- When two or more forwarding rules share the same IP address by using the `--purpose=SHARED_LOADBALANCER_VIP` flag, at most only one of them can have the protocol set to `L3_DEFAULT`.\n\nUse cases\n---------\n\nMany different types of deployments are possible. The following\nexamples use one IP address that accepts traffic on specific ports for two\nload balancers.\n\n### Example 1\n\nThis example uses different forwarding rules with the following parameters:\n\n- The same IP address (`10.1.1.1`)\n- Different protocols\n- Separate backend services that each forwarding rule points to\n- Matching protocols: the protocol of each backend service matches the protocol of the corresponding forwarding rule\n\n[](/static/load-balancing/images/ilb-fwd-rules-same-ip-different-protocols.svg) Different forwarding rules, same IP address, different protocols and ports (click to enlarge).\n\n### Example 2\n\nThis example uses different forwarding rules with the following parameters:\n\n- The same IPv4 address (`10.1.1.1`)\n- The same protocol\n- A different set of numbered ports on each forwarding rule\n\n| **Notes:**\n|\n| - This configuration option is an alternative to creating a single forwarding rule that specifies all ports.\n| - You cannot share a static internal IPv6 address across multiple forwarding rules.\n[](/static/load-balancing/images/ilb-fwd-rules-same-ip-different-ports.svg) Different forwarding rules, same IP address, same protocol, more than five numbered ports (click to enlarge).\n\nConfiguration steps\n-------------------\n\nYou can create multiple internal forwarding rules that have the same IP address\nif you do both of the following:\n\n1. [Create a static (reserved) internal IP address](/vpc/docs/reserve-static-internal-ip-address) for the forwarding rules to use.\n2. Set the [`--purpose` flag](/sdk/gcloud/reference/compute/addresses/create#--purpose) on the shared internal IP address to the value `SHARED_LOADBALANCER_VIP`.\n\nFor an example setup, see\n[Accepting traffic on multiple ports using two forwarding rules](/load-balancing/docs/internal/setting-up-internal#multiple-ports-two-fwd-rules)."]]