You can connect to Internet using Wi-Fi feature available built with in the iPhone / iPod Touch. You can find the Wi-Fi setup and information here.
However the internet connectivity depends on two factors :
1> You have to be in an area that has Wi-Fi and you should be with in the Wi-Fi range. Good Wi-Fi range is around 100 feet, that’s around 30 – 40 meters.
2> Now even if you are with in range, sometimes you may not be able to able connect to the internet. If you are unable to connect even then, you have to check if you have access to the available network. If it is a public network then you can connect without any need to validating, but if the network available is a secured Wi-Fi network, then you’ll be prompted for a security key. Only those with security key will be able to connect to the Internet.
If you have problems connecting to internet even if there is Wi-Fi, then you should first check if it is a secured network or not. This may be the problem most of the times.