Warning: Parameter 1 to Language::getMagic() expected to be a reference, value given in /opt/local/apache2/htdocs/wiki/includes/StubObject.php on line 58
Tuntap - OSR

Tuntap

From OSR

Jump to: navigation, search

Contents

What is Tuntap*?

TUN/TAP provides packet reception and transmission for user space programs. It can be viewed as a simple Point-to-Point or Ethernet device, which instead of receiving packets from a physical media, receives them from user space program and instead of sending packets via physical media writes them to the user space program.

When a program opens /dev/net/tun, driver creates and registers corresponding net device tunX or tapX. After a program closed above devices, driver will automatically delete tunXX or tapXX device and all routes corresponding to it.


Setup the Linux kernel (host OS)

  • Make sure that the tuntap module and kernel module auto-loader is included in your kernel.
  • Add the following line to /etc/modprobe.conf
   alias char-major-10-200 tun
  • To automatically load the driver when the application accesses /dev/net/tun, run the following command:
   /sbin/depmod –a


Configure Bochs to use the tuntap interface

  • Make sure Bochs has ne2000 support. Check Bochs for more information.
  • Edit your .bochsrc configuration file and add the following line:
   ne2k: ioaddr=0x300, irq=9, mac=fe:fd:00:00:00:01, ethmod=tuntap, ethdev=/dev/net/tun,
   script=/path/to/tunconfig 

You will find instructions on howto create the tunconfig script in the next section.


Setup the private network between the host and the guest

  • I've setup a private network between the host and the guest with the following parameters. If your parameters are different, adapt the rest of the section to suit your needs.
   Host IP : 192.168.3.100
   Guest IP : 192.168.3.101
  • Create the /path/to/tunconfig script and make it executable:
   #!/bin/bash
   /sbin/ifconfig ${1##/*/} 192.168.3.100

The script gets the interface name as the first parameter. Linux will forward incoming packets between interfaces.

  • Run Bochs as root and install your guest OS.
  • Create and run the following script in your guest OS to start the network services:
#!/bin/sh

# net-up.sh: set up network access

DEVICE=eth0
IPADDR=192.168.3.101
NETMASK=255.255.255.0
NETWORK=192.168.3.0
GATEWAY=192.168.3.100

ifconfig $DEVICE $IPADDR netmask $NETMASK up
route add -net $NETWORK netmask $NETMASK $DEVICE
route add default gw $GATEWAY
  • You may have to disable your firewall and add the following line to /etc/hosts.allow in the host OS:
   ALL: 192.168.3.101
  • At this point, you should be able to ping/telnet/ftp/ssh the guest from the host and vice-versa.


Links

  1. Bochs official Website
  2. Bochs User Manual
  3. *tuntap.txt file in the Linux kernel tree