Never, ever, ever give ibuprofen. It's highly toxic to dogs and cats. I know of a Doberman who had severe kidney failure and had to be euthanized from just two Advil.
It's best to call your vet if you need to give something. They can dispense a medication, or give you the proper dosage of something OTC that's safe.
But honestly? If he's just stiff from a long hike, I'd just let him sleep it off.