When a charged particle travels across the vacuum chamber of an accelerator, it induces electromagnetic fields, which are left mainly behind the generating particle. These electromagnetic fields act back on the beam and influence its motion. Such an interaction of the beam with its surro undings results in beam energy losses, alters the shape of the bunches, and shifts the betatron and synchrotron frequencies. At high beam current the fields can even lead to instabilities, thus limiting the performance of the accelerator in terms of beam quality and current intensity. We discuss in this lecture the general features of the electromagnetic fields, introducing the concepts of wakefields and giving a few simple examples in cylindrical geometry. We then show the effect of the wakefields on the dynamics of a beam in a linac, dealing in particular with the beam breakup instability and how to cure it.