InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Networking tutorials

  • DIG quick start tutorial
  • Dig - list all dns records
  • How to view wifi connection speed on Mac
  • Linux iptables - Nat port forwarding using PREROUTING
  • Linux iptables and ip6tables examples
  • Ngrep - quick start guide
  • Use nc to check if a remote port is reachable
  • Use nc to listen to tcp or udp port
  • Use nc to test HTTP url redirection
  • add more DNS servers to Wi-Fi interface on Mac
  • locally override website host to IP mapping
  • use nc to print headers from browser
 
  • Home
  • > Tutorials
  • > Networking

Linux iptables – Nat port forwarding using PREROUTING

on Sep 23, 2018

One can use iptables to forward a specific port to another port using NAT PREROUTING chain. This can be used to make a server available on a different port for users.

  1. Add NAT forwarding using PREROUTING chain
    $ sudo iptables -t nat -A PREROUTING -p tcp --dport 81 -j REDIRECT --to-port 80
    
  2. Add NAT forwarding using PREROUTING chain on a specific interface
    $ sudo iptables -t nat -A PREROUTING -p tcp -d INTERFACE_IP --dport 443 -j REDIRECT --to-port 8443
    
  3. List iptable nat PREROUTE rules
    ## -n (numeric)
    $ sudo iptables -t nat -L PREROUTING -n  --line-numbers
    Chain PREROUTING (policy ACCEPT)
    num  target     prot opt source               destination         
    1    REDIRECT   tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:81 redir ports 80
    2    REDIRECT   tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:82 redir ports 80
    
  4. List all rules with line numbers
    $ sudo iptables -n -L -v --line-numbers
    
  5. Delete a specific rule
    $ sudo iptables -t nat -D PREROUTING [NUM]
    

Suggested posts:

  1. AngularJS ng-if vs ng-hide/ng-show
  2. Use x2go to access remote Ubuntu Linux
  3. Linux iptables and ip6tables examples
  4. How to migrate wordpress from root to sub directory
  5. Java – Arrays.sort custom Comparator example
  6. How to monitor 404 pages on your site
  7. CSS – enlarge image on hover
  8. Enable query log without restarting mysql on Linux
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, Networking, Tutorials, Unix
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress