Presuming you only want to accept incoming TCP traffic, you can use these rules to restrict outgoing traffic to established TCP connections (which would have to have been initiated from the outside) and IP addresses outside your LAN:
iptables -A INPUT -p tcp -i lo -j ACCEPT
iptables -A INPUT -p tcp -p 22 -j ACCEPT # repeat for other ports you want to allow
iptables -P INPUT -j DENY
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT -p tcp \! -d 10.0.0.0/8 -j ACCEPT # replace by your LAN's network(s)
iptables -A OUTPUT -p tcp \! --syn -j ACCEPT
iptables -P OUTPUT -j DENY
Given your requirements, you may prefer to apply some rules specifically to processes executed by the supporters. Supposing they are in the supporters
group, the following rules will deny supporters (and only supporters) all connections (incoming or outgoing) inside your LAN:
iptables -I INPUT \! -i lo -s 10.0.0.0/8 -m owner --gid-owner supporters -j DENY
iptables -I OUTPUT \! -o lo -d 10.0.0.0/8 -m owner --gid-owner supporters -j DENY
Note that gid-owner
tests the process's fsgid, which is almost always the effective GID. Unless a process is run setgid or switches its effective GID to a supplementary group, the user's primary group (recorded in the user database, e.g. /etc/passwd
) applies.
INPUT
rules, but I find it cleaner to block both directions (and they may catch stray UDP packets). Yes,-p tcp \! -d 10/8 -j ACCEPT
accepts outgoing TCP traffic going outside the LAN; include it or not depending on what policy you want to implement. – Gilles 'SO- stop being evil' Dec 30 '11 at 23:42