2 fixing typo (changed 'web side' to webpage)
source | link

So here is my high level goal:

I have Linux running on a small device that acts as a Wifi-Hotspot for wireless clients. It also runs a web server (nginx) for configuration and I would like to redirect all html requests from my Wifi clients to that local web-server until it is configured correctly, once configured correctly it should stop redirecting and go back to just routing the traffic.

I am relatively new to iptables, ip route & co, so not sure if my approach is correct:

ATM I just use iptables to redirect http traffic to my local webserver when in 'config mode' (and clearing those rules when back in normal mode):

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.42.1
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 192.168.42.1
iptables -t nat -A PREROUTING -p tcp --dport 5000 -j DNAT --to-destination 192.168.42.1

(I need port 5000 as my config software runs a websockets server for the config web sidewebpage)

This works fine as long the client can resolve DNS requests (or use hard coded IP address). My dhcp server sets default 8.8.8.8/8.8.4.4 as DNS server on the wifi clients, but if 8.8.8.8 cannot be reached (this can be the case when the device is not configured correctly) the client will not hit my config web page since the wifi client cannot resolve the ip address in the first place.

So my thinking was to setup a DNS server on my device that just forwards DNS requests when in 'normal mode' , but when in 'config mode' it would resolve all requests to my local web server IP.

Here my questions: What software would I use for this (dnsmasq?) and how would I set it up so I can make it switch (during runtime) between just forwarding DNS requests and resolving request to my local server?

Or is the approach wrong and I should use some proxy or other way for the redirect? One downside I see having a DNS server temporary resolve requests to my local IP is that clients might cache the result, so they would still hit my local web server even the configuration is done.

So here is my high level goal:

I have Linux running on a small device that acts as a Wifi-Hotspot for wireless clients. It also runs a web server (nginx) for configuration and I would like to redirect all html requests from my Wifi clients to that local web-server until it is configured correctly, once configured correctly it should stop redirecting and go back to just routing the traffic.

I am relatively new to iptables, ip route & co, so not sure if my approach is correct:

ATM I just use iptables to redirect http traffic to my local webserver when in 'config mode' (and clearing those rules when back in normal mode):

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.42.1
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 192.168.42.1
iptables -t nat -A PREROUTING -p tcp --dport 5000 -j DNAT --to-destination 192.168.42.1

(I need port 5000 as my config software runs a websockets server for the config web side)

This works fine as long the client can resolve DNS requests (or use hard coded IP address). My dhcp server sets default 8.8.8.8/8.8.4.4 as DNS server on the wifi clients, but if 8.8.8.8 cannot be reached (this can be the case when the device is not configured correctly) the client will not hit my config web page since the wifi client cannot resolve the ip address in the first place.

So my thinking was to setup a DNS server on my device that just forwards DNS requests when in 'normal mode' , but when in 'config mode' it would resolve all requests to my local web server IP.

Here my questions: What software would I use for this (dnsmasq?) and how would I set it up so I can make it switch (during runtime) between just forwarding DNS requests and resolving request to my local server?

Or is the approach wrong and I should use some proxy or other way for the redirect? One downside I see having a DNS server temporary resolve requests to my local IP is that clients might cache the result, so they would still hit my local web server even the configuration is done.

So here is my high level goal:

I have Linux running on a small device that acts as a Wifi-Hotspot for wireless clients. It also runs a web server (nginx) for configuration and I would like to redirect all html requests from my Wifi clients to that local web-server until it is configured correctly, once configured correctly it should stop redirecting and go back to just routing the traffic.

I am relatively new to iptables, ip route & co, so not sure if my approach is correct:

ATM I just use iptables to redirect http traffic to my local webserver when in 'config mode' (and clearing those rules when back in normal mode):

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.42.1
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 192.168.42.1
iptables -t nat -A PREROUTING -p tcp --dport 5000 -j DNAT --to-destination 192.168.42.1

(I need port 5000 as my config software runs a websockets server for the config webpage)

This works fine as long the client can resolve DNS requests (or use hard coded IP address). My dhcp server sets default 8.8.8.8/8.8.4.4 as DNS server on the wifi clients, but if 8.8.8.8 cannot be reached (this can be the case when the device is not configured correctly) the client will not hit my config web page since the wifi client cannot resolve the ip address in the first place.

So my thinking was to setup a DNS server on my device that just forwards DNS requests when in 'normal mode' , but when in 'config mode' it would resolve all requests to my local web server IP.

Here my questions: What software would I use for this (dnsmasq?) and how would I set it up so I can make it switch (during runtime) between just forwarding DNS requests and resolving request to my local server?

Or is the approach wrong and I should use some proxy or other way for the redirect? One downside I see having a DNS server temporary resolve requests to my local IP is that clients might cache the result, so they would still hit my local web server even the configuration is done.

1
source | link

Temporary DNS resolve to local ip (for temporary http redirect)

So here is my high level goal:

I have Linux running on a small device that acts as a Wifi-Hotspot for wireless clients. It also runs a web server (nginx) for configuration and I would like to redirect all html requests from my Wifi clients to that local web-server until it is configured correctly, once configured correctly it should stop redirecting and go back to just routing the traffic.

I am relatively new to iptables, ip route & co, so not sure if my approach is correct:

ATM I just use iptables to redirect http traffic to my local webserver when in 'config mode' (and clearing those rules when back in normal mode):

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.42.1
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 192.168.42.1
iptables -t nat -A PREROUTING -p tcp --dport 5000 -j DNAT --to-destination 192.168.42.1

(I need port 5000 as my config software runs a websockets server for the config web side)

This works fine as long the client can resolve DNS requests (or use hard coded IP address). My dhcp server sets default 8.8.8.8/8.8.4.4 as DNS server on the wifi clients, but if 8.8.8.8 cannot be reached (this can be the case when the device is not configured correctly) the client will not hit my config web page since the wifi client cannot resolve the ip address in the first place.

So my thinking was to setup a DNS server on my device that just forwards DNS requests when in 'normal mode' , but when in 'config mode' it would resolve all requests to my local web server IP.

Here my questions: What software would I use for this (dnsmasq?) and how would I set it up so I can make it switch (during runtime) between just forwarding DNS requests and resolving request to my local server?

Or is the approach wrong and I should use some proxy or other way for the redirect? One downside I see having a DNS server temporary resolve requests to my local IP is that clients might cache the result, so they would still hit my local web server even the configuration is done.