Under optimal interaction conditions ions can be accelerated up to relativistic energies by a petawatt laser pulse in both underdense and overdense plasmas. Two-dimensional particle in cell simulations show that the laser pulse drills a channel through an underdense plasma slab due to relativistic self-focusing. Both ions and electrons are accelerated in the head region of the channel. However, ion acceleration is more effective at the end of the slab. Here electrons from the channel expand in vacuum and are followed by the ions dragged by the Coulomb force arising from charge separation. A similar mechanism of ion acceleration occurs when a superintense laser pulse interacts with a thin slab of overdense plasma and the pulse ponderomotive pressure moves all the electrons away from a finite-diameter spot.