It seems that "Gewehr" can mean gun, but also specifically rifles. Can "Gewehr" be used more generally to mean all guns, or does it only mean rifles specifically?
Gewehr today typically denotes any gun that has a long barrel (as opposed to a pistol). Rifles, machine guns, even shotguns.
And no, it is not the generic term for gun, that would be Schusswaffe.
The word Gewehr itself was actually part of the language before guns were even invented - It used to mean anything that could be used as a means of long-range defense before you got into a melee fight, so it included battlements, walls, towers, barricades, whatever (The Grimm has an extensive explanation on that). Over time, the meaning focused on guns but still anything that would not apply to melee battle.
Waffe = weapon
This can be a gun, a bomb, a missile, and many other things that are made to hurt or kill people. Depending on the context, a Waffe also can be anything that can be used to hurt or kill people, independent of what it was made for - so a screwdriver, a baseball bat, or a box cutter can also be Waffen.
Gewehr = rifle, long gun
A Gewehr is any gun with a long barrel, i.e. something that shoots bullets, but not a pistol.
Schusswaffe = gun
Schusswaffe (literally: shoot-weapon) is the German word for any weapons that can be used to shoot bullets.