13

I have a dedicated server with one network card in it. I however got two IP addresses. When I use the simple command sudo ip addr add 188.40.90.88 dev eth0 it fails to see it as a separate IP. I've googled along trying to find a fix, but I can't really find out what packages I need to set up a switch, and how to do it.

My dedicated server runs with the following specifications:

  • 16GB DDR3 RAM ( intel i7 )
  • OS: ubuntu 14.01

These are the two most important ones, I believe; I've got no idea what network card my dedicated server has, but I know it supports IEEE 802.1q, which I found out on the Ubuntu website.

3
  • What does ip addr show say after running that command and what does "it fails to see it as a separate IP" mean? Commented Jan 13, 2015 at 3:06
  • I found that ip addr was temporary. I've re-routed the NIC and now it works. I have forgotten to bind my processes too.
    – Sam
    Commented Jan 13, 2015 at 23:11
  • I also need that and i found a best answer "How to Assigning multiple Virtual IPs to a NIC" on this site linuxinpakistan.com/assigning-multiple-virtual-ips-nic
    – Mari Criss
    Commented Sep 23, 2017 at 8:04

3 Answers 3

20

I'm not quite sure exactly what you're trying to accomplish. I am assuming that your question could be re-titled "How to set up two IPs on a single network interface."

Each network interface on your machine is given an identifier. Typically, you start with eth0 and work your way up (eth1, eth2, eth3). These are all physically different network cards.

You can also have virtual cards on top of each of your physical cards. This is how you would set up multiple IPs on the same NIC.

To set this up, you can use the following example, changing the addresses to suit your needs (/etc/network/interfaces):

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback


# The primary network interface
auto eth0 eth0:0
allow-hotplug eth0 eth0:0

#eth0
iface eth0 inet static
address 123.123.123.123
netmask 255.255.255.0
gateway 123.123.123.1

#eth0:0 (LAN)
iface eth0:0 inet static
address 212.212.212.212
netmask 255.255.128.0
gateway 212.212.212.1

The tricky part could be the netmask. Try 255.255.255.0 if you aren't sure.

11

If you set a secondary IP for eth0, it should be set to eth0:0:

sudo ip addr add 188.40.90.88 dev eth0:0
7
  • 3
    Please explain your answer more clearly. How would the OP set the IP? Using which command? Editing what file? Could you provide an example? Perhaps explain what eth0:0 means? We expect answers here to be comprehensive.
    – terdon
    Commented Jan 8, 2015 at 11:48
  • The command is exactly the same as the OP is using to add an IP to begin with, just use eth0:0 instead of eth0.
    – Elias
    Commented Jan 8, 2015 at 11:53
  • 1
    Please edit your answer to add extra information, it is hard to read and easy to miss in the comments. Just add an extra line showing the command the OP would need to run.
    – terdon
    Commented Jan 8, 2015 at 12:04
  • This has not done the trick. It instead gives priority to the second port I open up ( same ports ), but it does not seperate those.
    – Sam
    Commented Jan 8, 2015 at 16:44
  • What are you actually trying to accomplish and how is your routing set up?
    – Elias
    Commented Jan 8, 2015 at 17:04
3

On Ubuntu you could try this:

If you have two IP adresses configured on your server, to see them you could run a simple ifconfig:

# ifconfig

eth1  Link encap:Ethernet  HWaddr 00:aB:cD:eF:Gh:Ij  
      inet addr:X.X.X.X  Bcast:X.X.X.X  Mask:255.255.255.248 # IP address ONE
      inet6 addr: fe80::230:48ff:fe34:1c17/64 Scope:Link


eth1:0 Link encap:Ethernet  HWaddr 00:aB:cD:eF:Gh:Ij  
      inet addr:X.X.X.X  Bcast:X.X.X.X  Mask:255.255.255.255 # IP address TWO
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

If you want to configure your second IP address in the same NIC you must specify your NIC interface & create a virtual IP:

# ifconfig eth1:0 X.X.X.X netmask 255.255.255.255 # Setting up IP address TWO

If you want to reach a specific address through your virtual or secondary IP, you could make a route.

# ip route add <target> via <network IP> dev <NIC interface [eth1]> [SECOND IP]

Not the answer you're looking for? Browse other questions tagged .