It came a day after a Nigerian asylum-seeker and drug dealer was arrested in the same town for the murder of an 18-year-old woman, whose dismembered body was discovered in suitcases.
"I was driving to the gym when I heard on the radio about the 18-year-old girl," daily newspaper Corriere della Sera quoted him as telling investigators.
"Instinctively I turned around, I went home, I opened the safe and took the pistol and decided to kill them all."
After the shootings, Traini, 28, allegedly got out of his car, made a fascist salute with a tricolour Italian flag draped over his shoulders and shouted "Viva Italia", or "Long Live Italy", and "Italy for Italians", media reports said.
Police who raided his mother's home found far-right literature, including a copy of Adolf Hitler's manifesto "Mein Kampf" and a book by fascist dictator Benito Mussolini.
Interior Minister Marco Minniti said the attack was part of a culture "of right-wing extremism with clear reference to fascism and Nazism" and deplored that the sole link between the victims was "the colour of their skin".
He said the "criminal act" was prompted by "racial hatred" and had been prepared in advance.
The man allegedly opened fire in eight areas in the town and also targeted the office of the centre-left Democratic Party in a two-hour terror spree in the sleepy town of 43,000 people, press reports said.
One victim was seriously injured in the thorax, the reports said. The other five had lesser injuries.
Two Nigerians among victims
Two Nigerians, Jennifer, 29, and Gideon, 25, were also among the victims of the gunman.
According to hospital officials in Macerata, Jennifer suffered a fracture in her arm, and might be operated on.
Gideon also expressed surprise at the attack, saying that he had always seen Macerata as a safe city. He also wondered why the gunman will attack an innocent person, who has lived a honest life like him.
Traini is a member of the far-right anti-immigration Northern League party and had run in local elections last year.
Media reports said police found a gun in the man's vehicle, a black Alfa Romeo.
"Someone who shoots is a delinquent, irrespective of the colour of his skin," said Northern league chief Matteo Salvini, ahead of legislative elections on March 4.
"I'm in a hurry to be in government to bring back security, social justice and serenity to Italy," he said.
'Hate will not divide us'
Italian Prime Minister Paolo Gentiloni meanwhile made a pitch for unity after Saturday's incident, saying: "Hate and violence will not divide us."
Italians head to the polls in national elections next month, with immigration shaping up to be a key issue.
The country is a favoured landing point on Europe's southern coastline for migrants making the perilous journey across the Mediterranean, often aboard unseaworthy boats, to enter the continent.
jpegMpeg4-1280x720But 2017 was a turning point for Italy: the country went from large-scale arrivals in the first six months to a sharp drop-off, thanks to controversial agreement between the EU and Libya.
Some 119,000 people landed in Italy last year, down 35 percent on 2016.
The Northern League is part of a populist coalition tipped to do well in the elections.
According to opinion polls, the alliance between ex-prime minister Silvio Berlusconi's centre-right Forza Italia (Go Italy), the post-fascist Fratelli d'Italia (Italian Brothers) and the Northern League leads with more than 35 percent ahead of the March 4 vote.