Since many birds nest in trees, you might think it would make sense to mount a nestbox on a tree trunk. However, some nestings in natural cavities may fail because the tree offers ready access to climbing predators like raccoons, mice, red squirrels, cats, and snakes. Cavities excavated by birds like woodpeckers often have a long tunnel like entrance that protects them from predators that reach in to nab eggs or nestlings. However, cavities in decayed snags are susceptible to predation because they can break off, blow down, or can be ripped open by raccoons.
Most nestboxes on tree trunks offer ready access to predators. Even though it may take several years for a raccoon to recognize a nestbox as a "Happy Meal," once they do, they will be back time after time. (Woodpeckers typically excavate a new cavity for each nesting, which prevents such learning.) In areas like the south where rat snakes are common, a nestbox on a tree can be a death sentence. The same problem exists with nestboxes mounted on fence posts, large wooden posts, or telephone poles.
Note that snakes and climbing predators (raccoons, squirrels) are common, but are NOT a problem in all areas (e.g., in San Diego, parts of Colorado)
It is safer to mount nestboxes on metal poles (like EMT conduit), that are either greased regularly, or (much better) have a wobbling baffle on them.
Boxes can also be hung from trees out of reach from cats, bears or vandals, and too far out on a limb for a raccoon to gain access. (This does not provide protection from snakes). The boxes can be lowered for regular monitoring.
Noel Guards will provide some protection against raccoons, but not against snakes.
Nestbox design: Eliminate perches. Measure entrance hole (1 1/2 - 1 9/16" round or 1.375" x 2.250" oval hole), put hole restrictor on if the hole has been enlarged. Add a wooden face guard/block (1 1/2 to 2 1/4" thick) over hole, lower nest to 4.5"+ below entrance hole. Use a deeper nestbox (8.5" from bottom of hole to floor) with kerfs on interior to enable fledging. Have an ample roof overhanging entrance hole. Remove used nests so birds don't build on top, making the nest too high and more accessible to a reaching predator.
A "Bird Guardian" would help protect nestbox contents from reaching predators (not snakes). It is a plastic tunnel that connects to or screws onto the entrance on the outside of the nestbox. However, Dorene Scriven felt it makes feeding difficult and was not well accepted by bluebirds.
As a last resort, a sheet metal guard at least 30" wide can be placed around the trunk/fence post underneath the nestbox. If it is on a tree, it must be put up in such a way as to not interfere with the trees' growth. If the metal cuts into the bark and girdles the tree, the tree will die. Heavily and regularly grease poles, and mix grease with red cayenne pepper.
Tufted Titmice and Nuthatches seem to prefer boxes mounted on trees or under tree cover. They do not like to cross open spaces, but a pole mounted box under a heavy tree canopy would be attractive. They WILL nest in boxes on baffled poles. They will nest in hanging boxes, which are safer than a tree trunk mount.