Professional Documents
Culture Documents
Network Qemu
Network Qemu
Network Qemu
QEMU supports network in user mode. You can browse the Internet and use ftp, ssh etc. without root
privilege or Administrative privilege.
When you use a program which connect from a Host OS to a Guest OS with option -redir, it needs to
have a root privilege or an Adrimistrative privilege.
•1. Option
•2. Network card
•3. NE2000 PCI card emulation
•3.1 Auto-configuration
•3.2 Example of Morphix
•3.3 DNS server's addresses
•4. Using VLAN
•4.1 Introduction
•4.2 Guest-only network
•4.3 Guest-only network by UDP
•4.4 One guest using user-mode net, listening socket at different VLAN bus and the
other connecting to the one
•4.5 One guest using user-mode net, listening socket in the same VLAN bus and the
other guest is connecting to the one
•4.6 TCP vs. UDP
•5. Network by option -M isapc
•5.1 Setting network configuration manually
•5.2 Setting network configuration automatically at startup
•6. File transfer by option -tftp
•7. Connection from Host OS to Guest OS by option -redir
•8. Notes
•9. When the network doesn't work
•10. Virtual network's internals
•11. Sharing files between Windows guest and Windows host
1. Option
-net option is used to set a network card and a input-output of data, so it is necessary to set more than
two -net options.
-net nic -net user
Default.
2. Network card
NE2000 PCI, RTL8139, PCNET and NE2000 ISA cards are available for the network card.
-net nic,model is used to set the model of the network card. ne2k_pci is a default.
-net nic,model=ne2k_pci -net user
-net nic,model=rtl8139 -net user
-net nic,model=pcnet -net user
When you want to use ISA card, it is necessary to set -M isapc option.
-M isapc -net nic -net user
-M isapc -net nic,model=nek2_isa -net user
It is necessary to set DNS server's addresses to a guest OS. When a guest OS is linux, set them in
/etc/resolve.conf
/etc/resolve.conf:
When a guest OS is Windows, set them in property of NE2000 in Network and Dial-up Connections.
4. Using VLAN
4.1 Introduction
From version 0.8.0, network options are changed. It is called VLAN. You can connect among guest
OSes.
-net option is used to set data input/output terminal. For NE2000, it is -net nic. If you want to use more
than two NE2000 or more than two guest OSes, it is necessary to set macaddr for each -net nic option
like -net nic,macaddr=52:54:00:12:34:56. The value of macaddr should be different for each NE2000.
For user mode network stack, -net user option is used. When you want to set one NE2000 for guest OS
and connect to the Internet, options are -net nic -net user. It is default.
When you want to use more than two guest OSes, you can use TCP or UDP. TCP can be used by -net
socket,listen and -net socket,connect options. UDP can be used by -net socket,mcast option. When -net
socket,listen and -net socket,connect options are used, output data from NE2000 of one guest OS are
encapsulated by TCP packet and sent to other OSes. When -net socket,mcast option is used, it is done
by UDP packet.
-net socket,listen or -net socket,mcast options need to have an administrative priviledge to use them.
I made three copies of Redhat hard disk image and start them at different command prompt. ne2k-pci
kernel module is loaded so that I can see network interface by ifconfig -a.
Redhat2
(qemu) info network
VLAN 0 devices:
socket: connect to 127.0.0.1:1234
ne2000 pci macaddr=52:54:00:12:34:57
Results:
ping works between two guests.
telnet, ssh work fine between them.
Note:
When you want to use more than three guest OSes, just connect to the one. Use different macaddr.
term3$ qemu -L ./pc-bios -hda redhat2.img -net nic,macaddr=52:54:00:12:34:58
-net socket,connect=localhost:1234
If Redhat1 crashes, you can not communicate between Redhat2 and Redhat3.
Redhat2
(qemu) info network
VLAN 0 devices:
socket: mcast=230.0.0.1:1234
ne2000 pci macaddr=52:54:00:12:34:57
Redhat3
(qemu) info network
VLAN 0 devices:
socket: mcast=230.0.0.1:1234
ne2000 pci macaddr=52:54:00:12:34:58
Results:
ping works between two guests.
telnet, ssh work fine between them.
4.4 One guest using user-mode net, listening socket at the different VLAN bus and
the other connecting to the one
VLAN 1
Redhat1 NE2000 --------------- USER -------------- Host & Internet
NE2000 ---------
| VLAN 2
|
Redhat2 NE2000
The second guest OS does not have DHCP server so that it is necessary to set IP address.
Redhat2 guest> ifconfig eth0 192.168.10.3
Redhat2 guest> route add default gw 192.168.10.2 eth0
Redhat2
VLAN 2 devices:
socket: connect to 127.0.0.1:1234
ne2000 pci macaddr=52:54:00:12:34:01
Results:
telnet and ssh works between guests.
lynx works on Redhat1.
It is necessary to set Redhat1 as a router to browse the Internet from Redat2.
Note:
VLAN ID is NOT necessary the same between guests. Port number (in this case 1234) determines
which bus is used.
4.5 One guest using user-mode net and listening socket in the same VLAN bus and
the other guest is connecting to the one
Redhat1 NE2000 -------------- USER --------- Host & Internet
|
|
Redhat2 NE2000
The second guest OS gets IP address from DHCP server but it is the same IP as the first OS's IP. It is
necessary to set it manually.
Redhat2 guest> ifconfig eth0 10.0.2.17
Redhat2 guest> route add default gw 10.0.2.2 eth0
Results:
telnet sometimes works but sometimes refuse to connect. When telnetd is working on connected guest,
it can be success.
When ssh is used, RSA key is saved at the first time but failed with this message.
Write failed: Connection reset by peer.
Notes:
This case does not work well.
It is not necessary to set Redhat1 as router to browse the Internet from Redhat2.
All packets except for 10.x.x.x and 127.x.x.x are sent to gateway 10.0.2.2 through eth0(NE2000).
NOTE: You can use modprobe and DHCP server instead of 3.1, 3.2 and 3.3.
[Red Hat 7.2]#/sbin/modprobe ne irq=9 io=0x300
[Red Hat 7.2]#/sbin/dhcpcd eth0
Please start Telnet service from controll panel. It needs to disable NTLM authentication.
Please stop it after you use it. It can be a security hole.
C:\>exit
Backspace is Ctrl-h.
Then you can use other programs.
5.2 Setting network configuration automatically at startup
10.0.2.16 is the IP address of the guest OS. 5555 is a port which is used to accept a connection on the
host OS and 23 is a port which is used in the guest OS. 23 is used by telnet server.
If you want to use telnet and ssh together, you can use some -redir options.
But don't set IP address of the guest OS manually in the guest OS.
You can see IP address gotten from DHCP server by winipcfg.exe in Windows 98/Me guest, ipconfig
/all in Windows 2000/XP guest and ifconfig in Linux guest. IP address is probably 10.0.2.15 or
10.0.2.16. It is necessary to set it at starting the program.
Routing table is like this when IP address is set by hand.
If you want set them by hand, you can set them like this.
You will see Login prompt from telnet server after a while.
There is a ftp client which can not set port. It takes time to connect to ftp server.
If it doesn't return elapsed time, please set IP address 10.0.2.16 manually and try ping. If it works,
NE2000 and it's driver is OK. A problem is to get IP address from DHCP server.
Plese set DNS server's addresses from the Internet Service Provider manulally.
If it desn't work, it might be a problem of the driver. please try to use -isa option to start the QEMU.
If you can use tcpdump as root on a host OS, you can check it.
[host OS]# tcpdump -i eth0
or
[host OS]# tcpdump -i eth1 (if you have two cards)
or when you use a host-gest connection,
[host OS]# tcpdump -i lo
ICMP ping is converted UDP packet and sent to port 82 (XFER UTILITY) of the host OS. Linux
doesn't respond to it but Windows does only when it is the host OS. The program ping can't be used to
the Internet because a remote host usually doesn't respond to it.
It is made in c:\tmp\slirp.log.
When a connection is made, there are soread and sbappend in it. Data are received by soread and send
by sbappend.
struct socket in socket.h has data of a socket descriptor and socket state (so_state) etc. It holds state of
connection.
For UDP/IP, it is easier. It probably works if TCP/IP works. It changes functions depending on TCP or
UDP.
When -redir option is used, functions solisten and udp_listen are used to act as a server.
2. On guest OS, right click on my network in Explore, select allocationg network drive.
Input a drive name like E: and a folder name of sharing folder in host OS like \\10.0.2.2\tmp , "tmp" is
the name you set in host OS. then shared folder is shared as drive E:.
home