Step-by-step Tutorial: How to Jailbreak and Unlock Your iPhone 3GS Using PwnageTool 4.1.3 (Mac OS) [iOS 4.1]
For iPhone 3G use this tutorial.
There is no unthethered jailbreak for new iPhone 3GS bootroms and iOS 4.2.1 yet, so you should stay at iOS 4.1.
Important: iPhone3GS users with old bootroms who want to go to 4.2.1 and unlock should not use this PwnageTool! Update to stock 4.2.1 first, then use new redsn0w to update your baseband.
Make a folder called “Pwnage” on the desktop. Download a couple of things: