This document describes the various deployment, installation, and upgrade options for Vyatta software. This preface provides information about using this guide. The following topics are presented: Intended Audience Organization of This Guide Document Conventions Vyatta Publications

NAT

R6.4v01

Vyatta

IntendedAudience viii

IntendedAudienceThis guide is intended for experienced system and network administrators. Depending on the functionality to be used, readers should have specific knowledge in the following areas: Networking and data communications TCP/IP protocols General router configuration Routing protocols Network administration Network security IP services

OrganizationofThisGuideThis guide has the following aid to help you find the information you are looking for: Quick List of Commands Use this list to help you quickly locate commands. List of Examples Use this list to help you locate examples youd like to try or look at. This guide has the following chapters:ChapterChapter 1:NATOverview

This document uses the following typographic conventions.

Monospace

Examples, command-line output, and representations of configuration nodes. Your input: something you type at a command line. Commands, keywords, and file names, when mentioned inline. Objects in the user interface, such as tabs, buttons, screens, and panes.

An argument or variable where you supply a value. A key on your keyboard, such as <Enter>. Combinations of keys are joined by plus signs (+), as in <Ctrl>+c. Enumerated options for completing a syntax. An example is [enable | disable]. A inclusive range of numbers. An example is 165535, which means 1 through 65535, inclusive. A range of enumerated values. An example is eth0..eth3, which means eth0, eth1, eth2, or eth3. A value that can optionally represent a list of elements (a space-separated list and a comma-separated list, respectively).

VyattaPublications

NAT

R6.4v01

Vyatta

VyattaPublications x

Full product documentation is provided in the Vyatta technical library. To see what documentation is available for your release, see the Guide to Vyatta Documentation. This guide is posted with every release of Vyatta software and provides a great starting point for finding the information you need. Additional information is available on www.vyatta.com and www.vyatta.org.

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

This chapter explains how to set up network address translation (NAT) on the Vyatta System. This chapter presents the following topics: What is NAT? Benefits of NAT Types of NAT Interaction Between NAT, Routing, Firewall, and DNS NAT Rules Traffic Filters Address Conversion: Translation Addresses

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

WhatisNAT? 2

WhatisNAT?Network Address Translation (NAT) is a service that modifies address and/or port information within network packets as they pass through a computer or network device. The device performing NAT on the packets can be the source of the packets, the destination of the packets, or an intermediate device on the path between the source and destination devices. Figure11AnexampleofadeviceperformingNetworkAddressTranslation(NAT)

External (untrusted ) network

Internal (trusted) network

IP Packet Dest-addr = 12.34.56.78

NAT

IP Packet Dest-addr = 10.0.0.4

NAT was originally designed to help conserve the number of IP addresses used by the growing number of devices accessing the Internet, but it also has important applications in network security. The computers on an internal network can use any of the addresses set aside by the Internet Assigned Numbers Authority (IANA) for private addressing (see also RFC 1918). These reserved IP addresses are not in use on the Internet, so an external machine will not directly route to them. The following addresses are reserved for private use: 10.0.0.0 to 10.255.255.255 (CIDR: 10.0.0.0/8) 172.16.0.0 to 172.31.255.255 (CIDR: 172.16.0.0/12) 192.168.0.0 to 192.168.255.255 (CIDR: 192.268.0.0/16)

To this end a NAT-enabled router can hide the IP addresses of an internal network from the external network, by replacing the internal, private IP addresses with public IP addresses that have been provided to it. These public IP addresses are the only addresses that are ever exposed to the external network. The router can manage a pool of multiple public IP addresses, from which it can dynamically choose when performing address replacement. Be aware that, although NAT can minimize the possibility that internal computers make unsafe connections to the external network, it provides no protection to a computer that, for one reason or another, connects to an untrusted machine. Therefore, you should always combine NAT with packet filtering and other features of a complete security policy to fully protect your network.

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

BenefitsofNAT 3

BenefitsofNATNAT confers several advantages: NAT conserves public Internet address space. Any number of hosts within a local network can use private IP addresses, instead of consuming public IP addresses. The addresses of packets that are transmitted from this network to the public Internet are translated to the appropriate public IP address. This means that the same private IP address space can be re-used within any number of private networks, as shown in Reusing private address space Figure 1-2. Figure12Reusingprivateaddressspace

Internet

10.0.0.0/8

10.0.0.0/8 10.0.0.0/8

10.0.0.0/8

NAT enhances security. IP addresses within a private (internal) network are hidden from the public (external) network. This makes it more difficult for hackers to initiate an attack on an internal host. However, private network hosts are still vulnerable to attack, and therefore NAT is typically combined with firewall functionality.

Routing Table 10.x.x.x not listed

InternetExternal (untrusted ) netw ork Internal (trusted) netw ork

NAT is seamless. Standard client/server network services work without modification through a NAT-enabled device.

NAT facilitates network migration from one address space to another. The address space within a NATted private network is independent of the public IP address. This means that the private network can be moved to a new public IP address without changing network configurations within the private network. Likewise, the addressing within the private network can change without affecting the public IP address.

TypesofNATThere are three main types of NAT: Source NAT. This is also called SNAT. Masquerade NAT is a special type of SNAT. Destination NAT. This is also called DNAT. Bidirectional NAT. When both SNAT and DNAT are configured, the result is bidirectional NAT.

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

