Application of highly articulated hyper-redundant robots to manoeuvre in narrow and confined spaces is gaining popularity due to their obvious advantages. In this paper, we describe an optimization based approach for motion planning of hyper-redundant robots, which results in a natural motion of the links through ducts and confined spaces. It is shown that for a desired motion of the end-effector or the head of the hyper-redundant robot, the motion of the subsequent links attenuate and all the links avoid collision with the walls of the ducts and any other obstacles in the confined spaces. We discuss several ways to represent ducts in 2D and 3D space and also how the proposed algorithm is applied in these representations. It is shown that the complexity of the algorithm, with m constraints is at most O(m3.5) and in case where the ducts can be modeled with polyhedra, the complexity can be as low as O(m1.5). The proposed approach is also used to determine the largest link length in the hyper-redundant robot which can traverse the confined path. The concepts developed in this paper are demonstrated using simulations conducted on three practical scenarios: 1) hyper-redundant manipulators inspecting an industrial pipeline, 2) motion of an endoscopic robot through gastro-intestinal (GI) tract and 3) motion of hyper-redundant manipulators in search and rescue operations. Analysis on the computational complexity and the simulations shows that the method is feasible for practical implementation.