Connecting Macbook to WiFi network breaks internet for everyone
If I were you, I would backup all your important files, reformat the disk and reinstall the macOS unless you would have a better clue of what the problem is. It might be something as simple as a corrupted preferences file or as difficult as a faulty hardware component. If you try this approach and you find out that everything is working as it should then at least you can exclude any hardware problem.