3

How to redirect all HTTP request to a local web server, supposing we don't have an internet connections

Exemple

  • Web server with @IP 192.168.1.1, running apache
  • Client with @IP 192.168.1.X making a HTTP request to X.X.X.X:80-443, and no internet connection is available for always, so all those traffic should be directly redirected to 192.168.1.1:80

I need to do this with iptables, and thank you guys for the help :)

3
  • You can't use dnsmasq? Commented May 16, 2015 at 14:11
  • 1
    Nm, dnsmasq was a bad idea Commented May 16, 2015 at 14:16
  • I think that if i use dns spoofing, we must to flush the DNS cache of client machine Commented May 16, 2015 at 19:44

1 Answer 1

2

This is an example taken from http://www.andybev.com/index.php/Using_iptables_and_PHP_to_create_a_captive_portal . This does exactly what you want:

IPTABLES=/sbin/iptables # Create internet chain # This is used to authenticate users who have already signed up $IPTABLES -N internet -t mangle # First send all traffic via newly created internet chain # At the prerouting NAT stage this will DNAT them to the local # webserver for them to signup if they aren't authorised # Packets for unauthorised users are marked for dropping later $IPTABLES -t mangle -A PREROUTING -j internet $IPTABLES -t mangle -A internet -j MARK --set-mark 99 # Redirects web requests from Unauthorised users to internet webserver $IPTABLES -t nat -A PREROUTING -m mark --mark 99 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.1 # Now that we've got to the forward filter, drop all packets # marked 99 - these are unknown users. We can't drop them earlier # as there's no filter table $IPTABLES -t filter -A FORWARD -m mark --mark 99 -j DROP # Do the same for the INPUT chain to stop people accessing the web through Squid $IPTABLES -t filter -A INPUT -p tcp --dport 80 -j ACCEPT $IPTABLES -t filter -A INPUT -p udp --dport 53 -j ACCEPT $IPTABLES -t filter -A INPUT -m mark --mark 99 -j DROP 
1
  • Thank you very much, it seems pretty much what i want to do :) Commented May 18, 2015 at 12:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.