views:

312

answers:

3

I'm trying to set up a socket server on a ubuntu machine. I've been setting up the same server-script on my own machine where it works perfectly. In my router i forwarded port 10007 to the right machine and bind the ip to my local ip (192.168...:10007).

Now i need to set it up on a dedicated server though and that is where the problems start. I don't seem to have a local ip on the server, atleast ifconfig won't show me one. I've tried to bind to the public ip instead or to 127.0.0.1 or 0.0.0.0, that works fine if i telnet from the same machine but not from another machine. Anyone knows how to solve this? Do i need to set up some sort of port forwarding?

+2  A: 

Do not bind to a specific IP address; use INADDR_ANY (IPv4) or an all-zeros address.

Ubuntu includes its own firewall as part of the system. If you cannot connect from another machine, check whether it is configured to block connections to your port.

Ubuntu Firewall documentation
Ubuntu ufw man page

Edit: There could also be a firewall between you and the server that is blocking the port. You might check with your hosting provider or your service agreement; they may need to specifically enable each additional port that is required. Some providers offer different hosting packages ranging from a basic web-only shared hosting package allowing only port 80, to a dedicated server allowing full access to the machine and all ports.

mark4o
Okay, now i've tried 0.0.0.0, enabled port 10007 with ufw, checked that i don't have any iptables restrictions and tried to connect from different machines. But it still doesn't work :/
Martin
Are you able to ping the server machine? Are you successfully connecting to other ports? Are you sure there is not some other firewall protecting the server?
mark4o
Yes pinging the 79.136.... ip works fine and i can ssh to it and the webserver on it (port 80) is working fine. How can i find out if there is a firewall blocking the port? That seems to be the only way this could happen but i don't know where to look, iptables -L gives no rules.
Martin
+2  A: 

NAT - Network Address Translation is what allows multiple machines to have local addresses behind a router that presents one public address to the internet. With your old server you were almost certainly behind a router than ran NAT, which is why you had to do port forwarding to reach your server.

If you aren't currently behind a NAT device then that is why you aren't seeing private addresses in the 192.168.x.x or 172.16.x.x or 10.0.x.x range. You are hooked directly to the internet and there is no distinction between private and public addresses. 79.136.x.x is your public address and you don't have a private one. Just bind to that and run your server.

Duck
+1  A: 

After you run your program, is the port listed in netstat (I use netstat -a)? This will tell you if the port is open and listening.

Coleman
Yes it's listed with netstat:tcp 0 0 0.0.0.0:10008 0.0.0.0:* LISTEN 13071/php
Martin
Would that not show up if a firewall was blocking it?
Martin
yes, I believe it will show up even if the firewall is blocking it. This shows you're program is "doing the right thing" and successfully opening the socket. You can also use lsof to get this same information.If you still can't connect at this point, then there is something else blocking your socket.
Coleman