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.

After 3 days I finally have kvm guests working on the network via wireless (link below - thanks!):

My network is 192.168.1.0/24

on the host:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo tunctl -t tap0
sudo ip link set tap0 up
sudo ip addr add 192.168.1.25/24 dev tap0
sudo route add -host 192.168.1.30 dev tap0
sudo parprouted wlan0 tap0

on the guest:

auto eth0
iface eth0 inet static
  address 192.168.1.30
  netmask 255.255.255.0
  network 192.168.1.0
  broadcast 192.168.1.255
  gateway 192.168.1.25

and start the guest:

sudo kvm /path/to/guest.img -net nic,macaddr=DE:AD:BE:EF:90:26 -net tap,ifname=tap0,script=no

This works great and I can ping the local network and the internet back and forth between the guest.

But how do I add these settings to the guest's xml config so I can start the guest via virt-manager with the same nic settings?

ref:

share|improve this question
    
Wonderful! Worked great for me too! Thank you very much for this great tip! –  Avio Jul 17 '12 at 12:00
add comment

2 Answers

I think you are trying to setup bridged networking in a round-about way by creating tap devices etc. In Linux you can create a virtual bridge device for a physical interface using simple configuration changes. Once done the KVM VMs can be configured to use this virtual bridge device to connect to normal LAN as if they were directly connected to it. It gives illusion that all VMs and base/host machine are all connected to LAN directly.

If that is what you want then modify your /etc/sysconfig/network-scripts/ifcfg-eth0 (assuming eth0 is the host network device having IP in 192.168.1.0/24 network in your case) to have lines

DEVICE=eth0
TYPE=Ethernet
BRIDGE=br0

among other configuration lines. Copy ifcfg-eth0 to ifcfg-br0 where ifcfg-br0 should differ from ifcfg-eth0 in below mentioned lines

DEVICE=br0
TYPE=Bridge

Now when you use 'service network restart' you will have to network interfaces br0 and eth0 and your LAN IP in range 192.168.1.0/24 would seem to be assigned to br0. Now all you have to do is to edit VM settings and ask it to connect using br0 network.

share|improve this answer
    
thanks Saurabh, but this round-about way is because wireless interfaces don't support normal bridging, like you would with a wired eth0 interface. –  DaveO Nov 2 '10 at 9:33
    
Oops! My bad. Was not aware that bridging does not works for wireless interfaces as they do for wired. –  Saurabh Barjatiya Nov 7 '10 at 4:59
    
Instead of bridging. You can also setup complete wireless network with its own DHCP and use some unused private IP range. Then to make this wireless network connect outside you can use source/destination NAT on machine which has both wireless and wired connection. If wireless VMs wont have any servers then only source PAT would do. If it is necessary to connect to wireless VMs from rest of the network then source and destination NAT combo should do. –  Saurabh Barjatiya Nov 12 '10 at 13:19
add comment

What's wrong with using macvtap? This is completely painless and doesn't require any further configuration on the host.

macvtap selection in virt-manager

share|improve this answer
    
Macvlan / macvtap is great for wired interfaces but it seems to not work on wireless interfaces, based on my own experience and experience read online. –  lgaggini Nov 14 '13 at 11:05
    
@lgaggini You can't bridge to wireless interfaces because the AP will reject the MAC addresses of the virtual machines. In that case you just do something else. –  Michael Hampton Nov 14 '13 at 13:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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