Results 1 to 4 of 4
  1. #1
    Join Date
    May 2007
    Posts
    83

    iptables redirect rule - please help

    Hello!

    Please help me to write iptables rule, I need to redirect specific external IPs to another IP instead main website IP.

    Any way to do this?

    Thank you!

  2. #2
    Join Date
    Mar 2009
    Location
    /home/khunj
    Posts
    432
    Try something like this :

    Code:
    fromIP=xx.xx.xx.xx
    fromPort=xx
    toIP=xx.xx.xx.xx
    toPort=xx
    echo 1 > /proc/sys/net/ipv4/ip_forward
    iptables -t nat -A PREROUTING --dst $fromIP -p tcp --dport $fromPort -j DNAT --to-destination $toIP:$toPort
    iptables -t nat -A POSTROUTING -p tcp --dst $toIP --dport $toPort -j SNAT --to-source $fromIP
    iptables -t nat -A OUTPUT --dst $fromIP -p tcp --dport $fromPort -j DNAT --to-destination $toIP:$toPort
    NinTechNet
    ★ NinjaFirewall : Web Application Firewall for PHP and WordPress.
    ★ NinjaMonitoring : Monitor your website for suspicious activities.

  3. #3
    Join Date
    May 2007
    Posts
    83
    What does it mean?

    --dport $fromPort
    Which port I need to specify, if this is standard request from user to website?

  4. #4
    Join Date
    Mar 2009
    Location
    /home/khunj
    Posts
    432
    Your visitors will connect to fromIP:fromPort and then iptables will redirect them to toIP:toPort
    Note that due to SNAT/DNAT, when your visitors will reach toIP, their IP will be fromIP, not their originating IP. If you need to identify them, use preferably a HTTP reverse proxy that will add their originating IP in the X-Forwarded-For variable.
    NinTechNet
    ★ NinjaFirewall : Web Application Firewall for PHP and WordPress.
    ★ NinjaMonitoring : Monitor your website for suspicious activities.

Similar Threads

  1. Delete rule in iptables
    By Adwis in forum Hosting Security and Technology
    Replies: 3
    Last Post: 08-15-2011, 12:15 PM
  2. The VPS iptables rule limit
    By persianwhois in forum Hosting Security and Technology
    Replies: 3
    Last Post: 08-07-2008, 10:59 AM
  3. Iptables rule limit (numiptent)
    By persianwhois in forum Hosting Security and Technology
    Replies: 4
    Last Post: 06-02-2008, 03:47 AM
  4. iptables rule for ftp
    By SmartTux in forum Hosting Security and Technology
    Replies: 4
    Last Post: 01-07-2005, 12:38 PM
  5. iptables rule assistance
    By enquire in forum Hosting Security and Technology
    Replies: 3
    Last Post: 09-03-2004, 02:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •