LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-25-2010, 04:30 AM   #1
MarkoSan
Member
 
Registered: Jun 2006
Location: Ljubljana
Distribution: KUbuntu
Posts: 57

Rep: Reputation: 1
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
 
Old 07-25-2010, 04:36 AM   #2
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
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"
 
1 members found this post helpful.
Old 07-25-2010, 04:37 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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.
 
Old 07-25-2010, 05:07 AM   #4
MarkoSan
Member
 
Registered: Jun 2006
Location: Ljubljana
Distribution: KUbuntu
Posts: 57

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by zirias View Post
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
 
Old 07-25-2010, 05:12 AM   #5
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Marko, your mysql daemon is just not listening on eth0. You have to adjust its configuration if you want that.
 
Old 07-25-2010, 05:34 AM   #6
MarkoSan
Member
 
Registered: Jun 2006
Location: Ljubljana
Distribution: KUbuntu
Posts: 57

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by zirias View Post
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?
 
Old 07-25-2010, 05:50 AM   #7
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
As I already said, edit your "my.cnf" file, that's the main configuration for the mysql daemon.
 
1 members found this post helpful.
Old 07-25-2010, 04:00 PM   #8
MarkoSan
Member
 
Registered: Jun 2006
Location: Ljubljana
Distribution: KUbuntu
Posts: 57

Original Poster
Rep: Reputation: 1
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??
 
Old 07-25-2010, 08:16 PM   #9
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,827

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
the difference ?

one is a number the other is text

other than that -- the same for all practical reasons
 
0 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie question: whats the difference between "su root", "su" and "su -&quo mojarron Slackware 9 12-07-2009 05:08 PM
Trying webmin, getting "attempt to connect to 127.0.0.1:10000 (localhost) failed" jeffreybluml Linux - General 1 08-16-2007 12:16 PM
KDE/CUPS printer slow to start up; fixed with "127.0.0.1 localhost" in /etc/hosts KWTm LinuxQuestions.org Member Success Stories 0 03-05-2005 12:11 PM
Can you explain the difference between "Free Software (GNU)" and "Open Source"? vharishankar General 5 03-03-2005 10:40 AM
difference between "Web server local URL" and "IPv4 address"? kpachopoulos Linux - General 2 09-17-2004 02:30 PM


All times are GMT -5. The time now is 05:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration