- Learn Linux
- Learn Electronics
- Raspberry Pi
- LPI certification
- News & Reviews
19 July 2010
Sometimes you need to know your IP address. Sometimes it needs to be the real IP address that you appear as on the Internet and not just the fake one that your local router uses. An example is when I blocked access from visitors whilst upgrading my blog.
First thing is you need to understand the different between public and private IP addresses to know which address you should be looking for. It's explained in detail in the Networking reference guide, but I'm guessing you'd rather have it condensed down to less than 5000 words.
Basically put your IP address is a string of numbers that identifies your computer on the Internet. When you are going to a website such as www.penguintutor.com that name is translated into the IP address (currently 220.127.116.11) and that's where your request goes to. The problem is that we are running out of addresses and in some cases (eg. for security reasons) you may want to hide behind a local IP address.
There are some addresses that are reserved for private address ranges which are:
Class A 10.0.0.0 to 10.255.255.255 Class B 172.16.0.0 to 172.31.255.255 Class C 192.168.0.0 to 192.168.255.255
If you are using a home router rather than connecting directly to a ADSL/Cable Modem then you will most likely be given a private IP address from one of the ranges above and your computer will appear to be from the Internet IP address of the router when connecting to a site on the Internet.
If you are wanting to connect to a local machine on the same network (eg. to share files between computers on the same wireless network) then you normal need to know the local ip address. If however you are looking to add your IP address to a server on the Internet then you need to use the real Internet IP address.
With Linux you can issue the ifconfig command. Then look for the address inet addr:
eth0 Link encap:Ethernet HWaddr 00:1d:6c:3b:d4:a0 inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20d:31ff:fe0d:d9a0/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:755027 errors:0 dropped:0 overruns:0 frame:0 TX packets:1045478 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:118125432 (118.1 MB) TX bytes:1268529451 (1.2 GB) Interrupt:16 Base address:0xa000
On Windows you can open a command prompt and run the command ipconfig.
Windows IP Configuration Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : penguintutor.com IP Address. . . . . . . . . . . . : 192.168.1.232 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.1.1
If you need to find your public IP address then that will need to be done over the Internet. It is possible you may have a different proxy IP address to the address used for other protocols, and you could also have a proxy that gives different IP addresses per session but to keep it simple I'm assuming that the address you get to this server with is the same as the one you need.
You can check your ip address here:
In this case the it's just 2 lines of PHP code which can be included in an appropriate php file on a webserver:
Note: This is all based on IPV4 which is what most of us are using when I wrote this. IPV6 has many more IP addresses and different private address ranges (see RFC4193).