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.
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.