Afghanistan, like Iraq, is a place where the enemy will attack your bases. The smaller and more vulnerable your base, the more likely it will be attacked. In this respect, Afghanistan is very much like Iraq, with one exception. The Afghans are much more likely to muster a large force of gunmen and try to take your base by direct assault. Like Iraq, the enemy will use mosques to stockpile weapons and ammunition, and terrorize the civilians, if need be, into keeping quiet about it. But this also means that the local civilians will slip away before attack. Bases inside villages and towns thus get a warning from that, if intelligence has not already detected the plan. The Taliban have figured out that the cell phone networks, and any other kind of wireless communications, is being listened to by the Americans. But there are other things the Americans keep an eye in. Thus it's been difficult for the Taliban to pull off too many of these attacks, and none have succeeded. But it's not for want of trying, and foreign troops have to be alert to attempts. The Taliban also learn, even when they call off an attack because they sense that the foreign troops are too alert, or seem to have detected the preparations. Ideally, U.S. troops want to be aware of an attack, and quietly prepare an ambush that will wipe out the Taliban force. That has happened a few times. It's an ongoing battle of wits.
The Taliban also attack bases with rockets (usually the meter long, 15 kilogram/33 pound 107mm models) or mortars. These rarely hit the target, or cause many casualties. But they do annoy the enemy, and encourage them to come out at night to try and catch the teams setting up the rockets or mortars (which have to be within about five kilometers of the base). Troops have found that it's better to try and ambush these teams, rather than just firing back with mortars, gunfire or artillery. The Taliban will endeavor to fire their rockets or mortars from populated areas, in the hope that counterfire will kill civilians and destroy their homes. This makes the locals mad at the foreign troops and easier for the Taliban to control.
If the foreign troops are really on the ball, they will make the surrounding area too dangerous for the Taliban, and there won't be any rocket or mortar attacks. The foreign troops have night vision equipment, and UAVs overhead that can also see in the dark. This puts the Taliban rocket/mortar teams at a disadvantage, and the Taliban will back away from unequal situations like that.
The Taliban will also lay "distant siege" to a remote base, by vigorously attacking supply convoys. The U.S. can respond by delivering supply via helicopter or air drops. But the Taliban know that this makes supply a base more costly, and a marginal base may just be shut down, which the enemy will count as a victory. With so many bases spread over a wide area, the "distant siege" often turns into another game of wits, as the foreign troops have to figure out how and when the Taliban will attack the convoys, and hit the attackers first. If you hit the Taliban hard enough, they go away.