Ubuntu – How to Restrict User Access to Certain Ports

portUbuntuubuntu-11.10

This question is purely hypothetical. Is it possible to restrict which ports certain users may use for their processes? Say users1 gets ports 8000-8999 and user2 gets ports 9000-9999.

I am running Ubuntu 11.10.

Best Answer

The only Linux native application that can handle this kind of restriction might be SElinux, which is part of the Ubuntu distribution. SElinux is well complicated and I am not sure how you would implement port restrictions on a per user bassis. That will be between you and Google.

This discussion mentions two kernel patches (GRsecurity and TOMOYO) which specifically allow port restrictions at the application level, although the discussion includes reference to per user port restriction.

Lastly, I have seen links to another kernel patch called 'user-port-hack' but its project page is not forthcoming and one kernel post mentions that it is for kernel 2.4 only. Perhaps you can dig for that.

A left field solution I can see for your requirement is to simply ask users to conform to a policy. i.e. "User X, please only use ports 8000-8999."

Alternatively, if your users insist on using ports other than the 1000 they have been allocated, you could isolate users to their own dedicated virtual machines and then implement firewall/iptables rules at the host level to limit the traffic to a certain port range for each VMs IP address.