A magnitude four earthquake has rocked the coast of Western Australia, with tremors felt in several towns south of Perth.