A Simulated Network with Qemu and Sockets
I was trying to test some networking stuff with various operating systems. I have neither the patience nor the hardware to set up a bunch of real machines with those systems to try out things. So qemu came to my mind to simulate these things - which would be good enough for my problem case.
According to my study of the various parts of documentation on qemu, the fastest way to get this going was to set up a "socket" based network. That way, a couple of virtual machines can share a virtual network. They don't have access to the host's network connection - and therefore to the Internet though - unless you set up one of the guest OS systems as a router and set up some routing. I wasn't going to do that, as in my problem case a bit of isolation is a good thing.
My first machine is running some oldish variant of Linux. There isn't much special about it in that sense. This machine is the one that is set up as a "socket listener" in the command line:
#!/bin/sh qemu-system-x86_64 -nographic -no-acpi \ -m 1024 -clock unix \ -net nic,model=rtl8139,macaddr=52:55:01:4e:79:28 \ -net socket,listen=:1234 \ -hda lunix_hda.img
Basically it's a normal qemu command, the only thing different from usual is that we're not specifying the default "user" type of network, we're using "socket". This means that the vm will listen on port 1234 on the host operating system (127.0.0.1 is implied here).
The second machine is running good ol' Windows 2000 - guess why a bit of isolation is a good thing. Here too, the setup is pretty much standard. Note that I'm specifying MAC addresses - apparently if I don't do that, all virtual systems will get the same MAC address, which is not a good thing in a network. The socket network setup is there too:
#!/bin/sh qemu-system-i386 -m 512 \ -net nic,vlan=0,model=ne2k_pci,macaddr=52:54:00:12:34:58 \ -net socket,connect=127.0.0.1:1234 \ -monitor stdio w2kdisk.qcow2
I'm not sure it's necessary to specify 127.0.0.1 here, but it was like that in the docs. We do not set it to "listen", we set it to "connect" on this machine.
Now these two virtual machines will live in the same network, it's as if they were connected with ethernet cables. They do not have any IP addresses yet though - when using the "socket" networking in qemu, the built-in DHCP server from the "user" network is not activated. No problem though, on Windows just go to the control panel and set up an IP address and netmask (no router, name server or anything else required). Set up a different IP in the same network range and netmask on the other machine (on Linux with ifconfig). Now they can ping each other and as a test the windows machine can telnet to port 22 of the Linux system.
More machines could be set up to this system and you could even set up more virtual ethernet cards and hook them to more virtual networks, or route them through the host system to the Internet.