LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   difference between "localhost" and "127.0.0.1"?? (https://www.linuxquestions.org/questions/linux-newbie-8/difference-between-localhost-and-127-0-0-1-a-822010/)

MarkoSan 07-25-2010 03:30 AM

difference between "localhost" and "127.0.0.1"??
 
Hi to all!

I have a web server with mysql which to I access via ssh from remote computer. There is also a router with firewall ON and open ports that I need between remote comp and this web server. Now, I am trying to access to mysql database via MySQL Workbench and I cannot connect to it. Therefore, I've logged into my server via ssh from my remote comp and checked open ports with nmap. Now after nmapping server's ip I see there is not opened 3306 port:
Code:

X@staufenberg:~$ nmap -v 192.168.123.103

Starting Nmap 5.00 ( http://nmap.org ) at 2010-07-25 10:24 CEST
NSE: Loaded 0 scripts for scanning.
Initiating Ping Scan at 10:24
Scanning 192.168.123.103 [2 ports]
Completed Ping Scan at 10:24, 0.00s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 10:24
Completed Parallel DNS resolution of 1 host. at 10:24, 6.50s elapsed
Initiating Connect Scan at 10:24
Scanning 192.168.123.103 [1000 ports]
Discovered open port 80/tcp on 192.168.123.103
Discovered open port 21/tcp on 192.168.123.103
Discovered open port 22/tcp on 192.168.123.103
Discovered open port 548/tcp on 192.168.123.103
Completed Connect Scan at 10:24, 0.02s elapsed (1000 total ports)
Host 192.168.123.103 is up (0.00017s latency).
Interesting ports on 192.168.123.103:
Not shown: 996 closed ports
PORT    STATE SERVICE
21/tcp  open  ftp
22/tcp  open  ssh
80/tcp  open  http
548/tcp open  afp

Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 6.58 seconds
x@staufenberg:~$

If I nmap localhost (also this web server), I get:
Code:

x@staufenberg:~$ nmap -v localhost

Starting Nmap 5.00 ( http://nmap.org ) at 2010-07-25 10:27 CEST
NSE: Loaded 0 scripts for scanning.
Warning: Hostname localhost resolves to 2 IPs. Using 127.0.0.1.
Initiating Ping Scan at 10:27
Scanning 127.0.0.1 [2 ports]
Completed Ping Scan at 10:27, 0.00s elapsed (1 total hosts)
Initiating Connect Scan at 10:27
Scanning localhost (127.0.0.1) [1000 ports]
Discovered open port 22/tcp on 127.0.0.1
Discovered open port 80/tcp on 127.0.0.1
Discovered open port 3306/tcp on 127.0.0.1
Discovered open port 21/tcp on 127.0.0.1
Discovered open port 548/tcp on 127.0.0.1
Completed Connect Scan at 10:27, 0.01s elapsed (1000 total ports)
Host localhost (127.0.0.1) is up (0.00016s latency).
Interesting ports on localhost (127.0.0.1):
Not shown: 995 closed ports
PORT    STATE SERVICE
21/tcp  open  ftp
22/tcp  open  ssh
80/tcp  open  http
548/tcp  open  afp
3306/tcp open  mysql

Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 0.07 seconds
x@staufenberg:~$

Why "127.0.0.1" and "localhost" are not the same???

Sincerely,
Marko

zirias 07-25-2010 03:36 AM

Uhm, looking at your logs, localhost and 127.0.0.1 ARE the same on your machine. By convention, localhost always maps to the local loopback interface, configured for IPv4 address 127.0.0.1 (and possibly IPv6 address ::1).

But, it's NOT that same as the REAL ethernet interface of your box, as you can see in the first log. The 192.168.x.x IP address is given to your real network card, while "local loopback" is always a virtual network card and not connected to the outside world. MySQL by default only binds to the loopback interface, for security reasons. You can probably change this behavior in your "my.cnf" (I don't remember the syntax).

If you want to get an overview of all your network interfaces, try typing "ifconfig" :)

druuna 07-25-2010 03:37 AM

Hi,

Have a look at your /etc/hosts file.

127.0.0.1 / localhost.localdomain / localhost are the same and mapped to each other. There should also be one or more lines that name your other IP's (something like: 192.168.123.103 myip1.domain.com myip1).

If you use a name (like localhost or myip1 in the previous example), this is translated first to the connected ip address. localhost will become 127.0.0.1 and myip1 will become 192.168.123.103.

Hope this helps.

MarkoSan 07-25-2010 04:07 AM

Quote:

Originally Posted by zirias (Post 4044569)
Uhm, looking at your logs, localhost and 127.0.0.1 ARE the same on your machine. By convention, localhost always maps to the local loopback interface, configured for IPv4 address 127.0.0.1 (and possibly IPv6 address ::1).

But, it's NOT that same as the REAL ethernet interface of your box, as you can see in the first log. The 192.168.x.x IP address is given to your real network card, while "local loopback" is always a virtual network card and not connected to the outside world. MySQL by default only binds to the loopback interface, for security reasons. You can probably change this behavior in your "my.cnf" (I don't remember the syntax).

If you want to get an overview of all your network interfaces, try typing "ifconfig" :)

I did that, here are results:
Code:

x@staufenberg:~$ ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:19:66:ef:25:59 
          inet addr:192.168.123.103  Bcast:192.168.123.255  Mask:255.255.255.0
          inet6 addr: fe80::219:66ff:feef:2559/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3867370 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2389011 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:892942200 (892.9 MB)  TX bytes:216539452 (216.5 MB)
          Interrupt:31 Base address:0xe000

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:15785 errors:0 dropped:0 overruns:0 frame:0
          TX packets:15785 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:879384 (879.3 KB)  TX bytes:879384 (879.3 KB)

x@staufenberg:~$

So, that means, that on router probably there is not 3306 opened port. How do I get router's ip on this local network (i.e., how do I get a list of computers in local network from server's command line)? And router has GUI based (web based) configuration option, how do I open port from linux's cmd?

Sincerely,
Marko

zirias 07-25-2010 04:12 AM

Marko, your mysql daemon is just not listening on eth0. You have to adjust its configuration if you want that.

MarkoSan 07-25-2010 04:34 AM

Quote:

Originally Posted by zirias (Post 4044590)
Marko, your mysql daemon is just not listening on eth0. You have to adjust its configuration if you want that.

How do I do that?

zirias 07-25-2010 04:50 AM

As I already said, edit your "my.cnf" file, that's the main configuration for the mysql daemon.

MarkoSan 07-25-2010 03:00 PM

now, I fixed that, but now I have following problem: I can connect to mysql server via terminal window using my account, but with MySQL Workbench I cannot connect using same account, I get:
Quote:

Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (4)
Why??

John VV 07-25-2010 07:16 PM

the difference ?

one is a number the other is text

other than that -- the same for all practical reasons


All times are GMT -5. The time now is 02:23 AM.