Is it the same with other games, or is it just Terraria that doesn't work?
Do you have a Gold subscription? If you have GamePass, it should be part of that.
In Settings, on the Network settings page there should be some information about your console's Internet connection. Does it say anything about NAT-type?