vyos.vyos.vyos_nat module – NAT resource module
Note
This module is part of the vyos.vyos collection (version 6.2.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install vyos.vyos.
To use it in a playbook, specify: vyos.vyos.vyos_nat.
New in vyos.vyos 6.0.0
Synopsis
This module manages NAT configuration on devices running VyOS.
Aliases: nat
Parameters
Parameter |
Comments |
|---|---|
The desired configuration for the NAT resource represented as a dictionary. |
|
Configuration for NAT rules. |
|
Configuration for Carrier Grade NAT (CGNAT). |
|
Log CGNAT address allocations. Choices:
|
|
Configuration for CGNAT pools. |
|
List of external NAT pools for CGNAT. |
|
Port range to use for NAT translations in this external pool. |
|
Name of the external NAT pool. |
|
Per-user limit configuration for the external pool. |
|
Maximum number of ports allocated per user. |
|
List of external IP address ranges in the pool. |
|
Optional sequence number for this range entry. |
|
IP address, prefix, or range (e.g. 203.0.113.0/24 or 203.0.113.1-203.0.113.60). |
|
List of internal NAT pools for CGNAT. |
|
Name of the internal NAT pool. |
|
List of internal IP addresses or prefixes in the pool. |
|
List of CGNAT rules. |
|
Rule number for CGNAT. |
|
Source pool configuration for CGNAT translation. |
|
Source pool name to use for CGNAT translation. |
|
Translation pool configuration for CGNAT. |
|
Translation pool name to use for CGNAT translation. |
|
Configuration for destination NAT rules. |
|
List of destination NAT rules. |
|
User-friendly description of the destination NAT rule. |
|
Match criteria for destination NAT. |
|
IP address, subnet, or range to match. |
|
Address group name to match. |
|
Domain group name to match. |
|
Fully qualified domain name to match. |
|
MAC address group name to match. |
|
Network group name to match. |
|
Port number or range to match. |
|
Port group name to match. |
|
Disable this destination NAT rule. Choices:
|
|
Exclude packets matching this rule from NAT. Choices:
|
|
Rule number for destination NAT. |
|
Match inbound interface. |
|
Interface group to match. |
|
Interface name to match. |
|
Load balancing configuration for this NAT rule. |
|
List of backends to load-balance across. Weights should sum to 100. |
|
IP address of the backend translation target. |
|
Relative weight (1-100) for this backend’s share of load-balanced traffic. |
|
Fields to hash on for load balancing. Mutually exclusive with translation.address. Choices:
|
|
Log packets hitting this rule. Choices:
|
|
Packet type to match. |
|
Protocol to NAT (default all). |
|
Translation configuration for destination NAT. |
|
IP address or prefix to translate destination to. |
|
Address mapping mode for translation. Choices:
|
|
Port number or range to translate destination port to. |
|
Port mapping mode for translation. Choices:
|
|
Redirect to local port number. |
|
Configuration for source NAT rules. |
|
List of source NAT rules. |
|
User-friendly description of the source NAT rule. |
|
Destination match criteria for source NAT. |
|
IP address, subnet, or range to match. |
|
Address group name to match. |
|
Domain group name to match. |
|
Fully qualified domain name to match. |
|
MAC address group name to match. |
|
Network group name to match. |
|
Port number or range to match. |
|
Port group name to match. |
|
Disable this source NAT rule. Choices:
|
|
Exclude packets matching this rule from NAT. Choices:
|
|
Rule number for source NAT. |
|
Load balancing configuration for this NAT rule. |
|
List of backends to load-balance across. Weights should sum to 100. |
|
IP address of the backend translation target. |
|
Relative weight (1-100) for this backend’s share of load-balanced traffic. |
|
Fields to hash on for load balancing. Mutually exclusive with translation.address. Choices:
|
|
Log packets hitting this rule. Choices:
|
|
Match outbound interface. |
|
Interface group to match. |
|
Interface name to match. |
|
Packet type to match. |
|
Protocol to NAT (default all). |
|
Source match criteria for source NAT. |
|
IP address, subnet, or range to match. |
|
Address group name to match. |
|
Domain group name to match. |
|
Fully qualified domain name to match. |
|
MAC address group name to match. |
|
Network group name to match. |
|
Port number or range to match. |
|
Port group name to match. |
|
Translation configuration for source NAT. |
|
IP address or prefix to translate source to. Use masquerade to masquerade as the outbound interface address. |
|
Address mapping mode for translation. Choices:
|
|
Port number or range to translate source port to. |
|
Port mapping mode for translation. Choices:
|
|
Configuration for static one-to-one NAT rules. |
|
List of static NAT rules. |
|
User-friendly description of the static NAT rule. |
|
Match criteria for static NAT. |
|
IP address, subnet, or range to match. |
|
Rule number for static NAT. |
|
Inbound interface that this static NAT rule applies to. |
|
Log packets hitting this static NAT rule. Choices:
|
|
Translation configuration for static NAT. |
|
IP address or prefix to translate to. |
|
Configuration for NAT64 (IPv6-to-IPv4) rules. |
|
Configuration for NAT64 source rules. |
|
List of NAT64 source rules. |
|
User-friendly description of the NAT64 source rule. |
|
Disable this NAT64 source rule. Choices:
|
|
Rule number for NAT64 source rule (1-999999). |
|
Match criteria for NAT64 source rule. |
|
Match on firewall mark value (1-2147483647). |
|
IPv6 source prefix to match for NAT64 translation. |
|
IPv6 source prefix to match (h:h:h:h:h:h:h:h/x). |
|
Translation configuration for NAT64 source rule. |
|
List of translation pools for NAT64. |
|
IPv4 address or prefix for translation pool. |
|
User-friendly description of the translation pool. |
|
Disable this translation pool. Choices:
|
|
Pool number (1-999999). |
|
Port number or range for translation pool. |
|
Protocol for this translation pool entry. Choices:
|
|
Configuration for NAT66 (IPv6-to-IPv6) rules. |
|
Configuration for NAT66 destination rules. |
|
List of NAT66 destination rules. |
|
User-friendly description of the NAT66 destination rule. |
|
Match criteria for NAT66 destination rule. |
|
IPv6 address or prefix to match. |
|
Port number or range to match. |
|
Disable this NAT66 destination rule. Choices:
|
|
Exclude packets matching this rule from NAT66. Choices:
|
|
Rule number for NAT66 destination rule. |
|
Inbound interface to match for NAT66 destination rule. |
|
Interface name to match. |
|
Log packets hitting this NAT66 destination rule. Choices:
|
|
Protocol to match. |
|
Source match criteria for NAT66 destination rule. |
|
IPv6 source address or prefix to match. |
|
Source port number or range to match. |
|
Translation configuration for NAT66 destination rule. |
|
IPv6 address or prefix to translate destination to. |
|
Port number or range to translate destination port to. |
|
Configuration for NAT66 source rules. |
|
List of NAT66 source rules. |
|
User-friendly description of the NAT66 source rule. |
|
Destination match criteria for NAT66 source rule. |
|
Destination port number or range to match. |
|
IPv6 destination prefix to match (h:h:h:h:h:h:h:h/x). |
|
Disable this NAT66 source rule. Choices:
|
|
Exclude packets matching this rule from NAT66. Choices:
|
|
Rule number for NAT66 source rule. |
|
Log packets hitting this NAT66 source rule. Choices:
|
|
Outbound interface to match for NAT66 source rule. |
|
Interface name to match. |
|
Protocol to match. |
|
Source match criteria for NAT66 source rule. |
|
Source port number or range to match. |
|
IPv6 source prefix to match (h:h:h:h:h:h:h:h/x). |
|
Translation configuration for NAT66 source rule. |
|
IPv6 address or prefix to translate source to. Use masquerade to masquerade as the outbound interface address. |
|
Port number or range to translate source port to. |
|
This option is used only with state parsed. The value of this option should be the output received from the VyOS device by executing the command show configuration commands | match ‘nat’. The state parsed reads the configuration from The state replaced replaces only the provided configuration, while overridden removes any existing NAT configuration not specified in config. |
|
The state the configuration should be left in. Choices:
|
Notes
Note
Tested against VyOS 1.4.3 and 1.5.0.
This module works with connection
network_cli.
Examples
# Using merged - configure CGNAT
- name: Merge CGNAT configuration
vyos.vyos.vyos_nat:
config:
nat:
cgnat:
log_allocation: true
pool:
external:
- name: ext-pool-1
external_port_range: "10000-20000"
per_user_limit:
port: "200"
range:
- value: 203.0.113.0/24
internal:
- name: int-pool-1
range:
- 10.0.0.0/24
rule:
- id: 1
source:
pool: int-pool-1
translation:
pool: ext-pool-1
state: merged
# Using merged - configure destination NAT
- name: Merge destination NAT rule
vyos.vyos.vyos_nat:
config:
nat:
destination:
rule:
- id: 100
description: "Web server NAT"
protocol: tcp
log: true
destination:
address: 198.51.100.10
port: "80"
translation:
address: 192.168.1.10
port: "8080"
state: merged
# Using merged - configure source NAT
- name: Merge source NAT rule
vyos.vyos.vyos_nat:
config:
nat:
source:
rule:
- id: 200
description: "Outbound masquerade"
protocol: tcp
log: true
outbound_interface:
name: eth0
translation:
address: masquerade
state: merged
# Using merged - configure static NAT
- name: Merge static NAT rule
vyos.vyos.vyos_nat:
config:
nat:
static:
rule:
- id: 300
description: "Static mapping"
inbound_interface: eth2
destination:
address: 198.51.100.20
translation:
address: 192.168.1.20
log: true
state: merged
# Using merged - configure NAT64
- name: Merge NAT64 source rule
vyos.vyos.vyos_nat:
config:
nat64:
source:
rule:
- id: 10
description: "NAT64 example"
source:
prefix: 2001:db8::/96
match:
mark: 100
translation:
pool:
- id: 1
address: 192.168.100.10
port: "1-65535"
protocol: udp
state: merged
# Using merged - configure NAT66
- name: Merge NAT66 destination rule
vyos.vyos.vyos_nat:
config:
nat66:
destination:
rule:
- id: 20
description: "NAT66 DNAT"
protocol: tcp
inbound_interface:
name: eth1
destination:
address: 2001:db8::1
translation:
address: 2001:db8:1::10
port: "8443"
state: merged
# Using replaced - replace specific NAT rules
- name: Replace destination NAT rule
vyos.vyos.vyos_nat:
config:
nat:
destination:
rule:
- id: 100
description: "Replaced web server NAT"
protocol: tcp
destination:
address: 198.51.100.10
port: "443"
translation:
address: 192.168.1.10
port: "8443"
state: replaced
# Using overridden - override entire NAT configuration
- name: Override entire NAT configuration
vyos.vyos.vyos_nat:
config:
nat:
destination:
rule:
- id: 100
description: "Only rule after override"
protocol: tcp
destination:
address: 198.51.100.10
port: "80"
translation:
address: 192.168.1.10
port: "8080"
state: overridden
# Using deleted - delete all NAT configuration
- name: Delete all NAT configuration
vyos.vyos.vyos_nat:
state: deleted
# Using deleted - delete specific NAT rules
- name: Delete specific NAT rules
vyos.vyos.vyos_nat:
config:
nat:
destination:
rule:
- id: 100
source:
rule:
- id: 200
nat64:
source:
rule:
- id: 10
state: deleted
# Using gathered
- name: Gather NAT configuration from device
vyos.vyos.vyos_nat:
state: gathered
# Using rendered
- name: Render NAT configuration offline
vyos.vyos.vyos_nat:
config:
nat:
destination:
rule:
- id: 100
description: "Rendered rule"
protocol: tcp
destination:
address: 198.51.100.10
port: "80"
translation:
address: 192.168.1.10
port: "8080"
state: rendered
# Using parsed
- name: Parse NAT configuration from file
vyos.vyos.vyos_nat:
running_config: "{{ lookup('file', './nat_config.cfg') }}"
state: parsed
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
The resulting configuration after module execution. Returned: when changed Sample: |
|
The configuration prior to the module execution. Returned: when state is Sample: |
|
The set of commands pushed to the remote device. Returned: when state is Sample: |
|
Facts about the network resource gathered from the remote device as structured data. Returned: when state is Sample: |
|
The device native config provided in running_config option parsed into structured data as per module argspec. Returned: when state is Sample: |
|
The provided configuration in the task rendered in device-native format (offline). Returned: when state is Sample: |