Here's my trivial firewall script on the Z:
iptables -F INPUT
iptables -P INPUT DROP
iptables -I INPUT -m state --state established,related -j ACCEPT
basically, it uses connection tracking to only allow connections which were created by outbound traffic.