Diferencia entre revisiones de «QEMU/Redes»

Contenido eliminado Contenido añadido
I32lomaj (discusión | contribs.)
Página creada con «QEMU supports networking by emulating some popular network cards (NICs), and establishing virtual LANs (VLAN). There are four ways how QEMU guests can be...»
 
I32lomaj (discusión | contribs.)
Sin resumen de edición
Línea 1:
QEMU supportssoporta networkingredes byemulando emulatingalgunas somede popularlas networktarjetas cardsde red (NICsNIC) más populares, andy establishingestableciendo [[w:Virtual LANVLAN|virtualLAN LANsvirtuales]] (VLAN). ThereHay arecuatro fourformas waysen howlas QEMUque guestslos canhuéspedes bede connectedQEMU pueden ser thenconectados: usermodo modeusuario, socketredirección redirectionde conexiones, redes Tap andy VDE networking.
 
==UserRed modeen networkingmodo usuario==
 
Si no se especifican opciones de red, QEMU emulara por defecto una única tarjeta de red PCI Intel e1000 con un red en modo usuario que enlaza con la red del host. Los siguientes dos comandos son equivalentes:
If no network options are specified, QEMU will default to emulating a single Intel e1000 PCI card with a user-mode network stack that bridges to the host's network. The following two command lines are equivalent:
 
qemu -m 256 -hda disk.img &
qemu -m 256 -hda disk.img -net nic -net user &
 
TheEl guestsistema OSoperativo willguest seeverá anuna NIC E1000 NICcon withun aservidor virtual DHCP server onen 10.0.2.2 andy willserá beasignada allocatedcon anuna addressdirección startinga partir fromde 10.0.2.15. AUn virtualservidor DNS servervirtual willserá beaccesible accessible onen 10.0.2.3, andy aun virtualservidor SAMBA file servervirtual (ifsi presentexiste) willserá beaccesible accessible onen 10.0.2.4 allowingpermitiendo youel toacceso accessa filesficheros onen theel host viaa SAMBAtravés filede sharescompartición de ficheros de SAMBA.
 
La red en modo usuario es buena para permitir el acceso a recursos de red, incluyendo Internet. Por defecto, sin embargo, actúa como un cortafuegos y no permite el tráfico entrante. Tampoco soporta otros protocolos que no sean TCP y UDP - así, por ejemplo, ping y otras utilidades ICMP no funcionarán.
User mode networking is great for allowing access to network resources, including the Internet. By default, however, it acts as a firewall and does not permit any incoming traffic. It also doesn't support protocols other than TCP and UDP - so, for example, ping and other ICMP utilities won't work.
 
===Redireccionamiento de puertos===
===Redirecting ports===
 
Para permitir las conexiones de red hacia el sistema operativo guest bajo el modo usuario de red, se puede redirigir un puerto del sistema operativo host a un puerto del sistema operativo guest. Esto es muy útil para dar soporte a la compartición de ficheros, servidores web y servidores SSH desde el sistema operativo guest.
To allow network connections to the guest OS under user mode networking, you can redirect a port on the host OS to a port on the guest OS. This is useful for supporting file sharing, web servers and SSH servers from the guest OS.
 
