Goblins can defend all of their Tunnels simply with two sets of Goblin Warriors. So, how does one accomplish this you might ask? Well it's all to do with the Goblin's resource buildings, which double as a system of Tunnels.
First of all, the importance of this tip. The fact that Goblins can defend their Tunnels at a moment's notice makes harassing difficult and allows the Goblin player to expand and get an economic advantage over his opponent.
So, to start off you want to build two Goblin Warrior units from your Caves and put them in your Tunnels close to your base.
Now that you have these Goblins in your Tunnels, you're ready to defend from harassment. Below are a few examples of Goblins defending from harassing units.
Video's of Tunnel Camping
This also works against Soldiers and Pike units.
This will not work against units with splash damage, such as Rohirrim. Splash damage basically means that any damage done to one unit will spread to units close to those, and in this case, will kill both battalions in a short period of time.
Also, remember to use Poison when the Goblins come out. This makes it much more effective. If you have Bats, use them as well to weaken the enemy units, hopefully saving your building.