<sect1>
<title>Networking using DOSEMU</title>

<sect2>
<title>Direct NIC access</title>
<para>
The easiest (and not recommended) way to set up the networking
in DOSEMU is to use the direct NIC access. It means that DOSEMU
will exclusively use one of your network interfaces, say eth1.
No other processes will be able to use that interface. If they
try to, the data exchange will became unreliable. So you have
to make sure that this network interface is not used by anything
including the kernel itself, before starting DOSEMU.
The settings for this method are as follows:
<screen>
$_pktdriver = (on)
$_ethdev = "eth1"
$_vnet = "eth"
</screen>
Note that this method requires root privileges.
</para>
<para>
As you can see, this simple method has many shortcomings. If
you don't have the network card dedicated specially for dosemu,
consider using more advanced method called "Virtual Networking".
</para>
</sect2>

<sect2>
<title>Virtual networking</title>
<para>
Virtual networking is a mechanism that allows to overcome all the
limitations of the direct NIC access method, but it requires more
work to set up everything properly.
A special virtual network devices can be created using TUN/TAP interface.
This will enable multiple dosemu sessions and the linux kernel to be on
a separate virtual network. Each dosemu will have its own network device
and ethernet address.
</para>

<para>
First make sure that your Linux kernel comes with support for TUN/TAP;
for details check Documentation/networking/tuntap.txt
in the Linux kernel source. The user who runs DOSEMU should have 
read/write access to /dev/net/tun. Then either:

<orderedlist>
<listitem>
<para>
Set
<screen>
$_pktdriver=(on)
$_vnet = "tap"
$_tapdev = ""
</screen>
</para>
<para>
Start DOSEMU as usual and configure the network device while DOSEMU is
running (using ifconfig manually as root, a script, or usernetctl if
your distribution supplies that), e.g.
<screen>
ifconfig dosemu_tap0 up 192.168.74.1
</screen>
</para>
<para>
Configure the DOS TCP/IP network clients to have another IP address in the
subnet you just configured. This address should be unique, i.e. no other
dosemu, or the kernel, should have this address. For the example addresses
given above, 192.168.74.2-192.168.74.254 would be good. 
Your network should now be up and running and you can, for example,
use a DOS SSH client to ssh to your own machine, but it will
be down as soon as you exit DOSEMU.
</para>
</listitem>

<listitem>
<para>
Or set
<screen>
$_pktdriver=(on)
$_vnet = "tap"
$_tapdev = "tap0"
</screen>
</para>
<para>
Obtain tunctl from the user mode linux project. Then set up a persistent
TAP device using tunctl (use the -u owner option if you do that as root).
Configure the network using ifconfig as above, but now before starting
DOSEMU. Now start DOSEMU as often as you like and you can use the network
in the same way as you did above.
</para>
<para>
Note, however, that multiple DOSEMU sessions that run at the same time
need to use multiple tapxx devices. $_tapdev can be changed without
editing dosemu.conf or ~/.dosemu/.dosemurc (if you leave it commented out there)
by using dosemu -I "netdev tap1".
</para>
</listitem>
</orderedlist>
</para>

<para>
With the above you did set up a purely virtual internal network between
the DOSEMU and the real Linux box. This is why in the
above example 192.168.74.1 should *not* be a real IP address of the
Linux box, and the 192.168.74 network should not exist as a real
network. To enable DOS programs to talk to the outside world you have
to set up Ethernet bridging or IP routing.
</para>

<sect3>
<title>Bridging</title>
<para>
Bridging, using brctl (look for the bridge-utils package if you don't
have it), is somewhat easier to accomplish than the IP routing. 
You set up a bridge, for example named "br0" and connect eth0 and
tap0 to it. Suppose the Linux box has IP 192.168.1.10 on eth0, where
192.168.1.x can be a real LAN, and the uid of the user who is
going to use DOSEMU is 500, then you can do (as root):
<screen>
brctl addbr br0
ifconfig eth0 0.0.0.0 promisc up
brctl addif br0 eth0
ifconfig br0 192.168.1.10 netmask 255.255.255.0 up
tunctl -u 500
ifconfig tap0 0.0.0.0 promisc up
brctl addif br0 tap0
</screen>
Now the DOSEMU's IP can be set to (for example) 192.168.1.11.
It will appear in the same network your linux machine is.
</para>
</sect3>

