What you want is called "tethering".
Here you can find apple's official stance on it:
From that same page (when you click on 'How to use internet tethering'):
Using iPhone as a Modem
You can use iPhone 3G or later as a
modem to connect, or tether, your
computer to the Internet. You can
connect iPhone to your computer using
the Dock Connector to USB Cable, or
NOTE: Additional fees may apply.
Contact your carrier for more
Tethering works over the cellular data
network. You can’t share a Wi-Fi
connection to the Internet. If you
have a 3G connection, you can make and
receive phone calls while tethering.
NOTE: To use iPhone as a modem with a
Mac computer, it must be running Mac
OS X version 10.5.7 or later.
Set up a
In Settings, choose General > Network > Internet Tethering.
Slide the Internet Tethering switch to On.
Connect iPhone to your computer:
USB: Connect your computer to iPhone, using the Dock
Connector to USB Cable. In your
computer’s Network services settings,
On a Mac, a pop-up window appears the first time you connect,
saying “A new network interface has
been detected.” Click Network
Preferences, configure the network
settings for iPhone, then click Apply.
On a PC, use the Network Control Panel
to configure the iPhone connection.
Bluetooth: On iPhone, choose Settings > General > Bluetooth
and turn on Bluetooth. Then refer to
the documentation that came with your
computer system software to pair and
connect iPhone with your computer.
When you’re connected, a blue band
appears at the top of the screen.
Tethering remains on when you connect
with USB, even when you aren’t
actively using the Internet
Monitor your cellular data
In Settings, choose General > Usage.
There's quite some other ways explained on the internet how to do it once you know which term to search for ;-)