Mechanics of peristaltic locomotion and role of anchoring