How to redirect all HTTP request to a local web server, supposing we don't have an internet connectionsExempleWeb server with @IP 192.168.1.1, running apacheClient 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:80I need to do this with iptables, and thank you guys for the help :)
How to redirect all HTTP request to a local web server
iptables
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