--- discourse: 11801 --- (network-forwards)= # How to configure network forwards ```{note} Network forwards are available for the {ref}`network-ovn` and the {ref}`network-bridge`. ``` ```{youtube} https://www.youtube.com/watch?v=B-Uzo9WldMs ``` Network forwards allow an external IP address (or specific ports on it) to be forwarded to an internal IP address (or specific ports on it) in the network that the forward belongs to. This feature can be useful if you have limited external IP addresses and want to share a single external address between multiple instances. There are two different ways how you can use network forwards in this case: - Forward all traffic from the external address to the internal address of one instance. This method makes it easy to move the traffic destined for the external address to another instance by simply reconfiguring the network forward. - Forward traffic from different port numbers of the external address to different instances (and optionally different ports on those instances). This method allows to "share" your external IP address and expose more than one instance at a time. ```{tip} Network forwards are very similar to using a {ref}`proxy device` in NAT mode. The difference is that network forwards are applied on a network level, while a proxy device is added for an instance. In addition, proxy devices can be used to proxy traffic between different connection types (for example, TCP and Unix sockets). ``` ## Create a network forward Use the following command to create a network forward: ```bash lxc network forward create [] [--allocate=ipv{4,6}] [configuration_options...] ``` Each forward is assigned to a network. Specify a single external listen address (see {ref}`network-forwards-listen-addresses` for more information about which addresses can be forwarded, depending on the network that you are using). If the network type supports IP allocation, you don't need to specify a listen address. If you leave it out, you must provide the `--allocate` flag. You can specify an optional default target address by adding the `target_address=` configuration option. If you do, any traffic that does not match a port specification is forwarded to this address. Note that this target address must be within the same subnet as the network that the forward is associated to. ### Forward properties Network forwards have the following properties: % Include content from [../config_options.txt](../config_options.txt) ```{include} ../config_options.txt :start-after: :end-before: ``` (network-forwards-listen-addresses)= ### Requirements for listen addresses The requirements for valid listen addresses vary depending on which network type the forward is associated to. Bridge network : - Any non-conflicting listen address is allowed. - The listen address must not overlap with a subnet that is in use with another network. - The `--allocate` flag is not supported. OVN network : - Allowed listen addresses must be defined in the uplink network's `ipv{n}.routes` settings or the project's {config:option}`project-restricted:restricted.networks.subnets` setting (if set). - The listen address must not overlap with a subnet that is in use with another network. - The `--allocate` flag is supported. If used, the OVN network driver will allocate an IP address from the uplink network's `ipv{n}.routes` or the project's {config:option}`project-restricted:restricted.networks.subnets` setting (if set). (network-forwards-port-specifications)= ## Configure ports You can add port specifications to the network forward to forward traffic from specific ports on the listen address to specific ports on the target address. This target address must be different from the default target address. It must be within the same subnet as the network that the forward is associated to. Use the following command to add a port specification: ```bash lxc network forward port add [] ``` You can specify a single listen port or a set of ports. If you want to forward the traffic to different ports, you have two options: - Specify a single target port to forward traffic from all listen ports to this target port. - Specify a set of target ports with the same number of ports as the listen ports to forward traffic from the first listen port to the first target port, the second listen port to the second target port, and so on. ### Port properties Network forward ports have the following properties: % Include content from [../config_options.txt](../config_options.txt) ```{include} ../config_options.txt :start-after: :end-before: ``` ## Edit a network forward Use the following command to edit a network forward: ```bash lxc network forward edit ``` This command opens the network forward in YAML format for editing. You can edit both the general configuration and the port specifications. ## Delete a network forward Use the following command to delete a network forward: ```bash lxc network forward delete ```