Cephalexin is used to treat certain infections caused by bacteria such as pneumonia and other respiratory tract infections; and infections of the bone, skin, ears, , genital, and urinary tract. Cephalexin is in a class of medications called cephalosporin antibiotics. It works by killing bacteria.