It is recommended to put the solenoid/flyback diode right on the relay socket by connecting *cathode lead (marked) point to 24V and the anode lead to Yxxx of the UB1 board.
The 1N4007 works fine in most situations.
*If you put the diode in the wrong direction, that will damage the UB1 output.