please go through the deployment guide , it will show you exactly which ports needs to open between UCMDB and DFM also we have a lot of ports between DFM and the discovered CI's you have to make sure that you already opened what you need. this will be find into UCMDB it self in portname.xml file.
For discovery, well it depends on the discoveries you want to do, so I would suggest to start by knowing this. Then once you know and you know which protocol you need to access to the information, well it's like any remote access using this protocol. If you want to access to a Linux machine via SSH, you will need port 22 opened. And so on.