TypesofNAT 5

SourceNAT(SNAT)Tip:SNATis performed afterthe routing decisionis made.

SNAT is the most common form of NAT. SNAT changes the source address of the packets passing through the Vyatta system. SNAT is typically used when an internal (private) host needs to initiate a session to an external (public) host; in this case, the NATting device changes the source hosts private IP address to some public IP address, as shown in Figure 1-4. In masquerade NAT (a common type of SNAT), the source address of the outgoing packet is replaced with the primary IP address of the outbound interface. The destination address of return packets is automatically translated back to the source hosts IP address. The NATting device tracks information about the traffic flow so that traffic from the flow can be correctly forwarded to and from the source host. Figure14SourceNAT(SNAT)External (untrusted ) network Internal (trusted) network

Source-addr = 12.34.56.78 Dest-addr = 96.97.98.99

SNAT

Source-addr = 10.0.0.4 Dest-addr = 96.97.98.99

While SNAT changes the source address of packets, DNAT changes the destination address of packets passing through the Vyatta system. DNAT is typically used when an external (public) host needs to initiate a session with an internal (private) host; for example, when a subscriber accesses a news service, as shown in Figure 1-5. The source address of return packets is automatically translated back to the source hosts IP address.

Source-addr = 96.97.98.99 Dest-addr = 12.34.56.78

DNAT

Source-addr = 96.97.98.99 Dest-addr = 10.0.0.4

BidirectionalNATBidirectional NAT is just a scenario where both SNAT and DNAT are configured at the same time. Bidirectional NAT is typically used when internal hosts need to initiate sessions with external hosts AND external hosts need to initiate sessions with internal hosts. Figure 1-6 shows an example of bidirectional NAT. Figure16BidirectionalNAT

External (untrusted ) network

Internal (trusted) network

SNATSource-addr = 12.34.56.78 Source-addr = 10.0.0.4

DNATDest-addr = 12.34.56.78 Dest-addr = 10.0.0.4

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

InteractionBetweenNAT,Routing,Firewall,andDNS 7

InteractionBetweenNAT,Routing,Firewall, andDNSOne of the most important things to understand when working with NAT is the processing order of the various services that might be configured within the Vyatta system. If processing order is not considered, the results achieved may not be as intended. For example, if you are using DNAT you should take care not to set up the system to route packets based on particular external addresses. This routing method would not have the intended result, because the addresses of external packets would have all been changed to internal addresses by DNAT prior to routing. Figure 1-7 shows the traffic flow relationships between NAT, routing, and firewall within the Vyatta system. Figure17TrafficflowsthroughtheVyattasystemRouting Dest = Local?Yes

Network A

DNAT

No

Firewall (name, in)

Firewall (name, out)

SNAT

Network B

Firewall (name, local)

Local Process

Routing

Vyatta system

InteractionBetweenNATandRoutingWhen considering NAT in relation to routing, it is important to be aware how routing decisions are made with respect to DNAT and SNAT. The scenarios in this section illustrate this point.

Scenario1a:DNATPacketsPassingThroughtheVyattaSystemIn this scenario, packets are originated in Network A and pass through the Vyatta system. Note the following:

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

InteractionBetweenNAT,Routing,Firewall,andDNS 8

Tip:DNATrou tingdecisions arebasedon translated destination address.

DNAT operates on the packets prior to the routing decision. This means that routing decisions based on the destination address are made relative to the translated destination addressnot the original destination address; see Figure 1-8. Figure18PassthroughDNATroutingdecisionsDest-addr = 12.34.56.78

Dest-addr = 10.0.0.4

Network A

DNAT

Routing

Dest = Local?Yes

No

Firewall (name, in)

Firewall (name, out)

SNAT

Network B

Firewall (name, local)

Local Process

Routing

Vyatta system

Scenario1b:DNATPacketsDestinedfortheVyattaSystemThe same is true for packets destined for the Vyatta system itself. In this scenario, packets are destined for a process within the Vyatta system. Again, because DNAT operates on the packets prior to the routing decision, routing decisions based on destination address are made on the translated destination addressnot the original destination address; see Figure 1-9.

Firewall (name, in)

Firewall (name, out)

Firewall (name, local)

On the other hand, routing decisions are made prior to SNAT. This means that routing decisions based on source address are made on the original source addressnot the translated source address; see Figure 1-10. Figure110PassthroughSNATroutingdecisionsSrc-addr = 12.34.56.78

Src-addr = 10.0.0.4

Network A

DNAT

Routing

Dest = Local?Yes

No

Firewall (name, in)

Firewall (name, out)

SNAT

Network B

Firewall (name, local)

Local Process

Routing

Vyatta system

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

InteractionBetweenNAT,Routing,Firewall,andDNS 10

Scenario2b:SNATPacketsOriginatingFromtheVyattaSystemIn this scenario, packets are originated by a process within the Vyatta system. Again, because routing decisions are made prior to SNAT, operations based on source address are made on the original source addressnot the translated source address; see Figure 1-11. Figure111VyattasystemoriginatedSNATroutingdecisionsSrc-addr = 12.34.56.78

Src-addr = 10.0.0.20

Network A

DNAT

Routing

Dest = Local?Yes

No

Firewall (name, in)

Firewall (name, out)

SNAT

Network B

Firewall (name, local)

Local Process

Routing