HereAsí ises howcomo tose set upconfiguraría QEMU withcon aun Windows XP como guest sharingcompartiendo filesficheros andy páginas web pagesbajo underel usermodo modeusuario networkingde red. El puerto TCP port 5555 on thedel host isse redirectedredirige toal thepuerto guest's80 portdel 80guest (theel servidor web server) andy TCPel portpuerto 5556 on thedel host isal redirectedpuerto to445 thedel guest's port(red 445de (Windows networking)::
 
qemu -m 256 -hda disk.img -redir tcp:5555::80 -redir tcp:5556::445 &
Línea 24:
firefox <nowiki>http://localhost:5555/</nowiki>
 
NBNOTA: Whencuando sharingse folderscomparten fromcarpetas desde el guest toa hosttravés viade Windowsla networkingred de Windows, youse mustdebe specifyespecificar auna passwordcontraseña forpara theel userusuario thatque mount willusará usepara to loginconectarse; ifsi youse tryintenta tousar usesin no passwordcontraseña, mount willfallará failcon withun anerror I/Ode errorentrada/salida.
 
==Interfaces TAP==
==TAP interfaces==
 
QEMU puede usar interfaces TAP para proporcionar capacidad de red complete para el sistema operativo guest. Esto puede ser útil cuando el sistema operativo guest está ejecutando varios servicios de red y debe estar conectado a través de puertos estándar; cuando se requieren otros protocolos distintos de TCP y UDP; y cuando múltiples instancias de QEMU necesitan conectarse entre ella (aunque esto se puede conseguir en el modo usuario de red a través de Redireccionamiento de puertos, o a través de conexiones).
QEMU can use TAP interfaces to provide full networking capability for the guest OS. This can be useful when the guest OS is running several network services and must be connected to via standard ports; where protocols other than TCP and UDP are required; and where multiple instances of QEMU need to connect to each other (although this can also be achieved in user mode networking via port redirects, or via sockets).
 
InEn QEmuQemu 1.1 andy newerposteriores, theel [http://wiki.qemu.org/Features/HelperNetworking networkasistente bridgede helperpuente de red] canpuede setconfigurar tun/tap up forpor youel withoutusuario thesin neednecesidad forde additionalscripts scriptingadicionales.
 
For olderPara versions más antiguas, settingconfigurar upun ainterfaz TAP interfacees isun apoco bitmás morecomplicado complicatedque thanen usermodo modeusuario networkingde red. ItSe requiresrequiere installinginstalar virtualred privateprivada networkingvirtual (VPN) onen theel hostsistema OSoperativo host, andy thendespués establishingestablecer aun bridgepuente betweenentre thela red del host's networkingy andla thered virtual network.
 
Here'sAsí howes tocomo dose itharía oncon Fedora 8 withcon staticasignación IPestática addressde assignmentdirecciones IP. TheEl procedureprocedimiento shoulddebería beser verymuy similar onen otherotras Linuxdistrubuciones distrosLinux, andy probablyprobablemente notno toomuy differentdiferente onen otherotros sistemas *nix systems.
 
===Dispositivo TAP/TUN device===
According toSegun [http://www.kernel.org/doc/Documentation/networking/tuntap.txt tuntap.txt], wecreamos create the TAP/TUNprimero deviceel firstdispositivo:
$ sudo mkdir /dev/net
$ sudo mknod /dev/net/tun c 10 200
Línea 44:
===qemu-ifup===
 
FirstPrimero, setconfigurar up aun script topara createcrear theel bridgePuente andy bringlevantar upel theinterfaz TAP interface. We'llLlamaremos calla thiseste script <code>/etc/qemu-ifup</code>.
 
<pre>
#!/bin/sh
#
# script topara bringlevantar upel thedispositivo tun device inen QEMU inen bridgedmodo modepuenteado
# firstel parameterprimer isparametro namees ofel tapnombre devicedel dispositivo tap (e.gej. tap0)
#
# somealgunas constantsconstantes specificespecificas todel thehost local host - changecambiarlas para que se toajuste suita yoursu host
#
ETH0IPADDR=192.168.0.3
Línea 58:
BROADCAST=192.168.0.255
#
# FirstPrimero taketiramos eth0 down, thendespués bringlo itlevantamos upcon withla dirección IP address 0.0.0.0
#
/sbin/ifdown eth0
/sbin/ifconfig eth0 0.0.0.0 promisc up
#
# BringLevantamos upel thedispositivo tap device (nameel nombre sera el specifiedespecificado ascomo firstprimer argument,argumento byen QEMU)
#
/usr/sbin/openvpn --mktun --dev $1 --user `id -un`
/sbin/ifconfig $1 0.0.0.0 promisc up
#
# createcrear theel bridgepuente betweenentre eth0 andy theel tapdispositivo devicetap
#
/usr/sbin/brctl addbr br0
Línea 74:
/usr/sbin/brctl addif br0 $1
#
# onlysolo aun singlepuente bridgepara soque loopslos arebucles notno possiblesean posibles, turnapagamos el offSTP (spanning tree protocol)
#
/usr/sbin/brctl stp br0 off
#
# BringLevantamos upel thepuente bridge withcon ETH0IPADDR andy añadimos addla theruta defaultpor routedefecto
#
/sbin/ifconfig br0 $ETH0IPADDR netmask 255.255.255.0 broadcast $BROADCAST
/sbin/route add default gw $GATEWAY
#
# stopparar firewallel cortafuegos - commentcomentar thisesta outlínea ifsi youno don'tse useusa Firestarter
#
/sbin/service firestarter stop
Línea 90:
===qemu-ifdown===
 
YouTambién willse alsonecesitará need aun script topara resetreiniciar yourla networkingconfiguración afterde QEMUred exitsdespués de salir de QEMU. ToPara beser consistentconsistente, we'll calllo itllamaremos <code>/etc/qemu-ifdown</code>.
 
<pre>
#!/bin/sh
#
# Script topara bringtirar downy andborrar deleteel bridgepuente br0 whencuando QEMUsalimos exitsde QEMU
#
# Bring downTirar eth0 andy br0
#
/sbin/ifdown eth0
Línea 103:
/sbin/ifconfig br0 down
#
# DeleteBorrar theel bridgepuente
#
/usr/sbin/brctl delbr br0
#
# bring upLevantar eth0 inen modo "normal" mode
#
/sbin/ifconfig eth0 -promisc
/sbin/ifup eth0
#
# Eliminar el dispositivo tap
# delete the tap device
#
/usr/sbin/openvpn --rmtun --dev $1
#
# Iniciar el cortafuegos de nuevo
# start firewall again
#
/sbin/service firestarter start
</pre>
 
===AllowingPermitir usersa tolos callusuarios theejecutar los scripts===
 
InEn qemu 1.1 andy aboveposteriores justsolo usehay theque usar el [http://wiki.qemu.org/Features/HelperNetworking|networkasistente helperde programred], whichque doesn'tno requirerequiere anyningún scriptsscript andy canpuede beautoidentificarse setuidcomo root.
 
ForPara olderversiones versionsanteriores, thelos twodos scripts aboveanteriores needse todeben beejecutar runcomo as the superusersuperusuario, sopara thatque theypuedan canmodificar modifylas theconfiguraciones networkde settingsred ofdel the systemsistema. TheLa mostmejor convenientmanera wayde toconseguirlo achievees thatpermitir isa tolos permitusuarios users ofde QEMU tollamar calla thelos scripts usingusando theel comando <code>sudo</code> command. ToPara setconfigurar thisesto, up,hay addque theañadir followinglo tosiguiente theal filefichero <code>/etc/sudoers</code>:
 
User_Alias QEMUERS = fred, john, milly, ...
Línea 133:
QEMUERS ALL=(ALL) NOPASSWD: QEMU
 
===StartingIniciar QEMU withcon aun TAPinterfaz interfaceTAP===
 
Now create a script to start QEMU with a VLAN, and clean up after itself when it exits. This one uses tap0. Specifying <code>script=no</code> tells QEMU to just use the tap device without calling the scripts - we do this so that QEMU can be run as a regular user, not root.
Línea 166:
* [http://blogtech.oc9.com/index.php?option=com_content&view=article&catid=44:linux&id=375:vmnets20130518&Itemid=6 Script to make virtual private networks without having to bridge your real network interface. Uses tap devices similar to here but doesn't touch your real network interfaces. Similar to vmnet1-vmnet7 in Vmware. Then, use iptables to configure your subnets like you would do with real physical private subnets on your LAN]
 
{{Auto categoryBookCat}}