Linux – Redirect specific IP address to a another site/page/IP using IPTABLES

apache-2.2iptableslinuxredirect

Currently, I am using IPTABLES to ban people from accessing my site. Using this format in IPTABLES:

  iptables -I INPUT -s 96.266.184.52 -j DROP -m comment --comment "whatever I have to say"

I would like to instead have it setup where iptables will redirect that specific person (IP 96.266.184.52 in this case) to a webpage where it says they are banned, and the steps involved to get unbanned. Rather I do this using apache, another IP, redirecting them to a specific port, whatever the case may be I would like to not access anything of mine except that one webpage telling them how to be unbanned.

Best Answer

To do this with iptables you could setup a virtual server in apache listening on an alternate port with the docroot set to the instructions for how to be un-banned.

iptables -t nat -I PREROUTING -p tcp --dport 80 -s 96.266.184.52 -j DNAT --to-destination $server_ip_address:$alternate_apache_port
Related Topic