Vyatta system

InteractionBetweenNATandFirewallWhen considering NAT in relation to the firewall, it is important to understand the traffic flow relationship between NAT and firewall. In particular, it is important to keep in mind that firewall rule sets are evaluated at different points in the traffic flow. The scenarios in this section illustrate this point.

Scenario1a:DNATPacketsPassingThroughtheVyattaSystemIn this scenario, packets are originated in Network A and pass through the Vyatta system. Note the following: For firewall rule sets applied to inbound packets on an interface, the firewall rules are applied after DNAT (that is, on the translated destination address). For rule sets applied to outbound packets on an interface, the firewall rules are applied after DNAT (that is, on the translated destination address); see Figure 1-12.

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

InteractionBetweenNAT,Routing,Firewall,andDNS 11

Figure112PassthroughDNATfirewalldecisionsDest-addr = 12.34.56.78

Dest-addr = 10.0.0.4

Network A

DNAT

Routing

Dest = Local?Yes

No

Firewall (name, in)

Firewall (name, out)

SNAT

Network B

Firewall (name, local)

Local Process

Routing

Vyatta system

Scenario1b:DNATPacketsDestinedfortheVyattaSystemIn this scenario, packets are destined for a process within the Vyatta system. When firewall rule sets are applied to locally bound packets on an interface, the firewall rules are applied after DNAT (that is, on the translated destination address); see Figure 1-13. Figure113VyattasystemdestinedDNATfirewalldecisionsDest-addr = 12.34.56.78

Firewall rules are applied prior to SNAT. This means that firewall decisions based on source address are made on the original source addressnot the translated source address. This order of evaluation is true for both inbound and outbound packets; see Figure 1-14. Figure114PassthroughSNATfirewalldecisionsSrc-addr = 12.34.56.78

Src-addr = 10.0.0.4

Network A

DNAT

Routing

Dest = Local?Yes

No

Firewall (name, in)

Firewall (name, out)

SNAT

Network B

Firewall (name, local)

Local Process

Routing

Vyatta system

Scenario2b:SNATPacketsOriginatingFromtheVyattaSystemIn this scenario, packets are originated by a process within the Vyatta system. Firewall rule sets are not involved.

Firewall (name, in)

Firewall (name, out)

SNAT

Network B

Firewall (name, local)

Local Process

Routing

Vyatta system

InteractionBetweenNATandDNSNAT and DNS can be combined in various scenarios involving load balancing. These can include additional load-balancing switches that operate at higher protocol layers (Layers 4 through 7). For example, a large bank may have many web servers with transactions load-balanced across them. In these cases the NAT configuration must be carefully considered to achieve the desired results. Discussion of DNS and load-balancing scenarios is beyond the scope of this chapter.

NATRulesNAT is configured as series of NAT rules. Each rule instructs NAT to perform a network address translation that you require. NAT rules are numbered, and are evaluated in numerical order. The NAT rule number can be changed using the rename and copy commands.NOTEChangestoNATrulesaffectonlyconnectionsestablishedafterthechangesaremade.Those connectionsthatarealreadyestablishedatthetimeachangeismadearenotaffected.Tip:Leavea gapbetween NATrule numbers.

It is advisable to create your NAT rules leaving space between the numbers. For example, you might initially create your set of NAT rules numbered 10, 20, 30, and 40. This way, if you need to insert a new rule later on, and you want it to execute in a particular sequence, you can insert it between existing rules without having to change any other rules.

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

TrafficFilters 14

The Vyatta system allows you to configure source NAT ( SNAT), or destination NAT rules. To implement bidirectional NAT, you define a NAT rule for SNAT and one for DNAT. Example 1-1 defines an SNAT rule 10. Example11CreatingasourceNAT(SNAT)rulevyatta@vyatta#setnatsourcerule10

TrafficFiltersFilters control which packets will have the NAT rules applied to them. There are five different filters that can be applied within a NAT rule: outbound-interface, inbound-interface, protocol, source, and destination.

TheoutboundinterfaceFilterThe outbound-interface filter is applicable only to source NAT (SNAT) rules. It specifies the outbound traffic flow that the NAT translation is to be applied to. Example 1-2 sets SNAT rule 20 to apply a NAT translation to outbound traffic on interface eth1. Example12Settingtheoutboundinterfacevyatta@vyatta#setnatsourcerule20outboundinterfaceeth1

TheinboundinterfaceFilterThe inbound-interface filter is applicable only to destination NAT (DNAT) rules. It specifies the inbound traffic flow that the NAT translation is to be applied to. Example 1-3 sets DNAT rule 20 to apply NAT rules to inbound traffic on interface eth0. Example13Settingtheinboundinterfacevyatta@vyatta#setnatdestinationrule20inboundinterfaceeth0

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

TrafficFilters 15

TheprotocolFilterThe protocol filter specifies which protocol types the NAT translation will be applied to. Only packets of the specified protocol are NATted. The default is all protocols. The protocol filter can be used in SNAT and DNAT rules. Example 1-4 sets SNAT rule 10 to apply to TCP protocol packets. Only TCP packets will have address translation performed. Example14Filteringpacketsbyprotocolvyatta@vyatta#setnatsourcerule10protocoltcp

