Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Linux Networking Cookbook

You're reading from   Linux Networking Cookbook Over 40 recipes to help you set up and configure Linux networks

Arrow left icon
Product type Paperback
Published in Jun 2016
Publisher
ISBN-13 9781785287916
Length 152 pages
Edition 1st Edition
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Gregory Boyce Gregory Boyce
Author Profile Icon Gregory Boyce
Gregory Boyce
Agnello Dsouza Agnello Dsouza
Author Profile Icon Agnello Dsouza
Agnello Dsouza
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Configuring a Router 2. Configuring DNS FREE CHAPTER 3. Configuring IPv6 4. Remote Access 5. Web Servers 6. Directory Services 7. Setting up File Storage 8. Setting up E-mail 9. Configuring XMPP 10. Monitoring Your Network 11. Mapping Your Network 12. Watching Your Network Index

Setting up port forwarding

In the previous section, we configured iptables to accept connections to port 22 in order to allow people to SSH into the host. Sometimes, you want to forward a port to a system behind the firewall instead of having the service run on the firewall itself. For example, you may have a web server running on port 8080 on an internal box that you want to expose to the Internet via port 80 on the firewall.

How to do it…

  1. Rewrite packets addressed to port 80 to instead go to port 8080:
    # iptables -t nat -A PREROUTING -p tcp -i eth2 --dport 80 \
    -j DNAT --to-destination 192.168.0.200:8080 
    
  2. Accept any packets addressed to 192.168.0.200 port 8080:
    # iptables -A FORWARD -p tcp -d 192.168.0.200 \
    --dport 8080 -m state --state NEW,ESTABLISHED,RELATED \
    -j ACCEPT 
    

How it works…

This example is a lot simpler since it builds upon concepts we've already learned. We just have two simple commands:

  • First we set up a PREROUTING rule which will be processed once the packet is received, prior to any routing rules being applied. If the packet is TCP and came in on the Internet interface (eth2) with a destination port, then the packet is added to the destination NAT (DNAT) chain with a final destination of 192.168.0.200 port 8080.
  • Next, any packet destined for 192.168.0.200 port 8080 is either a new connection or an established connection; the packet is then accepted for forwarding to the destination.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image