The rating for Defense represents the combined strength of all the defensive items in a settlement. This rating needs to be as high as the population at the very least otherwise production is reduced and it leaves the settlement more vulnerable to attack. One of the easiest ways to boost Defense is by building Guard Posts which can be incorporated into walls and fences or any other structures. They require only wood and steel and one guard assigned to three posts produces 6 Defense. You should always build some Guard Posts even when you acquire better defensive items.
One artillery piece produces 6 Defense with a worker assigned. If you can spare the materials and space. building an artillery piece to boost Defense and improve coverage of artillery support is a very useful commodity.
While they require more materials, turrets are fully automated and once placed, will provide a significant boost to your Defense without needing a worker assigned to them. This method is perhaps the simplest way to increase Defense though many turrets require rare materials and special perks in order to build them. They are well worth the cost though.
Traps are another handy way of improving Defense. They just need to be connected with a wire to a power grid and remain undamaged to count. There are some drawbacks though, namely that once triggered, they do not discriminate between targets damaged by the trap. The easiest way around this is to make laser tripwires as the trap trigger and then connect a Terminal. Access the tripwire’s options via the Terminal and set the trigger to ignore friendly targets.
Guard Posts and artillery pieces do not take damage during invasions but turrets and of course any triggered traps will need repairing or replacing. If the Defense rating drops, use the Workshop to repair any damaged structures.