NAT and port forwarding on Cisco

Internet access for the local network and port forwarding to servers.
Ready IOS commands with access by address, verification and rollback.

NAT and port forwarding on Cisco

Internet access for the local network through one public address (PAT) and port forwarding to servers — ready IOS and IOS XE commands with an access list and a rollback.

As in show ip interface brief: GigabitEthernet0/0, Dialer1.
Comma-separated: GigabitEthernet0/1, Vlan10.
Comma-separated. These networks reach the internet through the outside address.

Port forwarding

Each rule opens a port on the outside address and sends it to a server on the local network. The outside port and the server port may differ.

Configuration

   
Verification

   
Rollback

   

The commands are built in your browser; addresses are not sent anywhere.

How NAT works on Cisco

On a Cisco router NAT is built from three parts. Interfaces are marked as inside (ip nat inside) and outside (ip nat outside). A standard access list says which addresses may go out to the internet, and ip nat inside source list … overload replaces them with the outside address and different ports — that is PAT. Port forwarding is a static rule, ip nat inside source static tcp: packets to the outside port go to a server on the local network.

How to use it

  1. Enter the outside interface, the inside interfaces and the networks — names as in show ip interface brief.
  2. Choose whether your outside address is dynamic or static. With a dynamic one the rules are tied to the interface.
  3. Add forwarding rules: the outside port, the server address and port. For RDP, SSH and databases, list in “Sources” the addresses allowed to connect.
  4. Paste the configuration in configure terminal mode, test from outside and only then save: copy running-config startup-config.

Access only from the addresses you need

The PASW-WAN-IN list is applied inbound on the outside interface. On IOS an inbound list is checked before NAT, so it contains the outside port and the outside address, not the server address. Each restricted rule gets a permit from the listed addresses and a deny for everyone else, and the list ends with permit ip any any so other traffic is untouched. If the interface already has a list of its own, move the lines into it. The ACL generator helps build a list from address ranges, and for MikroTik there is MikroTik port forwarding.

Frequently asked questions

Why extendable in a static rule?

Without it IOS will not let you forward several ports of one outside address to the same inside address. The generator adds extendable when a server has more than one rule and the outside address is static. Rules with interface do not need it.

Why doesn't the forwarded port open from the local network?

Classic NAT on IOS does not turn traffic back inside. From inside, reach the server by its inside address or add a record with the inside address to your internal DNS. Test forwarding from outside, for example over mobile internet.

Do the commands work on ASA?

No. On ASA and Firepower, NAT is set up with object network and nat (inside,outside). The generator is for IOS and IOS XE routers: ISR, the 800, 1900, 2900 and 4000 series, Catalyst 8000 and others.

How do I check that NAT works?

show ip nat translations lists the current translations, show ip nat statistics shows the counters and the inside and outside interfaces, and show access-lists PASW-WAN-IN shows how many packets hit each line of the list. Dynamic translations can be cleared with clear ip nat translation *.

More tools

Cisco

Cisco backup link (IP SLA)
IP SLA, track, NAT on two links
Cisco VLAN lists
Compress, compare, add/remove for trunks
DHCP server on Cisco
Pools, exclusions, fixed addresses
Cisco port configuration
access, voice, trunk, Port Security for many ports
EtherChannel on Cisco
LACP, PAgP, trunk and commands for the other end
Cisco L2 security
DHCP snooping, DAI, IP Source Guard
Cisco SNMPv3
authPriv instead of communities, ACL, traps
Cisco config diff
Section by section, with draft commands