8

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:

DaveO
  • 175
  • 1
  • 5
  • 16

3 Answers3

1

try to follow this: libwirtwiki - guest tap

and fix /etc/libvirt/qemu/example.xml

<interface type='ethernet'>
  <mac address='26:c7:a9:96:a7:7a'/>
  <target dev='tap0'/>
  <model type='virtio'/>
  <script path='no'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>

in my case it works

MecaT
  • 11
  • 1
0

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.

Saurabh Barjatiya
  • 4,703
  • 2
  • 30
  • 34
  • 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 02 '10 at 09:33
  • Oops! My bad. Was not aware that bridging does not works for wireless interfaces as they do for wired. – Saurabh Barjatiya Nov 07 '10 at 04: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
0

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

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • 3
    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
  • 2
    @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