Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am working on a class project where we are making a captive portal, before you login to a web page hosted on the gateway all traffic trying to go past the router will not be forwarded.
I have a ubuntu machine set up as the gateway, with a apache hosting the login page.
The page currently will allow user to log in and then it changes the iptables rules to allow the traffic through the gateway... however I am having problems redirecting traffic to the gateway before they log in. What needs to happen is that all http requests before they are loged in are redirected to the login page.
I know there are plenty of programs that do this for me but I am not allowed to use them.
Thank you for being forthright about your problem being a school assignment. I'll be equally forthright and tell you I have never tried to do such a thing! Also, generally it is best (for the student) if a student figures out their own assignment, because that is where learning happens. (Yes, I've struggled with problems both while in "formal education" settings as well as outside such settings. The struggle and mistakes usually teaches you a lot.) But perhaps I can give you a nudge in (what I think!) is the right direction. Please realize I could be wrong, and, in any event, you need to work out the details.
I understandand you have Apache already running with the "login page" available? I suggest that you look at the REDIRECT target (-j REDIRECT) in the PREROUTING table to direct the outgoing request to the login page. You will, of course, have to make sure that users who have already logged in do not get so REDIRECTed. The ipablesman page is an excellent source of information about this. (As are Internet search engines.)
I suggest that you look at the REDIRECT target (-j REDIRECT) in the PREROUTING table to direct the outgoing request to the login page. You will, of course, have to make sure that users who have already logged in do not get so REDIRECTed.
Thanks!
I had seen --to-destination and I was trying to use that, but "REDIRECT --to-ports 80" was what I was missing and that works to redirect them. Now I just need to get the syntax right to stop the redirection once they log in.
I am assuming that the original poster has now finished their assignment, so for the benefit of anyone else coming across this thread, I have written full details of how to do this here
The page at the link describes how to create a captive web portal using iptables. Traffic is redirected from a client until they signup on a PHP webpage. It uses sudo to allow apache to insert the firewall rules, and importantly also uses conntrack to remove stale connection tracking information after they have signed up. If this is not done, I have found that a user can sometimes still not access the desired website after they have signed up.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.