The two will battle for a single berth from Group G for the finals in Gabon, who were designated as hosts earlier on Wednesday after a vote by the executive committee of the Confederation of African Football.
Egypt, whose seven titles include winning three in a row from 2006 to 2010, have not qualified for the last three tournaments.
Africa Cup of Nations
Gabon to host 2017 African Nations Cup
08/04/2015 AT 13:50
Egypt and three-times champions Nigeria meet each other in back-to-back games in March.
There will also be a tough battle in Group M where Cameroon and South Africa were paired together.
Holders Ivory Coast will play in Group I against Sierra Leone, Sudan and Gabon, who have already secured a place in the finals as hosts but still compete in the qualifiers.
Ghana, who lost to the Ivorians in a dramatic penalty shootout in the 2015 final in Bata in February, were placed in Group H with modest opposition in the form of Mauritius, Mozambique and Rwanda.
A record total of 52 countries entered the preliminaries. Only Eritrea and Somalia are absent.
Zimbabwe, banned from competing in the 2018 World Cup preliminaries, are entered for the Nations Cup and compete in Group L with Guinea, Malawi and Swaziland.
Africa Cup of Nations
CAF poised to choose 2017 African Nations Cup host
07/04/2015 AT 10:38
Africa Cup of Nations
CAS overturns Morocco's 2017 Nations Cup suspension
02/04/2015 AT 14:52