1

First of all this question is not about virtual host in Apache.

I have a network with the following address: 1.1.1.0

I have several host on this network: 1.1.1.1, 1.1.1.2, 1.1.1.3 and 1.1.1.4

The first host send a broadcast UDP paquet answer and expect other host to answer him.

Is it possible for my dev machine (1.1.1.4) to emulate the following virtual host : 1.1.1.5, 1.1.1.6, etc. ?

I'm using QUdpSocket from Qt 5.2.1 on MacOS 10.9 but I am open to any other tech that would help me do the trick.

Martin Delille
  • 11,360
  • 15
  • 65
  • 132

2 Answers2

3

It depends on you OS.

On linux, you can create multiple virtual network devices, and bind each of those devices to a different network address. The virtual network devices have the name of a real device with a :xxx numeric suffix. For example, if your primary network device is eth0, you can run the command

ifconfig eth0:1 1.1.1.5

to create the virtual device eth0:1 and bind it to the address 1.1.1.5. This is only temporary (it will go away when you reboot); if you want it to come back when you reboot, you can edit the `/etc/network/interfaces file to look something like:

auto eth0
iface eth0 inet static
    address 1.1.1.4
    netmask 255.255.255.0
    gateway 1.1.1.1

auto eth0:1
    address 1.1.1.5
    netmask 255.255.255.0

the lack of a gateway in the eth0:1 part means that it won't use this interface for routing, so it just exists for receiving packets and explicit binding to an ip address.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
1

Install VirtualBox (here) and make a tiny disk image big enough for a small Linux distro. Run several copies, each one at a different IP address and run a tiny netcat script in each one that listens and sends replies.

#!/bin/bash
while :
do
   command=$(nc -ul 1234)
   process $command and reply
done

Or, read this and go with Chris's idea which is lighter weight on resources!

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432