Internet in the trains
All long-distance trains are equipped with 3G/4G signal amplifiers. If you have a phone with internet access, you can use this improved signal. On other trains, you can use the unamplified signal.
You can use your smartphone to pick up the 3G/4G signal and configure the phone as a wifi hotspot. That allows wifi-enabled equipment such as a laptop or a tablet to access the internet. Buy an appropriate SIM card or wifi hotspot to save money.
Alternatively, there is SBB FreeSurf available on long-distance trains (IC and IR). You need the SBB FreeSurf app and an active Bluetooth connection. That will get you a free internet connection. SBB FreeSurf is new and still under construction. Whether it works depends on the train and the provider of your phone contract. It is an option worth trying if you don't have unlimited data.
Wifi in international trains
Most trains from Switzerland to Italy have on-board wifi that offers access to the internet and an entertainment program with news, films, games and more.
This wifi works similar to wifi at the station, but without a time limit.
Free wifi at the train stations
About 80 rail stations, including the ones in all larger towns, offer free wifi. This is how it works:
Connect your phone to the network "SBB-FREE";
Open your browser and go to onboard.sbb.ch;
Register. Your phone needs to be able to receive an SMS message;
Enjoy internet access for an hour. You can start using free wifi again after a 2-hour break.
Internet in other places
Nearly all hotels offer free or paid wifi. Mobile internet is available in nearly all inhabited areas. Don't expect internet to be available in remote areas. If internet connectivity is important to you, be sure to arrange for a Swiss SIM card or mobile hotspot.