John Hackney Hamlin, 71, an official of the Pentagon and the White House during the Eisenhower administrations, died of cancer April 8 in a hospital in Santa Barbara, Calif.

Mr. Hamlin came to Washington in 1954, as an adviser on small business for the assistant secretary of Defense for logistics and management and later became an executive assistant at the White House.

He retired to Bennington, Vt., in 1960, and spent the next eight years raising Morgan horses on his farm, writing and painting. He lived in Williamstown, Mass., from 1968 to 1975, before moving to Santa Barbara.

Mr. Hamlin was born in Sewickley, Pa. He was a 1929 graduate of Stanford University and attended Harvard University's law school. He was a Navy air combat intelligence officer in the Pacific during World War II and attained the rank of commander.

Survivors include his wife of 48 years, the former Gertrude Eleanor Smith of Santa Barbara; three daughters, Josephine H. Stead of Burlington, Vt., Cecily H. Wells of Westwood, Mass., and Gwendolen Hamlin of New York City, and five grandchildren.

The family suggests that expressions of sympathy be in the form of contributions to the Cancer Foundation of Santa Barbara, or to the American Cancer Society.