Penguin
Note: You are viewing an old revision of this page. View the current version.

After asking PerryLorier about allowing a user process to bind to port 80, the response that he and JohnMcPherson gave didn't leave me feeling all too inspired about achieving the task without stress and fatigue.

<Bryin?> Isomer?: Do you know how to let user processes bind to ports < 1024
<@Isomer?> Bryin?: run as root?
<@Isomer?> or give them cap_net IIRC
<kinko> Bryin?: only root can... normally your program is setuid root, and after binding to the port it immediately changes to nobody or some other normal user
<@Isomer?> Bryin?: the answer is, normally it doesn't work very well at all.
<@Isomer?> as root you can give yourself the cap_net_bind privilege, then change user, keeping that privilege
<Bryin?> I'll wiki this when I find a tidy solution

After this dialogue on the IRC channel of #wlug, I proceeded to think about cats and skinning. I then realised, "There is another solution!". I had decided I was going to make the application (a Java server) bind to port 8080 and get the OperatingSystem to perform the legwork.

Thankfully this turned out to be much easier than I expected.

I configured the port forwarding with the command below (replacing content between the angled brackets with the appropriate port numbers)

iptables --table nat -A PREROUTING -p tcp --dport <incoming port> -i eth0 -j REDIRECT --to-ports <local port>

Then I saved the configuration so that things work after, heaven forbid, a reboot!

/etc/init.d/iptables save


UserSubmittedNotes