From "White, Tom; Hadoop: The Definite Guide; Ch. 3, The Hadoop Distributed Filesystem, Anatomy of a File Write":
...The DataStreamer streams the packets to the first datanode in the pipeline, which stores each packet and forwards it to the second datanode in the pipeline. Similarly, the second datanode stores the packet and forwards it to the third (and last) datanode in the...
It doesn't metion how does the datanode know which one is the next datanode where it has to send the packets.