Install the GeoNames module. A properly configured drush environment will help. From $WEBROOT/sites/all/modules :
drush pm install geonames
When adding GeoNames to Drupal 6.x sites, initialize $may_cache to 0 in the function prototype for geonames_tools_menu.
sed -i -e "s/menu(\$may_cache)/menu(\$may_cache=0)/g" geonames/geonames_tools.module
The GeoNames module options may now be enabled at admin/build/modules. After enabling, configure GeoNames at admin/settings/geonames for cache and other considerations.