How to block Outgoing Port 25 for all VPS/Containers of SolusVM(Both OpenVZ/KVM)

Sometimes,when providing VPS service, it is necessary to block mailing service for VPS. Otherwise your IP ranges will be blocked by RBLs and other common mail providers like Gmail, Hotmail, AOL, etc. It is recommended to open ports by case by case for your customers, after establishing trust with your client.

Normally we block the port using the “OUTPUT” chain. However, SolusVM uses the chain “FORWARD” for routing traffic from containers/VPSs.

So by adding following rules, you can block all outgoing mails ports completely for all VPSs.

iptables -I FORWARD -d -p tcp -m tcp --dport 25 -j DROP
iptables -I FORWARD -d -p tcp -m tcp --dport 465 -j DROP
iptables -I FORWARD -d -p tcp -m tcp --dport 587 -j DROP

Then save the iptables by running

service iptables save