The 43-year-old Lopez played for the club for 12 seasons from 1998 to 2010, and previously coached the Sardinian outfit from 2013 to 2014, with a spell also in charge of the youth teams.
Lopez — who also briefly coached Palermo in Serie A last season and Bologna when they were in the second division — signed a contract until June 2019, the club said.
Cagliari are currently 14th in Serie A after four straight defeats, most recently losing 3-2 at home against Genoa.
Rastelli, 48, took over in the 2015-2016 season, guiding Cagliari into the Italian top flight after winning Serie B in 2016.
Last season the club finished 11th but this term are struggling with just two wins in eight games, against relegation rivals Crotone and SPAL.
Rastelli was the first Serie A coach sacked this season with coaching assistants Nicola Legrottaglie and Dario Rossi also dismissed in the clearout.
Download our app and read this and other great stories on the move. Available for Android and iOS.