<sect3>
<title>IP Routing</title>
<para>
If you like to use IP routing, note that unlike with bridging,
each DOSEMU box will reside in a separate IP subnet, which consists
only of 2 nodes: DOSEMU itself and the corresponding TAP device on
Linux side.
You have to choose an IP address for that subnet. If your LAN has the
address 192.168.1.0 and the netmask is 255.255.255.0, the dosemu subnet can
have the address 192.168.74.0 and tap0 can have the address 192.168.74.1:
<screen>
ifconfig tap0 192.168.74.1 netmask 255.255.255.0 up
</screen>
Choose a valid IP address from that subnet for DOSEMU box. It can be
192.168.74.2. Configure your DOS client to use that IP. Configure your
DOS client to use a gateway, which is the TAP device with IP 192.168.74.1.
Then you have to add the proper entry to the routing table on your Linux
box:
<screen>
route add -net 192.168.74.0 netmask 255.255.255.0 dev tap0
</screen>
The resulting entry in the routing table will look like this:
<screen>
Destination   Gateway  Genmask         Flags Metric Ref    Use Iface
192.168.74.0  *        255.255.255.0   U     0      0        0 tap0
</screen>

Then, unless the Linux box on which DOSEMU is running is a default
gateway for the rest of you LAN, you will have to also add an entry
to the routing table on each node of your LAN:
<screen>
route add -net 192.168.74.0 netmask 255.255.255.0 gw 192.168.1.10
</screen>
(192.168.1.10 is the IP of the box DOSEMU is running on).
Also you have to check whether IP forwarding is enabled, and if not -
enable it:
<screen>
echo 1 > /proc/sys/net/ipv4/ip_forward
</screen>
Now DOSEMU will be able to access any node of your LAN and vice versa.
Sometimes the forwarding is blocked by the firewall rules. In that
case try the following command (as root):
<screen>
iptables -t filter -I FORWARD 1 -i tap0 -j ACCEPT
</screen>
</para>

<para>
Yet one more thing have to be done if you want dosemu to be able to
access Internet. Unlike in your LAN, you are not supposed to change
the routing tables on an every Internet host, so how to make them
to direct the IP packets back to dosemu's virtual network? To
accomplish this, you only have to enable the IP Masquerading on
the network interface that looks into Internet. If your machine
serves as a gateway in a LAN, then the masquerading is most likely
already enabled, and no further work is required. Otherwise you
must run the following command
(assuming the eth0 interface serves the Internet connection):
<screen>
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
</screen>
Now you'll find your dosemu session being able to access Internet.
If you want these changes to be permanent, you can use iptables-save
script to save the changes to your iptables configuration file.
</para>
</sect3>
</sect2>

<sect2>
<title>VDE networking backend</title>
<para>
If you just need to have a working internet access from within your
DOSEMU environment, then you might want to consider using VDE networking.
slirpvde is a user mode networking utility providing a NAT-like
service, DHCP server, as well as a virtualized network in the 10.0.2.0/24
range, with a default gateway and a DNS server.
Note that dosemu uses VDE backend as a fallback when other methods are
unavailable. It also tries to start all the vde utilities, so no
configuration efforts are usually needed.
</para>
<para>
Use the following command to get VDE sources:
<screen>
svn checkout svn://svn.code.sf.net/p/vde/svn/trunk vde-svn
</screen>
You may also need to apply the following patches:
<ulink url=http://sourceforge.net/p/vde/bugs/70/attachment/flags.diff>
patch1
</ulink>
<ulink url=http://sourceforge.net/p/vde/bugs/71/attachment/atty.diff>
patch2
</ulink>
<ulink url=http://sourceforge.net/p/vde/bugs/_discuss/thread/dc88b292/4b26/attachment/msg.diff>
patch3
</ulink>
<ulink url=http://sourceforge.net/p/vde/bugs/73/attachment/0001-slirp-Forward-ICMP-echo-requests-via-unprivileged-so.patch>
patch4
</ulink>
</para>
<para>
VDE-specific config options:
<screen>
$_pktdriver=(on)
$_vnet = "vde"
$_vdeswitch = "/tmp/switch1
$_slirpargs = "--dhcp"
</screen>
</para>
<para>
Your wattcp.cfg file will look as simple as this:
<screen>
my_ip=dhcp
</screen>
</para>
</sect2>

</sect1>
