Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm doing some computer network homework and I'm supposed to develop some sort of Peer to Peer file sharing software, and when I wanna test it I need to run a few (5) instances on my linux/ubuntnu 11.10 . which means each one need to has a unique IP address. I heard I can do that but I dunno how. how can I have many IP addresses on a single computer? thanks

share|improve this question
add comment

closed as off topic by splattne Feb 2 '12 at 11:47

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers

up vote 5 down vote accepted

It is not really clear what you are trying to do, but you can run multiple virtual machines (virtualization) on your PC to do your tests using a single machine.

If you want to have multiple IP addresses on the same physical interface, that is another thing. If this is what you want, you can do it the old way using ifconfig or the new way using ip addr add.

The old way:

$ sudo ifconfig eth0:0 your.ip.addr.ess netmask your.sub.net.mask up

The new way:

$ sudo ip addr add your.ip.addr.ess/mask.bits dev eth0

Of course, you need to replace your.ip.addr.ess with real value like 192.168.1.1 and your.sub.net.mask with something like 255.255.255.0. The mask.bits can be something like 24. You may need also to change the device name eth0. To view the IPs currently added, you can use ifconfig (old) or ip addr show (new).

share|improve this answer
    
yes I want multiple IP addresses on the same physical interface –  ePezhman Feb 2 '12 at 9:31
add comment

You need to create a subinterface inorder to assign a multiple ip to the same interface (for e.g. eth0). The command for assigning suppose 2 Ip address like 10.100.10.1/24 & 10.100.10.2/24 to interface eth0 will be as follows

# ifconfig eth0 10.100.10.1 netmask 255.255.255.0 up

# ifconfig eth0:1 10.100.10.2 netmask 255.255.255.0 up

After this restart the network

service network restart

I hope this answers your question...

share|improve this answer
add comment

I think you should look into loopback side.

insider@localhost:/$ sudo ifconfig eth0:3 192.168.1.104 netmask 255.255.252.0
insider@localhost:/$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:26:b6:ff:69:93  
          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::226:b6ff:feff:6993/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17987 errors:0 dropped:0 overruns:0 frame:20557
          TX packets:18061 errors:15 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:13320368 (13.3 MB)  TX bytes:3143160 (3.1 MB)
          Interrupt:16 

eth0:2    Link encap:Ethernet  HWaddr 00:26:b6:ff:69:93  
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:16 

eth0:3    Link encap:Ethernet  HWaddr 00:26:b6:ff:69:93  
          inet addr:192.168.1.104  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:16 

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:285 errors:0 dropped:0 overruns:0 frame:0
          TX packets:285 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:54727 (54.7 KB)  TX bytes:54727 (54.7 KB)
share|improve this answer
2  
Not only does the loopback interface have nothing to do with this, you didn't even link to the correct article. –  Ignacio Vazquez-Abrams Feb 2 '12 at 9:26
    
255.255.250.0 is also not a valid netmask (250 base 10 = 1111 1010 base 2; netmasks must be a continuous sequence of 1 bits followed by a continuous sequence of 0 bits), which is almost certainly the reason for the (admittedly incredibly unhelpful) SIOCSIFNETMASK: Invalid argument at the top. I don't know what does the fudging to a /24, and am too lazy to find out... :) –  Michael Kjörling Feb 2 '12 at 10:33
    
i know i'm a bit lazy :), but an error has been ignored –  insider Feb 5 '12 at 0:16
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.