The invention provides a rail ultrasonic on-line detection system and its control method. The equipment includes a bracket, a roller table, a rail head tread landing gear, a rail bottom landing gear, a rail head right landing gear, a rail head left landing gear, and a rail waist Left landing gear, ultrasonic probe, No. 1 through-beam photoelectric, No. 2 through-beam photoelectric, No. 3 through-beam photoelectric, No. 4 through-beam photoelectric, rail position detection device, rail shape detection device, controller and ultrasonic detector; When the through-beam photoelectric senses the rail, the controller controls the corresponding landing gear to move up and down, thereby driving the ultrasonic probe installed on the landing gear to realize the flaw detection of each part of the rail. When a defect is detected inside the rail, the rail position detection The device outputs the specific position of the defect on the rail, and stops the flaw detection. It has the outstanding advantages of wide detection range, fast detection speed and high detection accuracy.