The Hammers started brightly, with Matthew Etherington testing Kelvin Davis in the home goal after just three minutes, before Pablo Counago went close for the Tractor Boys.
After 18 minutes David Connolly had the ball in the net for the visitors, but an offside flag ruled out the strike.
Within three minutes West Ham were ahead as Jermain Defoe ran at the retreating defence before powering his left-foot shot beyond Davis and into the back of the net.
The England striker had a couple of chances to extend the lead before the break, but Town escaped to go into the interval just one goal behind.
However, within seconds of the restart it was 2-0 as on-loan Neil Mellor forced a save from Davis and Republic of Ireland striker Connolly was on hand to net from the rebound.
Just after the hour mark, Town grabbed a lifeline as Jermaine Wright rifled his shot past David James, but the Hammers held out to secure the three points.
That gave them a maximum six points from two games played under caretaker manager Trevor Brooking.