Catalysis of the formation of a phosphodiester bond between the 3'-hydroxyl group at the end of one DNA chain and the 5'-phosphate group at the end of another. This reaction requires an energy source such as ATP or NAD+.