I can connect to other people's servers in Team Fortress 2 fine. I only have problems when I try to connect with a friend's dedicated server over the internet. Usually a message comes up and says that it "quit after 4 tries" or "server not responding". I know the server is responding, though, because the person running it and anyone on the same LAN connection can run it fine. I have tried using several other computers, maps, and ways to connect to the server, but nothing seems to work. What is the problem and how can I fix it?
If it's only people on the same LAN that can connect, then the problem is almost definitely to do with the server's firewall or, more likely, the router that your friend is using.
In the first case, it may be that the firewall is configured to accept connections from computers on the same subnet (i.e. on the LAN), but block connections coming from computers outside the subnet. Set the firewall permissions on the server, and you're set.
In the second case, it's likely that the ports used by the server aren't being forwarded by the router. The router doesn't know what to do with incoming connections that weren't initiated by one of the computers on the LAN, and the TF2 server might not be smart enough to tell the router that it's listening on port 270xx. Forward the required ports using the router (web) configuration tool, and you should be good to go.
Here is some more information about setting up a server, and the needed ports.
EDIT: @Matthew Read posted a nice answer on a similar question listing the ports in use by Valve games.
One thing to check will be which IP you are using -
If you are using the same IP address as other folk on their LAN, it will most likely be a local address (192.168.x.x, or similar). This will not work over the internet, and you will need their external IP address.
They will then need to deal with forwarding ports to the server, as in MBraedley's answer.