Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1
1.1
UML networking
Basic plan
We are going to create small and medium sized networks to getting some practical experience with the lectured routing protocols. We need to create two scripts. One is called the host script and the other the guest script.
2
2.1
Host script
Creating more than one instance
The option ro will mount the lesystem as read-only, so I couldnt write to the lesystem. For writing you can use the rw command. I did not encounter any problems by running multiple instances. To make a directory writable I added the following to my rcS script,
if [ ! -z %{home} ]; then mount none /root/#{home} -t hostfs -o /home/joeri/uml_auto/#{home}; fi;
This will mount a unique directory for every instance and will be writable inside the read-only mounted UML. I tested this by writing a le inside the directory.
Guest script
In order to load the guest script at init I added the following line in the inittab:
::sysinit:/etc/init.d/rcS
Now I need to create a /var directory containing lock, log, run and tmp using ramfs. Also /tmp has to be a symlink to /var/tmp
mkdir mount mkdir mkdir mkdir mkdir ln -s /var -t ramfs -o size=20m ramfs /var /var/tmp /var/lock /var/log /var/run /var/tmp
3.0.1
The /var contains data that is changed when the system is running normally. lock Lock les. Many programs follow a convention to create a lock le in to indicate that they are using a particular device or le. Other programs will notice the lock le and wont attempt to use the device or le. log Log les from various programs, especially login and syslog. run Files that contain information about the system that is valid until the system is next booted. tmp Temporary les that are large or that need to exist for a longer time than what is allowed for /tmp. Source: (http://www.faqs.org/docs/linux_admin/x595.html)
To encounter the problem of a UML taking over the console, there are two simple options. Option one is the screen command and the second option is a separate xterm console.
4.1
Screen
I looked up how screen works and how it can be used for the UML instances. In fact this is pretty easy. The following command was used to start a UML instance in detached mode with screen.
screen -S UML1 -d -m linux.uml rootfstype=hostfs rootflags=/uml umid=uml1 ro -dm start screen in detached mode -S sessionname
To see the list of current screens you can enter screen -list. To attach your screen to your console you can type screen -r and your session name.
screen -r UML1
4.2
Xterm
To use xterm I have to use X-forwarding in ssh, which can be done with the -X option. To start a UML with xterm all I did was the following;
linux.uml rootfstype=hostfs rootflags=/uml umid=uml1 ro con=xterm &
I prefer to use the screen command, so from now on no more xterm for me because it will create to many consoles.
5
5.1
I added the following to my rcS script to pass IP information. If the IP argument is set it will set the IP address accordingly.
if [ ! -z #{IP0} ]; then echo ETH0 found /bin/ip addr add #IP0 dev eth0 /bin/ip link set eth0 up fi; if [ ! -z #{IP1} ]; then /bin/ip addr add #IP1 brd + dev eth1 /bin/ip link set eth1 up
fi; if [ ! -z #{IP2} ]; then /bin/ip addr add #IP2 brd + dev eth2 /bin/ip link set eth2 up fi; if [ ! -z #{IP3} ]; then /bin/ip addr add #IP3 brd + dev eth3 /bin/ip link set eth3 up fi;
5.2
Roles
Next I added roles like host, snier, bridge and router to the rcS script.
case #ROLE in host) echo host started; ;; sniffer) echo sniffer started; ;; bridge) echo "Bridge role started" ;; router) echo router started; route add default gw #outergw #routergwdevice echo "1" > /proc/sys/net/ipv4/ip_forward ;; *) echo no role assigned; ;; esac
More automation
The following script is using the start and stop function to create and destroy UML instances and switches. In the following script the X represent the number of the instance. I know this is not the most automated script you will nd but it does the job and Im have more control on errors.
#!/bin/bash case "#1" in start) start-stop-daemon --start --quiet --background --pidfile /home/joeri/uml_auto/witchumlXX.pid --make-pidfile \ --exec usr/bin/uml_switch -- -unix /home/joeri/uml_auto/switchumlXX.clt (-hub) screen -S UMLX -d -m linux.uml rootfstype=hostfs rootflags=/uml umid=umlX ethX=daemon,,unix, /home/uml/switchumlXX.clt ROLE=Bridge|Sniffer|Host & ;; stop) #To stop all instances without using the halt command for every instance by hand uml_mconsole umlX halt #stopping all the switches created start-stop-daemon --stop --quiet --pidfile /home/uml/switchumlXX.pid *) echo "Usage: #0 [start|stop]" ;; esac
case "%1" in start) #number of switches start-stop-daemon --start --quiet --background --pidfile /home/joeri/uml_auto/switchuml01.pid --make-pidfile \ --exec /usr/bin/uml_switch -- -unix /home/joeri/uml_auto/switchuml01.clt; #number of uml instances in this format screen -S UML1 -d -m linux.uml rootfstype=hostfs rootflags=/uml umid=uml1 \ eth0=daemon,,unix,/home/joeri/uml_auto/switchuml01.clt IP0=10.0.0.1/24 ROLE=Host con=xterm; screen -S UML2 -d -m linux.uml rootfstype=hostfs rootflags=/uml umid=uml2 \ eth0=daemon,,unix,/home/joeri/uml_auto/switchuml01.clt IP0=10.0.0.2/24 ROLE=Host con=xterm; ;; stop) #To stop all instances without using the halt command for every instance by hand uml_mconsole uml1 halt; uml_mconsole uml2 halt; #stopping all the switches created start-stop-daemon --stop --quiet --pidfile /home/joeri/uml_auto/switchuml01.pid; ;; status) screen -ls ;; *) echo "Usage: %0 [start|stop|status]"; ;; esa