If you are traveling you may want your iPhone ot work over a network other than your home network. Fortunately, this is very easy to do with the iPhone 3G or 3GS. Your destination will likely have GSM in a different frequency than in your home country, since GSM frequencies are different all over the world. Your iPhone should switch between the frequencies automatically and allow you to select a different network.
Turn your iPhone on and allow it to boot up.
Enter the Settings menu. It has an icon that looks like gears.
Select carrier and choose the carrier or network you would like to use. If your iPhone does not have this option, enter the "General" menu. Again, it has a setting that looks like gears.
Select the option labeled "Network." It is a few down from the top, but has no icon. Select the network you wish to use, and your iPhone will start to communicate over that network.
While you are in the menu turn off Data Roaming to prevent racking up charges as your iPhone does simple things like checking for email.
If you're traveling abroad its best to turn off all the data options on your phone, as well as data roaming and cellular data. This will prevent you racking up substantial data charges. Select a different network if you're having trouble with service on one. This will not work if your home service provider is available. Jailbreaking your phone is an option if you want to use a different network in your home area, but this will void the warranty on your iPhone.