Difference between revisions of "Qemu networking"
m |
m |
||
Line 1: | Line 1: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Virtualization tools]] > [[Qemu]] > [[Qemu networking]] | |||
Qemu supports four types of networking. Details are available in wikibook at http://en.wikibooks.org/wiki/QEMU/Networking | Qemu supports four types of networking. Details are available in wikibook at http://en.wikibooks.org/wiki/QEMU/Networking | ||
Line 48: | Line 47: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Virtualization tools]] > [[Qemu]] > [[Qemu networking]] |
Latest revision as of 13:16, 24 August 2022
Home > CentOS > CentOS 6.x > Virtualization tools > Qemu > Qemu networking
Qemu supports four types of networking. Details are available in wikibook at http://en.wikibooks.org/wiki/QEMU/Networking
User mode
This is default and automatically chosen if nothing else is selected. Main points about this are:
- Host has IP 10.0.2.2. Guest can SSH to host at this IP.
- Host to guest connections will not work
- Guest can only ping to host as protocols apart from UDP, TCP do not work. Hence ICMP protocols will not work.
- Guest can access outside network. Thus nslookup (via DNS at 10.0.2.3) and net-browsing in guest will work.
Redirecting ports
To connect from host to guest in user mode, one can use tcp port forwarding. For example adding '-redir tcp:5555::22' will allow SSHing to guest from host using 'ssh -p 5555 root@localhost'.
Note -redir option is not documented in latest docs or man pages, but it seems to work properly. If use of documented features is necessary then same can be achieved using '-net nic -net user,hostfwd=tcp::5555-:22' as 'hostfwd' option of '-net user' is exactly same as -redir option.
Tap interfaces
For full networking using bridges tap interfaces can be used. Before using tap interfaces set up local machine to use bridged networking so that br0 is present and has IP, etc. Then create following two scripts:
- /etc/qemu-ifup
#!/bin/bash /usr/sbin/openvpn --mktun --dev $1 --user `id -un` /sbin/ifconfig $1 0.0.0.0 promisc up /usr/sbin/brctl addif br0 $1
- /etc/qemu-ifdown
#!/bin/bash /usr/sbin/brctl delif br0 $1 /sbin/ifconfig $1 down /usr/sbin/openvpn --rmtun --dev $1
Do 'chmod +x' on both scripts. Now to use bridged networking on a VM use:
sudo /etc/qemu-ifup tap0 qemu <Other options> -net nic -net tap,ifname=tap0,script=no sudo /etc/qemu-ifdown tap0
Note that thus if tap0, tap1, etc. are already connected then qemu guests will be able to use bridged networking without requiring root privileges.
Home > CentOS > CentOS 6.x > Virtualization tools > Qemu > Qemu networking