I would like to direct all the traffic through my VPN connection on my Android based phone (HTC Desire). The VPN works great, but problem is that when the VPN disconnects, the traffic is redirected through my regular internet, something I don't want to happen. How can I block the traffic outside the VPN?

  • using Tasker(app), I can put the phone into flight mode when an event occurs, in this case a message notification at the top bar. This does occur when the VPN disconnects, however the program can't distinguish that from any other message. What I need is a standalone app that would pop a message when the VPN disconnects. Do you know any? Oct 11, 2011 at 18:17
  • Flight mode also disables the cell radio, are you sure that you wish to disable calling features too when disconnected from the VPN? Oct 11, 2011 at 20:29

2 Answers 2


You could use DroidWall for this IF you're rooted. Just deny all traffic and then allow traffic to your VPN IP/port. If you need to use a custom script see the man page of iptables for the syntax. Here's a quick, untested example.

iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -A OUTPUT -p udp --dport 1194 -d xxx.xxx.xxx.xxx -j ACCEPT

Previous answer is a bit outdated (but should still work), because DroidWall isn't developed anymore, while there's a fork named AFWall+. App has free and "donate" versions and lets you to allow apps access internet only through VPN using GUI. You'll probably have to obtain paid version for this functionality, but I'm not sure about that because description in F-Droid says you need to buy it, while in Play Store there's nothing about that. Root is needed of course.

On screenshot WireGuard is VPN app and is allowed on all networks, other apps are allowed only on VPN (fourth column), some are not allowed to access internet at all:

enter image description here

Also since Android 8 there's built-in option Block connections without VPN in VPN settings.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .