town is an area of town (generally on the outskirts of a city) where people who can't afford housing live. A shanty is a house you build yourself, usually out of cheap plywood
, or whatever you can find that's handy. After the civil war
shanty towns populated by freed (but now homeless) slaves (who often were forbidden to live within city limits) sprung up all over the South
During the Great Depression in the US, when shanty towns filled with as many whites as blacks, they were called Hooverville (in tribute to President Herbert Hoover, who was widely blamed for the depression).
In Central and South America (and probably many other places) modern shanty towns are often big enough to be their own cities. Many have (stolen) electricity, bus service, and sometimes even running water (for a few hours / day, usually). But they are still impermanent settlements (having no foundations, many of the homes wash away every couple of years during the rainy season).