NAT in VyOS

Network Address Translation (NAT) lets you rewrite the IP addresses in packets as they pass through the router.

Section contents

NAT Configuration

A complete guide to configuring NAT in VyOS.

NAT types:

  • Source NAT (SNAT) - rewrites the source address (for internet access)
  • Destination NAT (DNAT) - rewrites the destination address (port forwarding)
  • Masquerade - SNAT with automatic detection of the external IP
  • 1:1 NAT - a static mapping between an internal and an external IP

Common scenarios

SNAT/Masquerade

Providing internet access for an internal network.

Port Forwarding

Forwarding external ports to internal servers (DNAT).

1:1 NAT

Publishing an internal server behind an external static IP.


Quick example

Source NAT (Masquerade)

set nat source rule 100 outbound-interface name eth0
set nat source rule 100 source address 192.168.1.0/24
set nat source rule 100 translation address masquerade

Port Forwarding (DNAT)

set nat destination rule 100 destination port 80
set nat destination rule 100 inbound-interface name eth0
set nat destination rule 100 protocol tcp
set nat destination rule 100 translation address 192.168.1.10

Additional resources

Reviewed by OpenNix LLC · Last updated on