Giz Asks reached out to experts in canine medicine and behavior to find out. There was not general agreement on the answer, but it appears that a majority of the five DVMs interviewed believe dogs can get headaches.
Source: GIZMODO, February 25, 2019. Link.
Dogs with brain tumors tend to push their head against walls and furniture as though their head hurts, and anti- inflammatory drugs improve this head pressing.” Elizabeth Stelow, Staff Clinician and Veterinary Behaviorist, UC Davis Clinical Behavior Service
Also see: Do dogs know they are good boys? GIZMODO, July 3, 2017. Link.