ports

Can anybody guide me on how to block all ports and allow only 1 or 2? The purpose is to prevent any possible leak like when I am using VPN.