One of the most common questions that comes from newbies is “What is my server’s IP address?”.
This is actually a pretty good question when it comes for VPS servers because the IP addresses are generally allocated by the service provider – you can have 1 IP address, maybe more, it depends on how generous your provider is and how much you want to pay for it.
Many hosting providers allow for their clients to purchase additional IP addresses (IPv4 or IPv6) for a monthly/yearly fee. Of course, you will need to contact your hosting provider to find out the exact price for it.
What you can do on your machine though is to look at ifconfig output to see what you have configured:
[root@bubble ~]# ifconfig 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:94736312 errors:0 dropped:0 overruns:0 frame:0 TX packets:94736312 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:73839990799 (68.7 GiB) TX bytes:73839990799 (68.7 GiB) venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:127.0.0.1 P-t-P:127.0.0.1 Bcast:0.0.0.0 Mask:255.255.255.255 inet6 addr: 2607:f348:101e::724:f12d/128 Scope:Global inet6 addr: 2607:f348:101e::7ea9:45f1/128 Scope:Global inet6 addr: 2607:f348:101e::2196:d9e0/128 Scope:Global inet6 addr: 2607:f348:101e::2c5b:2e29/128 Scope:Global inet6 addr: 2607:f348:101e::f7f4:7fcf/128 Scope:Global inet6 addr: 2607:f348:101e::b9f0:b45a/128 Scope:Global inet6 addr: 2607:f348:101e::e82e:c759/128 Scope:Global inet6 addr: 2607:f348:101e::7806:6bf5/128 Scope:Global UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1 RX packets:88091696 errors:0 dropped:0 overruns:0 frame:0 TX packets:96564965 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:11088477814 (10.3 GiB) TX bytes:96558104335 (89.9 GiB) venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:108.166.185.123 P-t-P:108.166.185.123 Bcast:108.166.185.123 Mask:255.255.255.255 UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
Ok .. so which one is the IP address? Short version: all of them.
Most Linux servers have multiple network interfaces:
- lo – loopback interface
- eth0, eth1, … – ethernet interface
- venet – virtual network device
It is common for a VPS server to have the public IPs set up as virtual network devices – simply because each client needs 1 or more dedicated addresses.
This is why from the example above, the most important one is venet0:0 – in this case it is a virtual network device with only 1 IPv4 address assigned: 108.166.185.123.
The virtual network device is also configured with 8 IPv6 addresses (inet6 addr fields) and of course it also has a loopback address (127.0.0.1).
It might seem a bit too much information, but you will get the hang of it pretty easily.
How about interfaces which have the link down for example (maybe the cable is not connected, maybe the switch is not accepting the connection)? You will notice that those interfaces will not be displayed by default, but you can use the following command to see all interfaces, no matter if they are UP or DOWN: ifconfig -a.
Another useful command you can use to see IP configuration is ip addr show:
[root@bubble ~]# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: venet0: <BROADCAST,POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN link/void inet 127.0.0.1/32 scope host venet0 inet 108.166.185.123/32 brd 108.166.185.123 scope global venet0:0 inet6 2607:f348:101e::b9f0:b45a/128 scope global valid_lft forever preferred_lft forever inet6 2607:f348:101e::7ea9:45f1/128 scope global valid_lft forever preferred_lft forever inet6 2607:f348:101e::724:f12d/128 scope global valid_lft forever preferred_lft forever inet6 2607:f348:101e::e82e:c759/128 scope global valid_lft forever preferred_lft forever inet6 2607:f348:101e::f7f4:7fcf/128 scope global valid_lft forever preferred_lft forever inet6 2607:f348:101e::7806:6bf5/128 scope global valid_lft forever preferred_lft forever inet6 2607:f348:101e::2c5b:2e29/128 scope global valid_lft forever preferred_lft forever inet6 2607:f348:101e::2196:d9e0/128 scope global valid_lft forever preferred_lft forever
It is a bit more complicated to read, but if you learn a bit about network mask you will understand why all the addresses have an extra /32 at the end (/128 for ipv6 in this case).
Yes, networking in Linux can be quite complex! If you want to see some really nice things you can do, check out this tutorial.