IpTables rules for captive portal

captive-portaliptables

I am trying to make a captive portal and I use the following iptables rules.

IPTABLES="/sbin/iptables"
EBTABLES="/sbin/ebtables"
DHCP="67:68"
SSH="22"
WWW="80"

$IPTABLES -t mangle -F
$IPTABLES -F

$IPTABLES -A INPUT -i lo -j ACCEPT
#ssh
$IPTABLES -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT


$IPTABLES -A INPUT -s 8.8.8.8 -j ACCEPT
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT


$IPTABLES -N internet -t mangle
$IPTABLES -t mangle -A PREROUTING -j internet

awk 'BEGIN { FS="\t"; } { system("$IPTABLES -t mangle -A internet -m mac --mac-source "$4" -j RETURN"); }' /var/lib/users

$IPTABLES -t mangle -A internet -j MARK --set-mark 99

$IPTABLES -t nat -A PREROUTING -m mark --mark 99 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.1

#$IPTABLES -t filter -A FORWARD -m mark --mark 99 -j DROP
#dns
$IPTABLES -t filter -A INPUT -s 8.8.8.8 -j ACCEPT
#http
$IPTABLES -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
#port dns
$IPTABLES -t filter -A INPUT -p udp --dport 53 -j ACCEPT
#drop
$IPTABLES -t filter -A INPUT -m mark --mark 99 -j DROP
echo "1" > /proc/sys/net/ipv4/ip_forward

$IPTABLES -A FORWARD -i eth0 -o eth0:1 -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i eth0:1 -o eth0 -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -o eth0 -j MASQUERADE

They do work, I mark all the packages and then redirect them to local page. Unfortunately, redirection does not work, when I load https pages. I have tried adding following rule:

$IPTABLES -t nat -A PREROUTING -m mark --mark 99 -p tcp --dport 443 -j DNAT --to-destination 192.168.1.1

But it did not help. What is wrong with these rules? I need to redirect entire traffic to one page.

I would appreciate any help.

Best Answer

As I know, you cannot redirect traffic from 443 port to 80.

You can try to use mod_rewrite in Apache2 to solve your problem.