the node will know by looking at the blockchain. If it's just a new node, it'll need to download some of the blockchains from another node before it can start connecting to others. For another, nodes can find and connect using a variety of methods such as multicast discovery protocols like mDNS or LLMNR. Nodes could also use services like Tor or I2P for anonymity and privacy protection. And lastly, nodes could also use a unique identifier that's generated for the node through its genesis block.