An undocumented immigrant was sentenced to two years in federal prison after being found with a gun during a DWI traffic stop in Angier, federal prosecutors said Wednesday.