File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes naive server ip connection question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "naive server ip connection question" Watch "naive server ip connection question" New topic
Author

naive server ip connection question

jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Hi Guys :

Background : I have a macbook and a linux laptop at home, and the linux server has a MySQL server on port 3306.

Goal : I wanted to connect to the linux mysql server from my mac laptop... but they both use the same router and thus have the same external ip address.

Question : How do I obtain the internal IP addresses for each individual computer so that they can talk to one another within my home network ? Also, any hints on how to connect to the server from OUTSIDE the router would be insightfull, although I have no need to do this at the current juncture.

Thanks!!!

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Both Mac OS and Linux have nice graphical tools to change and display the IP address of the machine itself. This is always the internal IP address; it's the router that translates (through something called NAT, network address translation) internal IP addresses to the single external IP address and vice versa.

Anyway, if you can't find that nice graphical tool (which one to use depends on the operating system) you can use the global Linux command line way:
- open a terminal.
- type "/sbin/ifconfig".
- look at the results.

There may be multiple results; usually there is an interface called "lo" which is the loopback address, and you can ignore this. "eth0", "eth1", etc are the wired network interfaces. If I recall correctly the wireless network interfaces are called "w0", "w1", etc. You usually only have at most one wired network interface and at most one wireless network interface, so "eth0" and "w0" are the ones to look for.


As for connecting from the outside world (WAN), first ask yourself if you really want to do this. You're opening up your machine for the world, so you'd better make sure it's properly secured. Keep all your software up-to-date, and don't open any ports that aren't necessary.

There are two layers of security: the firewall on the machine itself, and the firewall / NAT on the router. Linux mostly uses iptables for its firewall, with a multitude of front-ends. Ubuntu uses "ufw" as the command line front-end and "gufw" for the graphical front-end. The latter does not come installed by default so you must install it through Synaptic. I can't tell you about other Linux distributions.

The router has its own configuration, and this is different for each router brand and type. But what you must do is add a port forwarding rule for any service you want to allow. The server must have a fixed IP address, as it will only be referenced based on IP address. The port forwarding rule essentially says "if the router receives any data for port X, forward this data to port Y* on server A.B.C.D". Check out the router manual for more detailed instructions.

* X and Y may be the same, like 3306 for MySQL, but they can be usually different if needed.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Thanks ! One last question

I assumed that all routers, in a shared connection environment, simply assign internal IP's to individual computers.

Is this assumption correct ?

Or is it, for example, possible to truly have TWO computers with the exact same internal and external IP addresses ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

jay vas wrote:Thanks ! One last question

I assumed that all routers, in a shared connection environment, simply assign internal IP's to individual computers.

Is this assumption correct ?

If it has a built-in DHCP server, yes. Otherwise there must either be a different machine with a DHCP server running in the internal network, or each machine must have a fixed IP address.

Or is it, for example, possible to truly have TWO computers with the exact same internal and external IP addresses ?

IP addresses within one network must be unique, or you will get errors. With "network" I mean a group of machines that can access each other directly. You can use 192.168.0.1 in two different networks as long as they can't see each other. This is a very common situation; you can have that IP address in your internal network and I can have the same IP address in my own internal network. The external IP address must be unique worldwide because it can usually be accessed from worldwide.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: naive server ip connection question
 
Similar Threads
Wireless Access point question
Executing Netbeans 3.6 web application from another pc
Set tomcat for static IP.
Can not connect to internet
"main" java.sql.SQLException: Access denied for user 'root'@'192.168.1.1' (using password: YES)