ThesourceFilterThe source filter specifies which packets the NAT translation will be applied to, based on their source address and/or port. Only packets with a source address and/or port matching that defined in the filter are NATted. If the source filter is not specified, then by default, the rule matches packets arriving from any source address and port. The source filter can be used in SNAT and DNAT rules. Example 1-5 sets SNAT rule 10 to apply to packets with a source address of 10.0.0.4. Only packets with a source address of 10.0.0.4 will have address translation performed. Example15Filteringpacketsbysourceaddressvyatta@vyatta#setnatsourcerule10sourceaddress10.0.0.4

Example 1-6 sets SNAT rule 20 to apply to packets with a source network of 10.0.0.0/24 and port 80. Only packets with a source address on the 10.0.0.0/24 subnet with a source port of 80 will have address translation performed. Example16Filteringpacketsbysourcenetworkaddressandportvyatta@vyatta#setnatsourcerule20sourceaddress10.0.0.0/24 vyatta@vyatta#setnatsourcerule20sourceport80

NAT

R6.4v01

Vyatta

Chapter1:NATOverview

AddressConversion:TranslationAddresses 16

ThedestinationFilterThe destination filter specifies which packets the NAT translation will be applied to, based on their destination address and/or port. Only packets with a destination address and/or port matching that defined in the filter are NATted. If the destination filter is not specified, then by default, the rule matches packets sent to any destination address and port. The destination filter can be used in SNAT and DNAT rules. Example 1-7 sets SNAT rule 30 to apply to packets with a destination address of 12.34.56.78. Only packets with a destination address of 12.34.56.78 will have address translation performed. Example17Filteringpacketsbydestinationaddressvyatta@vyatta#setnatsourcerule30destinationaddress12.34.56.78

AddressConversion:TranslationAddressesThe translation address defines the address conversion that takes place. It specifies the information that is substituted into the packet for the original address.

SourceAddressTranslationsSNAT rules substitute the packets source address with the translation address. Port translation is also available and can be specified as part of the translation address. Note that the translation address must either be set to one of the addresses defined on the outbound interface or set to masquerade, indicating that the primary IP address of the outbound interface is to be used as the translation address. Example 1-8 sets rule 10 to substitute 12.34.56.78 as the source IP address of outbound packets matching its filter criteria. Example18SettingasourceIPaddressvyatta@vyatta#setnatsourcerule10translationaddress12.34.56.78

Example 1-10 sets rule 30 to substitute the primary address of the outbound interface as the source IP address of outbound packets that match its filter criteria. Example110SettingasourceIPaddresstothatoftheoutboundinterfacevyatta@vyatta#setnatsourcerule30translationaddressmasquerade

DestinationAddressTranslationsDNAT rules substitute the packets destination address with the translation address. Port translation is also available and can be specified as part of the translation address. Example 1-11 sets rule 40 to substitute 10.0.0.4 as the destination IP address of inbound packets matching its filter criteria. Example111SettingadestinationIPaddressvyatta@vyatta#setnatdestinationrule40translationaddress10.0.0.4

SourceNAT(OnetoOne)Figure 2-1 shows an example of source NAT (SNAT) where a single inside source address is translated to a single outside source address. In this example: An internal news server (an NNTP device) needs to connect to an external news server. The external news server accepts connections only from known clients. The internal news server does not receive connections from outside the local network.

Figure21SourceNAT(onetoone)10.0.0.4

eth0

INTERNET

Source-addr = 10.0.0.4 Dest-addr = 96.97.98.99

SNAT

Source-addr = 12.34.56.78 Dest-addr = 96.97.98.99

To configure NAT in this way, perform the following steps in configuration mode. Example21SourceNAT(onetoone)StepCreateRule10.Rule10isan SNATrule.

SourceNAT(ManytoOne)Figure 2-2 shows an example of SNAT where many different inside addresses are dynamically translated to a single outside address. In this example, all hosts on the 10.0.0.0/24 subnet will show the same source address externally.

NAT

R6.4v01

Vyatta

Chapter2:NATConfigurationExamples

SourceNAT(ManytoOne) 21

Figure22SourceNAT(manytoone)10.0.0.4 10.0.0.5 10.0.0.6 10.0.0.7

eth0

INTERNET10.0.0.0/24

Source-addr = 10.0.0.X Dest-addr = 96.97.98.99

SNAT

Source-addr = 12.34.56.78 Dest-addr = 96.97.98.99

To configure NAT in this way, perform the following steps in configuration mode. Example22SourceNAT(manytoone)StepCreateRule10.Rule10isan SNATrule.

SourceNAT(ManytoMany)In many-to-many translations, a number of private addresses are mapped to a number of public addresses. This provides a way of reducing the possibility of port exhaustions that is possible in a many-to-one scenario. For this reason, it can provide more capacity for outbound translations. Figure 2-3 shows a large private address space (a /8 network prefix, here represented as three /16 subnets) mapped to a small range of external addresses. Figure23SourceNAT(manytomany)

10.1.0.0/16

10.43.0.0/16eth0

INTERNET

10.197.0.0/16

Source-addr = 10.X.X.X Dest-addr = 96.97.98.99

SNAT

Source-addr = 12.34.56.64-79 Dest-addr = 96.97.98.99

NAT

R6.4v01

Vyatta

Chapter2:NATConfigurationExamples

SourceNAT(OnetoMany) 23

