3

Sometimes you want to have a server-client relationship only on your server, ie. only localhost.

But it seems that once you open a port to listen, it is also available on the internet. So if you avoid a password to a server with root privileges, the server seems to be open to everyone on the internet.

How do you restrict a server to connections from localhost only or in other words, have an internal network, where you can only communicate within even though the machine has internet access?

1 Answer 1

5

you can configure your application to listen only on address 127.0.0.1 (localhost), that way it won't be seen as open from the outside.

For example if I have a nginx listening on port 80 fort every ip and an apache listening on port 8080 for 127.0.0.1 :

# netstat  -ltnp (Redacted a little to make it clearer)
Local Address           State       Program name
0.0.0.0:80              LISTEN      nginx: master
127.0.0.1:8080          LISTEN      apache

If you check from the outside these 2 port (With nmap for example), you will only see the 80 opened, and the 8080 closed :

# nmap $server -p 80,8080

PORT     STATE  SERVICE
80/tcp   open   http
8080/tcp closed http-proxy

If you try to connect to the 8080 :

# telnet $server 8080
Trying $ip...
telnet: Unable to connect to remote host: Connection refused

But the 80 will work :

# telnet $server 80
Trying $ip...
Connected to .
Escape character is '^]'.

Hope it helps !

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .