Cisco ASA NAT Port Forwarding

NAT Port Forwarding is useful when you have a single public IP address and multiple devices behind it that you want to reach from the outside world. Take a look at the example below:

ASA1 forwards 192.168.2.254:80 to the HTTP server and 192.168.2.254:10022 to the SSH server in the DMZ

I’m using a Cisco ASAv firewall running ASA 9.24 and routers running Cisco IOS 15.9 (IOSv) for the HTTP server, the SSH server and R2. In the topology above we have an ASA firewall with a DMZ and two servers…an HTTP server and an SSH server. Let’s imagine that the IP address on the ASA’s Gi0/0 interface (192.168.2.254) is a public IP address. Our goal is to make sure that we can reach these servers from the outside world. R2 is only there so we have a device in the “outside” so we can try if NAT is working.

Configurations

Want to take a look for yourself? Here you will find the startup configuration of each device.

ASA1

hostname ASA1
!
interface GigabitEthernet0/0
 nameif OUTSIDE
 security-level 0
 ip address 192.168.2.254 255.255.255.0 
!             
interface GigabitEthernet0/1
 nameif DMZ
 security-level 50
 ip address 192.168.3.254 255.255.255.0 
!
: end

HTTP

hostname HTTP
!
no ip routing
!
interface GigabitEthernet0/1
 ip address 192.168.3.1 255.255.255.0
 no ip route-cache
 duplex auto
 speed auto
 media-type rj45
!
ip default-gateway 192.168.3.254
!
ip http server
!
end

SSH

hostname SSH_SERVER
!
no ip routing
!
ip domain name NETWORKLESSONS.LOCAL
!
username cisco secret 9 $9$XwjB5ursJ2hNVv$WGXJKKtH7ullKSNDLRGhEE0967yFaIFQy/6keGL4/2g
!
ip ssh version 2
!
interface GigabitEthernet0/1
 ip address 192.168.3.3 255.255.255.0
 no ip route-cache
 duplex auto
 speed auto
 media-type rj45
!
ip default-gateway 192.168.3.254
ip forward-protocol nd
!
line vty 0 4
 login local
 transport input ssh
!
end

R2

hostname R2
!
no ip routing
!
interface GigabitEthernet0/1
 ip address 192.168.2.2 255.255.255.0
 no ip route-cache
 duplex auto
 speed auto
 media-type rj45
!
ip default-gateway 192.168.2.254
!
end

HTTP uses TCP port 80 and SSH uses TCP port 22 so what we’ll do is forward these ports. Whenever someone connects on IP address 192.168.2.254 TCP port 80 we will forward them to 192.168.3.1 TCP port 80.

We can use different port numbers if we want and to demonstrate this, we will configure the ASA so that whenever someone connects on 192.168.2.254 TCP port 10022, we will forward it to 192.168.3.3 TCP port 22.

Let me show you how to configure this. We start with the HTTP server:

ASA1(config)# object network WEB_SERVER
ASA1(config-network-object)# host 192.168.3.1
ASA1(config-network-object)# nat (DMZ,OUTSIDE) static interface service tcp 80 80

We create a network object that specifies the real IP address of the web server and then we create our NAT rule. By using the keyword interface we tell the ASA to use the IP address on the (outside) interface. The first port number is the port that the server is listening on, the second port number is the outside port number.  Let’s configure another PAT entry for the SSH server:

ASA1(config)# object network SSH_SERVER
ASA1(config-network-object)# host 192.168.3.3
ASA1(config-network-object)# nat (DMZ,OUTSIDE) static interface service tcp 22 10022

This network object is similar to the first one but you can see I used a different port number for the outside. Whenever someone connects on TCP port 10022, it will be forwarded to TCP port 22. This takes care of the NAT rules but don’t forget to create an access-list or our traffic will be dropped:

Sign up for FREE to Get Started

Here's what you'll get:

  • Full Access to 448 lessons.
  • Learn CCNA, CCNP and CCIE R&S. Explained as simple as possible.
  • Unlock Access to this lesson + 424 more by becoming a member.
  • New Lessons Added Regularly. You'll Be the First to Know.
  • Content created by Rene Molenaar (CCIE #41726)

Takes 1 minute - No credit card needed

Tags: , ,


Forum Replies

  1. Avatar for rspela830 rspela830 says:

    Rene,

    Your scenario explains forwarding traffic to port 22 for SSH, but further down in your configuration example you are using port 25 for SMTP. Any reason for the change between the scenario and the example configuration??

  2. Avatar for ReneMolenaar ReneMolenaar says:

    Hi Ralph,

    That was a typo, I just changed port 25 to 22. Thanks for letting me know!

    Rene

  3. Avatar for taslimmajid taslimmajid says:

    Hi Rene,

    Thank you for the explanation.

    I have a question.

    In this tutorial, you are using PAT for sending traffic from Outside to DMZ. However, if I want to use PAT for sending traffic from DMZ to Outside, how should I do the configurations ?

    Thank you

    Taslim

  4. Avatar for ReneMolenaar ReneMolenaar says:

    Hi Taslim,

    Hmm why would you want to do this? :slight_smile: We use PAT in this example so that someone on the Internet is able to connect to a public IP address on the outside so that we can reach our DMZ servers with private IP addresses.

    Our DMZ servers can reach the Internet by using “regular” NAT.

    Rene

  5. Avatar for hvasudeva hvasudeva says:

    Hi Rene,

    Diagram needs to be updated to 192.16.1.0/24 for lan subnet.

66 more replies! Ask a question or join the discussion by visiting our Community Forum