To configure NAT in this way, perform the following steps in configuration mode. Example23SourceNAT(manytomany)StepCreateRule10.Rule10isan SNATrule.

SourceNAT(OnetoMany)The scenario described in this section is less common. In this scenario, a single test source device behind the NAT device appears externally to be multiple devices, as shown in Figure 2-4. One application of this scenario might be to test an upstream load-balancing device.

NAT

R6.4v01

Vyatta

Chapter2:NATConfigurationExamples

SourceNAT(OnetoMany) 24

Figure24SourceNAT(onetomany)10.0.0.4

eth0

INTERNET

Source-addr = 10.0.0.4 Dest-addr = 96.97.98.99

SNAT

Source-addr = 12.34.56.64-79 Dest-addr = 96.97.98.99

To configure NAT in this way, perform the following steps in configuration mode. Example24SourceNAT(onetomany)StepCreateRule10.Rule10isan SNATrule.

MasqueradeMasquerade NAT is a special case of source NAT. It is typically used in situations where the Internet-facing interface has a dynamic IP address provided by a mechanism such as DHCP. In these cases, configuring a static translation address is not appropriate as the address assigned to the interface can change. Specifying masquerade as the the translation address instructs the system to use the IP address currently assigned to the outbound-interface as the translation address. Masquerade NAT rules typically consist of match conditions containing: The source network (usually the private IP network assigned to LAN devices) The outbound interface (the Internet-facing interface that is assigned the dynmic IP address)

Figure 2-5 shows an example of masquerade NAT.

NAT

R6.4v01

Vyatta

Chapter2:NATConfigurationExamples

Masquerade 26

Figure25Masquerade

10.0.0.4 10.0.0.5 10.0.0.6 10.0.0.7

eth0

INTERNET10.0.0.0/24

Source-addr = 10.0.0.X Dest-addr = 96.97.98.99

SNAT

Source-addr = Address of eth0 Dest-addr = 96.97.98.99

To configure NAT in this way, perform the following steps in configuration mode. Example25MasqueradeStepCreateRule10.Rule10isan SNATrule.

DestinationNAT(OnetoOne)Destination NAT (DNAT) is used where only inbound traffic is expected.

Scenario1:PacketsdestinedforinternalwebserverFor example, DNAT might be used in a scenario where a corporate web server needs to be reachable from external locations but never initiates outbound sessions, as shown in Figure 2-6. Figure26DestinationNAT(onetoone)

Scenario2:PacketsdestinedforaninternalSSHserverIn this scenario, all traffic destined for the SSH port is passed through to a host containing an SSH server, as shown in Figure 2-7. Figure27DestinationNAT(onetoone):filteringonportname10.0.0.5

DestinationNAT(OnetoMany)Another example where DNAT might be used in a scenario where a corporate web farm is accessed through a single IP address. In this case, a single IP address is translated to many IP addresses dynamically, as shown in Figure 2-8.

NAT

R6.4v01

Vyatta

Chapter2:NATConfigurationExamples

DestinationNAT(OnetoMany) 30

Figure28DestinationNAT(onetomany)10.0.0.64 ... ... 10.0.0.79

eth0

INTERNET10.0.0.64/28

Source-addr = 96.97.98.99 Dest-addr = 10.0.0.64-79

DNAT

Source-addr = 96.97.98.99 Dest-addr = 12.34.56.78

To configure NAT in this way, perform the following steps in configuration mode. Example28DestinationNAT(onetomany)Step Command

BidirectionalNATBidirectional NAT is simply a combination of source and destination NAT. A typical scenario might use SNAT on the outbound traffic of an entire private network, and DNAT for specific internal services (for example, mail or web); see Figure 2-9. Figure29BidirectionalNAT10.0.0.4 10.0.0.5 10.0.0.6 10.0.0.7

eth0

INTERNET10.0.0.0/24

Source-addr = 10.0.0.X Dest-addr = 96.97.98.99

SNAT

Source-addr = 12.34.56.78 Dest-addr = 96.97.98.99

Source-addr = 96.97.98.99 Dest-addr = 10.0.0.4

DNAT

Source-addr = 96.97.98.99 Dest-addr = 12.34.56.78

To configure NAT in this way, perform the following steps in configuration mode. Note that source and destination rule numbers are independent. In this example, we highlight this by creating source rule 10 and destination rule 10. Example29BidirectionalNATStepCreatesource(SNAT)rule10.

MappingAddressRangesThe Vyatta system supports mapping an entire network of addresses to another network of addresses. This saves having to manually enter many NAT rules. For example, you can map the network 10.0.0.0/24 to 11.22.33.0/24. This would mean that 10.0.0.1 maps to 11.22.33.1, 10.0.0.2 maps to 11.22.33.2, and so on. The networks must be of the same size (that is, they must have the same network mask), as shown in Figure 2-10.

NAT

R6.4v01

Vyatta

Chapter2:NATConfigurationExamples

MappingAddressRanges 33

Figure210Mappingaddressranges10.0.0.4 10.0.0.5 10.0.0.6 10.0.0.7

10.0.0.0/24

eth0

INTERNET

Source-addr = 10.0.0.X Dest-addr = 96.97.98.99

SNAT

Source-addr = 11.22.33.x Dest-addr = 96.97.98.99

Source-addr = 96.97.98.99 Dest-addr = 10.0.0.x

DNAT

