We are, network engineers, have many *nix tools at our disposal: exaBGP, nmap, tcpdump, to name a few. And with UNetlab its very easy to run a linux system inside a topology (not to mention that you could use cloud
pnet interface to bridge unetlab topology with the real world). By default UNetLab’s linux template opts to VNC access, which is cool if you have a GUI, but for a networker – CLI is the only love. In this post I will share with you a method to get telnet access to a linux image inside the UNetLab.
All credits go to my colleague – Anatoliy Kolpakov.
Tuning your image
At first you have to add serial port to your linux image to use it later in a unetlab topology. We did it for ubuntu linux, but I believe that you can find specific guides for you distributive of choice.
To add a serial port to Ubuntu linux we have to perfom a couple of easy steps:
- Create a file called
/etc/init/ttyS0.conf containing the following:
1234567891011# ttyS0 - getty## This service maintains a getty on ttyS0 from the point the system is# started until it is shut down again.start on stopped rc RUNLEVEL=stop on runlevel [!12345]## if you do not need autologin, delete '--autologin root'respawnexec /sbin/getty --autologin root -L 115200 ttyS0 vt102
- Ask upstart to start the getty – sudo start ttyS0
- Now reboot and check that system starts normally
Full guide available on Ubuntu HowTo page.
Creating linux template
Now when you have a linux.qcow2 image equipped with serial port its time to create your own template for it, I covered the steps on this matter in details. The contents of the new template should be like these:
# vim: syntax=php tabstop=4 softtabstop=0 noexpandtab laststatus=1 ruler
* ALUnix template for UNetLab.
* UNetLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* UNetLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with UNetLab.If not, see <http://www.gnu.org/licenses/>.
* @author Roman Dodin <firstname.lastname@example.org>
* @copyright 2014-2015 Roman Dodin
* @license http://www.gnu.org/licenses/gpl.html
* @link http://noshut.ru
* @version 11112015
$p['type'] = 'qemu';
$p['name'] = 'Linux';
$p['icon'] = 'Server.png';
$p['cpu'] = 1;
$p['ram'] = 1024;
$p['ethernet'] = 2; ## set how many netw ifaces you want
$p['console'] = 'telnet'; ## set telnet as an access method
$p['qemu_arch'] = 'x86_64';
## copy this options. If smth goes wrong, delete -enable-kvm option
$p['qemu_options'] = '-enable-kvm -serial mon:stdio -nographic -nodefconfig -nodefaults -rtc base=utc -no-shutdown -boot order=c';
Now your are good to go to add linux image on a topology. Note that this time this linux image will try to connect via telnet (and should succeed).
Hope this will help you guys, use comments to ask questions if any.