{"id":679,"date":"2016-12-12T11:52:57","date_gmt":"2016-12-12T10:52:57","guid":{"rendered":""},"modified":"2019-10-31T09:00:55","modified_gmt":"2019-10-31T08:00:55","slug":"unified-network-lab-unetlab-installing-linux-container-lxc","status":"publish","type":"post","link":"https:\/\/nil.uniza.sk\/en\/unified-network-lab-unetlab-installing-linux-container-lxc\/","title":{"rendered":"Unified Network Lab (UNetLab): Installing on Linux Container (LXC)"},"content":{"rendered":"<p style=\"margin-top: 0px; margin-bottom: 0px;\">\n\tThe UNetLab is a tool which integrates several toolkits (dynamips, qemu, IOL) into the one solution were we are able to run several network systems (routers, switches, sensors, PCs &#8230;). The list of supported imeages is here:&nbsp;<a href=\"http:\/\/www.unetlab.com\/documentation\/supported-images\/index.html\">http:\/\/www.unetlab.com\/documentation\/supported-images\/index.html<\/a>.&nbsp;<\/p>\n<p style=\"margin-top: 0px; margin-bottom: 0px;\">\n\tActually, Unetlab may be installed and run on several platforms (the list is here: &nbsp;<a href=\"http:\/\/www.unetlab.com\/documentation\/index.html#toc0\">http:\/\/www.unetlab.com\/documentation\/index.html#toc0<\/a>&nbsp;). However, actually I&#8217;m doing some experiments with LXC and I&#8217;m able to run UNL within a LXC environment too. This article describe the way how to do it.&nbsp;<\/p>\n<h2>\n\tPrerequisities and initial state<\/h2>\n<p style=\"margin-top: 0px; margin-bottom: 0px;\">\n\tI&#8217;m using following software versions and I&#8217;m in following intial state:<\/p>\n<ul>\n<li>\n\t\ta host machine with installed Linux Mint 18.0 Cinammon 64bit<\/li>\n<li>\n\t\tinstalled LXC container and a little knowledge about it.&nbsp;<\/li>\n<li>\n\t\tNetwork configuration is using bridged connectivity over a physical NIC card. This is the requirement of LXC containers, which will not use a NATed adapterd (lxcbr0), but an open LAN connectivity with directly accessible IP addres (private or public). My container therefore will use bridge0 adapter bridged over eth0 NIC.&nbsp;<\/li>\n<li>\n\t\tCisco\/JunOS images, as they are not included<\/li>\n<li>\n\t\tinternet connectivity<\/li>\n<\/ul>\n<h2>\n\tPreparing the LXC container<\/h2>\n<p>LXC, as <a href=\"https:\/\/en.wikipedia.org\/wiki\/LXC\">wiki says<\/a>, is:<\/p>\n<p>&nbsp;<\/p>\n<address>\n\tLXC (Linux Containers) is an operating-system-level virtualization method for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel.&nbsp;<\/address>\n<p>\t&nbsp;<\/p>\n<p>and will allow us to run UNL within virtual environment keeping the main host system simple and clear (as the virtualization do).<\/p>\n<p>In present days &nbsp;(December 2016), UNL supports the installation only on Ubuntu 14.04 x64. Any other linux distro and x86 are not supported. I&#8217;ve tried Ubuntu 16.10 and it really did not work.<\/p>\n<p>Therefore as the first step we need to create and install required LXC container. I&#8217;m usually using online LXC templates. So type&nbsp;<\/p>\n<pre>lxc-create -n unetlab -t download<\/pre>\n<p>here the command will create the LXC container (virtual machine?) named <strong><em>unetlab<\/em><\/strong> directly from the internet. Then you need to choose Distribution (type <strong>ubuntu<\/strong>), then Release (type <strong>trusty<\/strong>) and finally architecture (type amd64).<\/p>\n<p>Final output look like:<\/p>\n<pre>Using image from local cache\nUnpacking the rootfs\n---\nYou just created an Ubuntu container (release=trusty, arch=amd64, variant=default)\n\nTo enable sshd, run: apt-get install openssh-server\n\nFor security reason, container images ship without user accounts\nand without a root password.\n\nUse lxc-attach or chroot directly into the rootfs to set a root password\nor create user accounts.<\/pre>\n<p>and we may see that the container was created typing lxc-ls list cmd<\/p>\n<pre>PS ~ # <strong><span style=\"background-color:#ffff00;\">lxc-ls -f<\/span><\/strong>\nNAME        STATE   AUTOSTART GROUPS IPV4 IPV6 \nTestujemLXC STOPPED 0         -      -    -    \ntemp        STOPPED 0         -      -    -    \n<span style=\"background-color:#ffff00;\">unetlab<\/span>     STOPPED 0         -      -    -<\/pre>\n<p>&nbsp;<\/p>\n<p>Now go to \/var\/lib\/lxc (default home folder for all LXC containers) and typing <em>ls <\/em>you may see a folder with your LXC container:<\/p>\n<pre>S lxc # ls -al\ndrwx------  5 root root 4096 Dec 12 12:24 .\ndrwxr-xr-x 87 root root 4096 Nov 22 12:04 ..\n...\ndrwxrwx---  3 root root 4096 Dec  8 12:15 unetlab<\/pre>\n<div>\n\tNow we will assign an IP Address which will be used &nbsp;by our container, and under which the UNL will be accessible from the outside world. To do that we will modify the default config of our LXC container. Go to \/var\/lib\/lxc\/&lt;container_name&gt; and modify the config file (it has the same name &#8222;config&#8220;) which is placed there. In my case:<\/div>\n<pre>vim \/var\/lib\/lxc\/unetlab\/config<\/pre>\n<div>\n\t&nbsp;<\/div>\n<div>\n\tand add there the IP address and an IP address of the default gateway. I&#8217;m using private adress space:<\/div>\n<div>\n<pre># def. gw\nlxc.network.ipv4.gateway = 192.168.10.1\n# the ip address of the LXC container itself\nlxc.network.ipv4 = 192.168.10.111\/24<\/pre>\n<div>\n\t\t&nbsp;<\/div>\n<div>\n\t\tthan rename the name of bridged adapter from the default NATed adapter lxcbr0 to your bridged one (bridge0 in my case):<\/div>\n<pre>lxc.network.link = bridge0<\/pre>\n<div>\n\t\t&nbsp;<\/div>\n<div>\n\t\tthe overall config should look like:<\/div>\n<\/div>\n<div>\n<pre># Template used to create this container: \/usr\/share\/lxc\/templates\/lxc-download\n# Parameters passed to the template:\n# For additional config options, please look at lxc.container.conf(5)\n# Uncomment the following line to support nesting containers:\n#lxc.include = \/usr\/share\/lxc\/config\/nesting.conf\n\n# (Be aware this has security implications)\n\n# Distribution configuration\nlxc.include = \/usr\/share\/lxc\/config\/ubuntu.common.conf\nlxc.arch = x86_64\n\n# Container specific configuration\nlxc.rootfs = \/var\/lib\/lxc\/unetlab\/rootfs\nlxc.rootfs.backend = dir\nlxc.utsname = unetlab\n\n# Network configuration\nlxc.network.type = veth\nlxc.network.link = bridge0\nlxc.network.flags = up\nlxc.network.hwaddr = 00:16:3e:61:b1:24\nlxc.network.ipv4.gateway = 192.168.10.1\nlxc.network.ipv4 = 192.168.10.111\/24<\/pre>\n<div>\n<p>\t\t\tThis configuration will assign the static ip address, however, the containers&#8216; system also ask for the dynamic one. We should correct it by manually edditing the main LXC container network config file. There are more ways to do that. However, the main system of the container is after creating totally minimalistic, without any editor or installed packages. Therefore the simplest one is the option, where we will manually edit mentioned file directly from the main host system (mint linux in my case). So open&nbsp;<\/p>\n<\/div>\n<pre>vim \/var\/lib\/lxc\/<span style=\"background-color:#ffff00;\">unetlab<\/span>\/rootfs\/etc\/network\/interfaces<\/pre>\n<div>\n\t\twhere the first part of the path is the path to the root file system of the container:<\/div>\n<pre>\/var\/lib\/lxc\/unetlab\/rootfs\/<\/pre>\n<div>\n\t\tand the second part of the path lead to to the container&#8217;s network config file.<\/div>\n<pre>\/etc\/network\/interfaces<\/pre>\n<\/div>\n<p>Within the unetlab config just change from<\/p>\n<pre>iface eth0 inet dhcp<\/pre>\n<div>\n\tto<\/div>\n<pre>iface eth0 inet manual<\/pre>\n<p>Now we are able to start the container and access to it.&nbsp;<\/p>\n<p>Start the container:<\/p>\n<pre>lxc-start -n unetlab<\/pre>\n<p>where -n define the the name of the container used in this example.&nbsp;<\/p>\n<p>Now check if it run:<\/p>\n<pre>lxc-ls -f\nNAME        STATE   AUTOSTART GROUPS IPV4                           IPV6 \n...\nunetlab     <span style=\"background-color:#ffff00;\">RUNNING<\/span> 0         -      1<span style=\"background-color:#ffff00;\">92.168.10.111 <\/span>                -    \n...<\/pre>\n<p>we may see, that it is running and it has static, just assigned IP address. And we are able to ping it from the main system:<\/p>\n<pre>ping 192.168.10.111\n\nPING 192.168.10.111 (192.168.10.111) 56(84) bytes of data.\n64 bytes from 192.168.10.111: icmp_seq=1 ttl=64 time=0.076 ms\n64 bytes from 192.168.10.111: icmp_seq=2 ttl=64 time=0.033 ms\n...<\/pre>\n<h2>\n\t&nbsp;<\/h2>\n<h2>\n\tStarting work with the container<\/h2>\n<div>\n\tI need to mention again, that the container is totally clear without any usefull package installed. To correct it we may either install some packages directly from the host system typing:<\/div>\n<pre>lxc-attach -n unetlab -- apt-get install PACAKGE_NAME<\/pre>\n<div>\n\t&nbsp;<\/div>\n<div>\n\tWhere for example to install vim, mc, ssh, and screen may look like:<\/div>\n<pre>lxc-attach -n unetlab -- apt-get install openssh-server mc vim screen<\/pre>\n<div>\n\t&nbsp;<\/div>\n<div>\n\tOr we may attach containers&#8216; console directly using:<\/div>\n<div>\n<pre>lxc-attach -n unetlab<\/pre>\n<p>&nbsp;<\/p>\n<p>The command will attach the container console directly so we may see that the shell has changed, as we are in:<\/p>\n<pre>root@unetlab:\/# pwd\n\/<\/pre>\n<\/div>\n<p>Now we are able to directly type&nbsp;<\/p>\n<pre>apt-get install PACKAGE_NAME<\/pre>\n<p>&nbsp;<\/p>\n<h2>\n\tInstalling UNetLab<\/h2>\n<p>Now we will install the UNL software. The UNL has guides (<a href=\"http:\/\/www.unetlab.com\/documentation\/index.html\">http:\/\/www.unetlab.com\/documentation\/index.html<\/a>) for installing UNL on different platforms as for example virtualization technologies like Vmware Player\/Workstation\/ESX. But it also support the installation on physical server (baremetal HW). I follow this options. Ubuntu we already have prepared within our LXC container.<\/p>\n<p>To do that access into the container (lxc-attach -n NAME) and check first if we have connectivity:<\/p>\n<pre>root@unetlab:\/# ping 8.8.8.8\nPING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.\n64 bytes from 8.8.8.8: icmp_seq=1 ttl=57 time=10.9 ms\n64 bytes from 8.8.8.8: icmp_seq=2 ttl=57 time=10.7 ms\n^C<\/pre>\n<div>\n\tseems fine. We will need at least curl package, so install it:<\/div>\n<pre>apt-get install curl<\/pre>\n<div>\n\tthen we may run UNL install script:<\/div>\n<pre>curl -s http:\/\/www.unetlab.com\/install.sh | bash<\/pre>\n<p>wait till it finish.<\/p>\n<p>Now you just need to add some router images (tutorial for adding Cisco IOS <a href=\"http:\/\/www.unetlab.com\/2014\/11\/adding-dynamips-images\/#main\">http:\/\/www.unetlab.com\/2014\/11\/adding-dynamips-images\/#main <\/a>) and start creating topologies and learn networking!<\/p>\n<p>&nbsp;<\/p>\n<h2>\n\tKnown issues<\/h2>\n<p>After some testing with running Cisco and Juniper I&#8217;m able to run just Cisco dynamips images, Junos has problem to start :-(.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p style=\"margin-top: 0px; margin-bottom: 0px;\">\n\tThe UNetLab is a tool which integrates several toolkits (dynamips, qemu, IOL) into the one solution were we are able to run several network systems (routers, switches, sensors, PCs &#8230;). The list of supported imeages is here:&nbsp;<a href=\"http:\/\/www.unetlab.com\/documentation\/supported-images\/index.html\">http:\/\/www.unetlab.com\/documentation\/supported-images\/index.html<\/a>.&nbsp;<\/p>","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[685],"tags":[],"class_list":["post-679","post","type-post","status-publish","format-standard","hentry","category-linux_-_howto-en"],"taxonomy_info":{"category":[{"value":685,"label":"Linux - HOWTO"}]},"featured_image_src_large":false,"author_info":{"display_name":"admin","author_link":"https:\/\/nil.uniza.sk\/en\/author\/admin\/"},"comment_info":6,"category_info":[{"term_id":685,"name":"Linux - HOWTO","slug":"linux_-_howto-en","term_group":0,"term_taxonomy_id":683,"taxonomy":"category","description":"","parent":0,"count":71,"filter":"raw","cat_ID":685,"category_count":71,"category_description":"","cat_name":"Linux - HOWTO","category_nicename":"linux_-_howto-en","category_parent":0}],"tag_info":false,"_links":{"self":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/posts\/679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/comments?post=679"}],"version-history":[{"count":0,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/posts\/679\/revisions"}],"wp:attachment":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/media?parent=679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/categories?post=679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/tags?post=679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}