Source-addr = 96.97.98.99 Dest-addr = 11.22.33.x

To configure NAT in this way, perform the following steps in configuration mode. Example210MappingaddressrangesStepCreatesource(SNAT)rule10.

TheexcludeOptionSometimes it is desirable to exclude packets from NAT translation that match a certain criteria. This can be accomplished using the exclude option. Example 2-11 uses exclude to exclude a subset of traffic (packets coming from 192.168.0.0/24 and destined for 172.16.50.0/24 through interface eth0) from translation. Note that rule 10 is used to exclude certain traffic from translation and rule 20 is used to perform a translation on the traffic that meets its filter criteria and is not excluded by rule 10. Example211SourceNATexclusionruleusingexcludeStepCreateSNATrule10. Applythisruletopacketscoming fromanyhostonnetwork 192.168.0.0/24,destinedfor 172.16.50.0/24,andegressingvia interfaceeth0. ExcludepacketsfromNAT translationthatmatchthefilter criteriainthisrule.

SourceNATandVPN:Usingtheexclude OptionWhen a packet is matched against the source NAT (including masquerade NAT) filter criteria, the source address of the packet is modified before it is forwarded to its destination. This means that source NAT rules are applied before the VPN process compares the packets against the VPN configuration. If the source network configured for source NAT is also configured to use a site-to-site VPN connection

NAT

R6.4v01

Vyatta

Chapter2:NATConfigurationExamples

SourceNATandVPN:UsingtheexcludeOption 36

using the same externally facing interface, the packets will not be recognized by the VPN process, since the source address has been changed. Consequently, they will not be placed into the VPN tunnel for transport. To account for this behavior, packets destined for a VPN tunnel must be excluded from having NAT applied. You can do this by using an exclusion rule, as shown in Figure 2-11. Figure211SourceNATandVPN

TheNegationOperatorAnother way to exclude a subset of traffic from being translated is by using the negation operator: !. Example 2-13 provides the same functionality as in the previous example, but uses the negation operator instead of the exclude option.

Note that you should take extreme care using more than one negation operator rule in combination. NAT rules are evaluated sequentially, and a sequence of rules that use the negation operator may result in unexpected behavior. Consider the set of two NAT rules shown in Example 2-14. Example214MultiplesourceNATrulesusingthenegationoperator:unexpected behavior

This combination rules will NOT result in the exclusion of networks 192.168.50.0/24 and 172.16.50.0/24. As explained above, these NAT rules are evaluated sequentially: when a packet arrives, it is tested against the first rule and if it does not match, it is tested against the second rule, and so on until it matches a rule. In the example, a packet with a destination in 192.168.50.0/24 does NOT meet the match criteria in rule 10 (which matches all packets with destination NOT in 192.168.50.0/24). As a result, the packet falls through to rule 20. A packet with a destination in 192.168.50.0/24 DOES match rule 20 (because it is not in 172.16.50.0/24), and therefore the packet has NAT applied, which is not the desired result. Similarly, a packet with a destination in 172.16.50.0/24 will be matched and NATted by rule 10.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: source: Defines a source NAT (SNAT) rule. destination: Defines a destination NAT (DNAT) rule. rule-num A numeric identifier for the rule. The range is 19999.

DefaultStatistics counters for all NAT translation rules of the specified type are cleared.

UsageGuidelinesUse this command to clear counters for NAT translation rules. Counters are cleared for all rules of the specified type by default. If a rule number is specified, only counters for that rule are cleared.

UsageGuidelinesUse this command to enable Network Address Translation (NAT) on the Vyatta system. Use the set form of this command to create and modify NAT configuration. Use the delete form of this command to remove NAT configuration and disable NAT on the system. Use the show form of this command to view NAT configuration.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: source: Defines a source NAT (SNAT) rule. destination: Defines a destination NAT (DNAT) rule. rule-num Mandatory. Multi-node. A numeric identifier for the rule. The range is 19999.

DefaultNone.

UsageGuidelinesUse this command to specify a NAT rule configuration.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

49

The rule-type defines the rule as either a source NAT rule or a destination NAT rule. Source NAT rules translate the source IP address. Destination NAT rules translate the destination IP address. Source rules typically egress from the trusted to the untrusted network. For source NAT rules, the translation address typically defines the IP address that faces the untrusted network. This is the address that is substituted in for the original source IP address in egressing packets. Destination rules typically ingress from the untrusted to the trusted network. For destination NAT rules, the translation address typically defines an IP address inside the trusted network. This is the address that is substituted in for the original destinatiuon IP address in ingressing packets. NAT rules are executed in numeric order. To allow insertion of more rules in the future, choose rule numbers with space between; for example, number your initial rule set 10, 20, 30, 40, and so on. Use the set form of this command to create or modify a NAT rule. Use the delete form of this command to remove a NAT rule. Use the show form of this command to view NAT rule configuration.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

50

nat<ruletype>rule<rulenum>description<desc>Specifies a brief description for a NAT rule.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: source: Defines a source NAT (SNAT) rule. destination: Defines a destination NAT (DNAT) rule. rule-num desc A numeric identifier for the rule. The range is 19999. A description for the rule. If the description contains spaces, it must be enclosed in double quotes.

DefaultNone.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

51

UsageGuidelinesUse this command to specify a description for a NAT rule. Use the set form of this command to add or modify the description. Use the delete form of this command to remove the description. Use the show form of this command to view description configuration.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

