Skip to contentSkip to conversation

Question about tun/tap networking

Qemu-devel Jim C. Brown 3 participants 4 messages Jun 23, 2004 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 9 lines · Phil Rasch

I have been running a mixture of linux and windows machines, all real machines on a LAN connected to the outside world through a router, which is acting as my DHCP server, DNS server, and gateway machine.

The LAN subnet is 192.168.0.*

Now I want to connect up the virtual machine running under QEMU. I want the virtual machine to be on the same subnet as the real machines, and to use DHCP from the router to get all the relevant info.

That is tricky. You will need to look into bridging.

Quoted 11 lines

Jim suggested the following commands for somebody else on the mailing list, but I think that was headed towards devising a subnet that two virtual machines could use to talk to each other.

[/space/qemu/qemu-0.5.4/ $] su root [/space/qemu/qemu-0.5.4/ #] vde_switch -daemon -tap tap0 [/space/qemu/qemu-0.5.4/ #] ifconfig tap0 192.168.1.254 [/space/qemu/qemu-0.5.4/ #] chmod 777 /tmp/vde.ctl [/space/qemu/qemu-0.5.4/ #] exit [/space/qemu/qemu-0.5.4/ $] vdeq qemu -hda disk1.img

That is correct. You now have 2 subnets, 198.168.0.* for the real network and 192.168.1.* for qemu/VDE.

Quoted 7 lines

The thing I dont understand is whether the above command is setting up seperate subnet for the virtual machines, or whether I can also set them up on the same subnet as the real machines, and let them see the DHCP server, etc, and if so, then how to do it. So far, I have never needed to learn the subtleties of ifconfig. Am I going to have to do so now? Do you have anymore advice on using VDE and QEMU together for my purpose?

Like I said, you will need to use bridging. After you have loaded vde_switch, skip the ifconfig step, and combine eth0 and tap0 into br0. Then you will need to set up br0 properly. If you are going to use bridging however, I recommend you use tuntap instead of VDE. (You don't really need VDE if you are going to to use bridging.) If you decide to go with tuntap and bridging, you should look in the qemu archives for assistance. There are several messages that appear to have useful information on this topic, such as this one which tells you step-by-step:

http://lists.gnu.org/archive/html/qemu-devel/2004-05/msg00032.html

(you'll need to do a 'brctl addif br0 eth0' and a 'ifconfig br0 192.168.0.XXX' for the machine that will be running qemu (almost certainly in one of the startup scripts, as eth0 must not have an ip yet) but otherwise the instructions are exactly the same.)

I am curious though, why do you require that the virtual machines be on the same subnet as the real ones?

Quoted 4 lines

Thanks

Phil

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#2 lore raw

Thanks Jim,

I dont really require everything to be on the same subnet. I just hate having to figure out how to setup the nameservers, gateways, IP numbers etc on each virtual machine I create. It would have been great to just tell the virtual machine to "go get the relevant info from the DHCP server". Maybe the alternative isnt really a big deal, but like I said, I am a beginner at configuring networks.

Phil

Quoted 63 lines · Jim C. Brown
Quoted 9 lines · Phil Rasch

I have been running a mixture of linux and windows machines, all real machines on a LAN connected to the outside world through a router, which is acting as my DHCP server, DNS server, and gateway machine.

The LAN subnet is 192.168.0.*

Now I want to connect up the virtual machine running under QEMU. I want the virtual machine to be on the same subnet as the real machines, and to use DHCP from the router to get all the relevant info.

That is tricky. You will need to look into bridging.

Quoted 11 lines

Jim suggested the following commands for somebody else on the mailing list, but I think that was headed towards devising a subnet that two virtual machines could use to talk to each other.

[/space/qemu/qemu-0.5.4/ $] su root [/space/qemu/qemu-0.5.4/ #] vde_switch -daemon -tap tap0 [/space/qemu/qemu-0.5.4/ #] ifconfig tap0 192.168.1.254 [/space/qemu/qemu-0.5.4/ #] chmod 777 /tmp/vde.ctl [/space/qemu/qemu-0.5.4/ #] exit [/space/qemu/qemu-0.5.4/ $] vdeq qemu -hda disk1.img

That is correct. You now have 2 subnets, 198.168.0.* for the real network and 192.168.1.* for qemu/VDE.

Quoted 7 lines

The thing I dont understand is whether the above command is setting up seperate subnet for the virtual machines, or whether I can also set them up on the same subnet as the real machines, and let them see the DHCP server, etc, and if so, then how to do it. So far, I have never needed to learn the subtleties of ifconfig. Am I going to have to do so now? Do you have anymore advice on using VDE and QEMU together for my purpose?

Like I said, you will need to use bridging. After you have loaded vde_switch, skip the ifconfig step, and combine eth0 and tap0 into br0. Then you will need to set up br0 properly. If you are going to use bridging however, I recommend you use tuntap instead of VDE. (You don't really need VDE if you are going to to use bridging.) If you decide to go with tuntap and bridging, you should look in the qemu archives for assistance. There are several messages that appear to have useful information on this topic, such as this one which tells you step-by-step:

http://lists.gnu.org/archive/html/qemu-devel/2004-05/msg00032.html

(you'll need to do a 'brctl addif br0 eth0' and a 'ifconfig br0 192.168.0.XXX' for the machine that will be running qemu (almost certainly in one of the startup scripts, as eth0 must not have an ip yet) but otherwise the instructions are exactly the same.)

I am curious though, why do you require that the virtual machines be on the same subnet as the real ones?

Quoted 4 lines

Thanks

Phil

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
Signature · 4 lines
Phil Rasch, Climate Modeling Section, National Center for Atmospheric Research
Mail     --> P.O. Box 3000, Boulder CO 80307  
Shipping --> 1850 Table Mesa Dr, Boulder, CO 80305
email: [email protected], Web: http://www.cgd.ucar.edu/cms/pjr Phone: 303-497-1368, FAX: 303-497-1324 
#3 lore raw
In reply to Jim C. Brown
Quoted 1 line · Jim C. Brown

That is tricky. You will need to look into bridging.

There are a few ways to do it:
o static nat
o iptables nat
o bridging

Try this qemu-ifup for script for the iptables method:

http://www.scaramanga.co.uk/stuff/qemu-ifup

Signature · 3 lines
// Gianni Tedesco (gianni at scaramanga dot co dot uk)
lynx --source www.scaramanga.co.uk/scaramanga.asc | gpg --import
8646BE7D: 6D9F 2287 870E A2C9 8F60 3A3C 91B5 7669 8646 BE7D
#4 lore raw
Quoted 12 lines · Gianni Tedesco
Quoted 1 line · Jim C. Brown

That is tricky. You will need to look into bridging.

There are a few ways to do it:
o static nat
o iptables nat
o bridging

Try this qemu-ifup for script for the iptables method:

http://www.scaramanga.co.uk/stuff/qemu-ifup

That's not what he asked for. AFAICT that script will set up a separate subnet, 192.168.1.*, instead of using the 192.168.0.* subnet. It won't do what he wants. (It looks like that to the outside world it will have an ip of $qemu_ip, but from inside the guest OS he will still be on a separate subnet.)

In any case my recommendation is that he uses VDE and maintains all the virtual machines on a separate subnet from his actual LAN (assuming thats possible, of course some Windows machines will refuse to browse SMB network shares that aren't on the same subnet ... but thats slightly off-topic).

Quoted 11 lines
Signature · 10 lines
// Gianni Tedesco (gianni at scaramanga dot co dot uk)
lynx --source www.scaramanga.co.uk/scaramanga.asc | gpg --import
8646BE7D: 6D9F 2287 870E A2C9 8F60 3A3C 91B5 7669 8646 BE7D



_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel
Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.