Production of the huge longitudinal magnetic fields by using an ultraintense laser pulse irradiating a solenoid target is considered. Through three-dimensional particle-in-cell simulations, it is shown that the longitudinal magnetic field up to ten kilotesla can be observed in the ultraintense laser-solenoid target interactions. The finding is associated with both fast and return electron currents in the solenoid target. The huge longitudinal magnetic field is of interest for a number of important applications, which include controlling the divergence of laser-driven energetic particles for medical treatment, fast-ignition in inertial fusion, etc., as an example, the well focused and confined directional electron beams are realized by using the solenoid target.