すべてのHTTPリクエストをローカルWebサーバーにリダイレクトする方法

すべてのHTTPリクエストをローカルWebサーバーにリダイレクトする方法

インターネットに接続されていないと仮定すると、すべてのHTTPリクエストをローカルWebサーバーにリダイレクトする方法

はい

  • Webサーバー@IP 192.168.1.1、Apacheの実行
  • @IP 192.168.1.XのクライアントはXXXX:80-443にHTTPリクエストを行い、常にインターネットに接続されていないため、これらのトラフィックはすべて192.168.1.1:80に直接リダイレクトする必要があります。

これを行うには、iptablesを使用する必要があります。助けてくれてありがとう :)

ベストアンサー1

これはからインポートされた例です。http://www.andybev.com/index.php/Using_iptables_and_PHP_to_create_a_captive_portal。これがまさにあなたが望むものです:

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

おすすめ記事