All of what the previous post said is true, but I thought you might be interested in knowing about the actual mechanism by which this immunity is transferred to a baby.
Here is a link to an article that talks about the actual molecular mechanism that allows the antibodies that the mother develops to be transferred to the fetus.
Breast milk contains antibodies that help to boost the babies' immunity. Breastfeeding prevents ear infections, allergies, diarrhea, pneumonia, meningitis and urinary tract infections.
Colostrum, in particular, is rich in antibodies. It is recommended that up to 6 months, baby to be exclusively breastfed, without any additions of powdered milk, water or food.
Concluding, there are many good healthy habits which, when there are applied, they can help strengthen baby's immune system.