LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 01-29-2017, 01:07 AM   #1
reevv
LQ Newbie
 
Registered: Aug 2016
Posts: 23

Rep: Reputation: Disabled
Custom iptables redirect


Hello,

Currently, I'm running two websites on the same IP with apache virtualhost. One of the sites gets often attacked by bots so what I did is redirect those IPs to a third virtual host that is listening on port 88 and displays a 'your ip has been blocked page'.

What i've used to redirect traffic is:

Code:
iptables -t nat -A PREROUTING -p tcp -s ATTACKING-IP --dport 80 -j REDIRECT --to 88
The question is, can this be done just for incoming traffic to website1?

If an ip has currently a redirect rule in iptables, if it tries to access website1 or website2, it gets redirected to virtualhost:88, i am trying to make it so if an iptables redirect ip tries to access website1, to get redirected to virtualhost:88, but if the same ip tries to access website2, it displays the normal website2,

Can this be done with a single IP?

Thank you!
 
Old 01-30-2017, 06:18 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by reevv View Post
Can this be done with a single IP?
Short answer - Yes.

However what you'll need to do is packet inspection. You'll need to inspect the content to detect the HOST: http header in the request. Roughly you'll need something like (untested!)

Code:
-p tcp --dport 80 -m string --algo bm --string 'HOST: website1.domain.name'
 
Old 01-30-2017, 11:43 PM   #3
reevv
LQ Newbie
 
Registered: Aug 2016
Posts: 23

Original Poster
Rep: Reputation: Disabled
Thank you for your reply

Code:
iptables -t nat -A PREROUTING -p tcp -s test.ip --dport 80 -m string --algo bm --string 'HOST: website1' -j REDIRECT --to 88
this allows test.ip to access website1 and website2 just like nothing ever happened
 
Old 02-04-2017, 08:26 AM   #4
netguy2000
Member
 
Registered: Oct 2003
Location: Karachi, PAKISTAN
Distribution: Redhat, Fedora, Open BSD, FreeBSD, SlackWare
Posts: 115

Rep: Reputation: 15
write answer by Ten Tenths,this will help other as well as me , thanks Ten Tenths.

netguy.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
syslog, redirect logging on multiple files with custom name mr.simo Linux - Server 1 05-04-2015 06:29 AM
Lipipq(iptables) . How do I redirect captured packet to another address with iptables inet905 Programming 0 05-25-2010 01:20 AM
iptables to redirect ip genderbender Linux - Networking 1 04-06-2008 01:53 AM
iptables redirect sanjibgupta Linux - Networking 3 05-18-2007 03:16 AM
iptables redirect _ben_deb_ Linux - Networking 7 11-13-2004 05:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration