What you want is an iptables firewall. Check out this lovely
HowTo on setting one up.
It'll make more sense after you read the documentation, but what you basically want is a default reject policy with specific enteries for each service you do want to allow.