The has given Queens a home second round tie against fellow Championship side Livingston.
Meanwhile, Annan Athletic will take on Championship side St Mirren in the second round at Galabank.
St Mirren, relegated from the Premier League last season, are one of the favourites for the Championship play-off places this season.
The draw was made at Hampden Park on Monday afternoon.
The draw is as follows:
Forfar Athletic v Dunfermline Athletic
Falkirk v Peterhead
Alloa Athletic v Elgin City
Stenhousemuir v Raith Rovers
Annan Athletic v St Mirren
Ayr United v Rangers
Queen of the South v Livingston
Queen’s Park v Dumbarton
Ties are due to be played on August 18/19