You can't unlock it. You can jailbreak it though. Depending on if it is an iPhone 3G or 3GS, you will have a tethered jb if it is a new boot 3GS. If it is an iPhone 3G, you might be able to downgrade the baseband if it has bootloader 5.8 so that you may unlock.
If you really desperately need to unlock and are willing to take any risks, you can upgrade the baseband to 6.15.00 to unlock. You'll need to use Redsn0w 0.9.6rc8 and the 4.2.1 stock ipsw to jailbreak.