Sorry, thought you meant, could you enemies fire through the walls. Yes, they can. Your turrets cannot. The only time that works is if you use one of the walls that has a lot of holes in it and you have to be careful because it doesn't always work. I do find that, simply having a roof over the turret does seem to minimize their being targeted though.
A couple of tricks I found were:
1) Make sure your turrets are above the 2nd level. Apparently enemy range is large enough to fire above the 2nd floor (mine on the 3rd have yet to be destroyed)
2) Face some of your guns in to your compound. You'll get enemies inside regularly and, apparently your enemies won't shoot their backsides.
3) The turrets I have that are both elevated and shoot "over" walls tend not to be destroyed as easily. Those in the open, even when elevated seem to be the most vulnerable. I have a group of them set right at the top of the walled gate going in to my compound in Hangman's, just barely visible and they have yet to be destroyed, yet they can still fire at enemies.
4) Laser turrets seem to be the most vulnerable as well as missile turrets. Enemies mostly ignore my machine gun and heavy machine gun turrets if I have them as well.
5) I always place a guard post near my outer turret defenses and my settlers do a great job not only defending the compound with turret backup but seem to protect the turret as well.
Note that these are just my experiences over the last three runthroughs. It's been pretty much trial and error to discover this stuff though.
On a completely separate note though. Apparently putting a roof over just about anything will help to protect it from destruction. I roof over my water pumps and my generators and haven't had more than a tiny loss since I did it during any attack. Now all that gets destroyed are my crops and their easy to replace.