First you havr to Jailbreak your iPhone 3.1, here is the Tutorial, After that to unlock iPhone 3.1, you must create a custom firmware that uses the current baseband. The iPhone 3.1 update updates the baseband to a newer one that permanently blocks the software unlock.
Read Also: How to Unlock Jailbreak iPhone 3GS 3.1 with PwnageTool 3.1.3
Read the Tutorial here to Jailbreak & Unlock iPhone 3.1 with PwnageTool 3.1