52

nat<ruletype>rule<rulenum>destinationSpecifies the destination address and port to match in a NAT rule.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: source: Defines a source NAT (SNAT) rule. destination: Defines a destination NAT (DNAT) rule. rule-num Mandatory. Multi-node. A numeric identifier for the rule. The range is 19999.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

53

address

The destination address to match. The following formats are valid: ip-address: An IPv4 address. ip-address/prefix: An IPv4 network address, where 0.0.0.0/0 matches any network. ip-addressip-address: A range of contiguous IPv4 addresses; for example, 192.168.1.1192.168.1.150. !ip-address: Every IPv4 address EXCEPT the one specified. !ip-address/prefix: Every IPv4 network address EXCEPT the one specified. !ip-addressip-address: All IP addresses EXCEPT those in the specified range.

port

The destination port to match. port is only valid for TCP and UDP protocols. The following formats are valid: port-name: The name of an IP service; for example, http. You can specify any service name in the file etc/services. port-num: A port number. The range is 1 to 65535. startend: A range of ports; for example, 10011005. You can use a combination of these formats in a comma-separated list. You can also negate the entire list by prepending it with an exclamation mark (!); for example, !22,telnet,http,123,1001-1005.

DefaultNone.

UsageGuidelinesUse this command to specify the destination to match in a NAT rule. Note that you should take care in using more than one exclusion rule (that is, a rule using the negation operation (!) in combination. NAT rules are evaluated sequentially, and a sequence of exclusion rules could result in unexpected behavior. Use the set form of this command to create a NAT destination filter. Use the delete form of this command to remove a NAT destination filter configuration. Use the show form of this command to view NAT destination filter configuration.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: source: Defines a source NAT (SNAT) rule. destination: Defines a destination NAT (DNAT) rule. rule-num Mandatory. Multi-node. A numeric identifier for the rule. The range is 19999.

DefaultNone.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

57

UsageGuidelinesUse this command to specify that packets matching this rule are to be excluded from address translation. Exclusion can be used in scenarios where certain types of traffic (for example VPN traffic) should not be translated. Use the set form of this command to specify that packets matching this rule will be excluded from NAT. Use the delete form of this command to remove the configuration Use the show form of this command to view the configuration.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

58

nat<ruletype>rule<rulenum>inboundinterface <interface>Specifies the interface on which to match inbound traffic to apply destination NAT rules to.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: destination: Defines a destination NAT (DNAT) rule. rule-num Mandatory. Multi-node. A numeric identifier for the rule. The range is 19999.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

59

interface

The inbound Ethernet or serial interface to match. Destination NAT (DNAT) will be performed on traffic received on this interface. You can specify an individual vif, rather than an entire interface. To do this, refer to the vif using int.vif notation. For example to refer to vif 40 on interface eth0, use eth0.40. You can also specify eth+ to indicate all ethernet interfaces and any to indicate any interface.

DefaultNone.

UsageGuidelinesUse this command to specify the Ethernet or serial interface on which inbound traffic will have destination NAT (DNAT) rules applied.NOTEThiscommandcanonlybeusedfordestinationNATrules(thatis,NATruleswitharuletype ofdestination).Itisnotapplicabletoruleswitharuletypeofsource.

Use the set form of this command to specify inbound interface configuration Use the delete form of this command to remove inbound interface configuration. Use the show form of this command to view inbound interface configuration.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

60

nat<ruletype>rule<rulenum>log<state>Specifies whether or not matched NAT rules are logged.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: source: Defines a source NAT (SNAT) rule. destination: Defines a destination NAT (DNAT) rule. rule-num state Mandatory. Multi-node. A numeric identifier for the rule. The range is 19999. Specifies whether or not to create log entries for matched NAT rules. Supported values are as follows: disable: Log entries are not generated for matched rules. enable: Log entries are generated for matched rules.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

61

DefaultLog entries are not generated for matched rules.

UsageGuidelinesUse this command to specify whether or not log entries are created when a NAT rule is matched. Take care when enabling this feature as it can create very large log files and quickly fill a disk. Use the set form of this command to set the state of NAT logging. Use the delete form of this command to restore the default NAT logging configuration. Use the show form of this command to view NAT logging configuration.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: source: Defines a source NAT (SNAT) rule. rule-num Mandatory. Multi-node. A numeric identifier for the rule. The range is 19999.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

63

interface

Mandatory for source rules. Not configurable for destination rules. The outbound Ethernet or serial interface. Source NAT (SNAT) or masquerade NAT will be performed on traffic transmitted from this interface. You can specify an individual vif, rather than an entire interface. To do this, refer to the vif using int.vif notation. For example to refer to vif 40 on interface eth0, use eth0.40. You can also specify eth+ to indicate all ethernet interfaces and any to indicate any interface.

DefaultNone.

UsageGuidelinesUse this command to specify the Ethernet or serial interface on which outbound traffic will have source NAT (SNAT) rules applied.NOTEThiscommandcanonlybeusedonsourceNATrules(thatis,NATruleswitharuletypeof source).Itisnotapplicabletoruleswitharuletypeofdestination.

Use the set form of this command to specify the outbound interface. Use the delete form of this command to remove outbound interface configuration. Use the show form of this command to view outbound interface configuration.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

64

nat<ruletype>rule<rulenum>protocol<protocol>Specifies which protocols are to have NAT performed on them.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: source: Defines a source NAT (SNAT) rule. destination: Defines a destination NAT (DNAT) rule. rule-num protocol Mandatory. Multi-node. A numeric identifier for the rule. The range is 19999. The protocol(s) on which to perform NAT. Any protocol literals or numbers listed in /etc/protocols can be used. The keywords all (for all protocols) and tcp_udp (for both TCP and UDP protocols) are also supported. Prefixing the protocol name with the exclamation mark character (!) matches every protocol except the specified protocol. For example, !tcp matches all protocols except TCP.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

65

DefaultNone.

UsageGuidelinesUse this command to specify the protocol(s) on which to perform NAT. Note that you should take care in using more than one exclusion rule (that is, a rule using the negation operation (!) in combination. NAT rules are evaluated sequentially, and a sequence of exclusion rules could result in unexpected behavior. Use the set form of this command to specify the protocol(s) on which to perform NAT. Use the delete form of this command to remove the configuration Use the show form of this command to view the configuration.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

66

nat<ruletype>rule<rulenum>sourceSpecifies the source address and port to match in a NAT rule.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: source: Defines a source NAT (SNAT) rule. destination: Defines a destination NAT (DNAT) rule. rule-num Mandatory. Multi-node. A numeric identifier for the rule. The range is 19999.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

67

address

The source address to match. The following formats are valid: ip-address: Matches the specified IP address. ip-address/prefix: A network address, where 0.0.0.0/0 matches any network. ip-addressip-address: Matches a range of contiguous IP addresses; for example, 192.168.1.1192.168.1.150. !ip-address: Matches all IP addresses except the one specified. !ip-address/prefix: Matches all network addresses except the one specified. !ip-addressip-address: Matches all IP addresses except those in the specified range.

port

The source port to match. port is only valid for TCP and UDP protocols. The following formats are valid: port-name: Matches the name of an IP service; for example, http. You can specify any service name in the file etc/services. port-num: Matches a port number. The range is 1 to 65535. startend: Matches the specified range of ports; for example, 10011005. You can use a combination of these formats in a comma-separated list. You can also negate the entire list by prepending it with an exclamation mark (!); for example, !22,telnet,http,123,1001-1005.

DefaultNone.

UsageGuidelinesUse this command to specify the source to match in a NAT rule. Note that you should take care in using more than one exclusion rule (that is, a rule using the negation operation (!) in combination. NAT rules are evaluated sequentially, and a sequence of exclusion rules could result in unexpected behavior. Use the set form of this command to create a NAT source filter. Use the delete form of this command to remove a NAT source filter configuration. Use the show form of this command to view NAT source filter configuration.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

68

nat<ruletype>rule<rulenum>translationSpecifies the translated address and/or port in a NAT rule.

Parametersrule-type Mandatory. An identifier for the type of rule. Supported values are as follows: source: Defines a source NAT (SNAT) rule. destination: Defines a destination NAT (DNAT) rule. rule-num Mandatory. Multi-node. A numeric identifier for the rule. The range is 19999.

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

69

address

The IP address or range of addresses to substitue for the original addresses. If rule-type is source, the address or addresses chosen must be present on the outbound interface. The following formats are valid: ip-address: Translates to the specified IP address. ip-address/prefix: Translates to the specified network. This is typically used in bidirectional NAT to translate one network of addresses to another. ip-addressip-address: Translates to one of the IP addresses in the specified pool of contiguous IP addresses; for example, 192.168.1.1192.168.1.150. masquerade: This is only available when rule-type is set to source. It specifies that the source IP address is to be set to to the primary IP address on the oubound interface.

port

The IP port to substitute for the original port. port is only valid for TCP and UDP protocols. port can not be used if the source address (or destination address) and the translation address are IPv4 subnets. The following formats are valid: port-num: Translates to the specified port number. The range is 1 to 65535. startend: Translates to one of the ports in the specified pool of contiguous ports; for example, 10011005.

DefaultNone.

UsageGuidelinesUse this command to specify the address and/or port translation in a NAT rule. A translation address or a port must be specified for each rule. Use the set form of this command to specify a NAT translation. Use the delete form of this command to remove a NAT translation. Use the show form of this command to view NAT translation.

UsageGuidelinesUse this command to display the NAT rules you have configured. You can use this command for troubleshooting, to confirm whether traffic is matching the NAT rules as expected.

ExampleExample 3-3 shows sample output for the show nat rule-type rules command. In the output for this example, the following abbreviations occur: saddr represents the source address sport represents the source port daddr represents the destination address dport represents the destination port proto represents the protocol intf represents the interface.

Note also the following about this example:

NAT

R6.4v01

Vyatta

Chapter3:NATCommands

71

There is only one interface column (intf). For a source NAT rule, this interface refers to the outgoing interface; for a destination NAT rule, this interface is the incoming interface. In the translation column, first two rows report translation information and the third row (if it occurs) reports the conditions required for translation to be performed. In the example, rule 10, which is an SNAT rule, translates source address 192.168.74.0/24 to 172.16.139.0/24, leaves the source port at its original value, and translates when (and only when) the destination port is 80 for any destination address. An X at the front of a rule (as for rule 20 in the example) means that the rule has been excluded. An M signifies a masquerade rule.