{"id":733,"date":"2011-03-27T20:47:11","date_gmt":"2011-03-27T18:47:11","guid":{"rendered":"http:\/\/mcl.jogger.pl\/2011\/03\/27\/how-to-run-multiple-guest-os-in-qemu\/"},"modified":"2023-03-23T14:13:28","modified_gmt":"2023-03-23T13:13:28","slug":"how-to-run-multiple-guest-os-in-qemu","status":"publish","type":"post","link":"https:\/\/touk.pl\/blog\/2011\/03\/27\/how-to-run-multiple-guest-os-in-qemu\/","title":{"rendered":"How to run multiple guest OS in QEMU?"},"content":{"rendered":"<p>This weekend I&#8217;ve been fiddling with<\/p>\n<p><a href=\"http:\/\/www.qemu.org\">QEMU<\/a>. I&#8217;ve installed\u00a0<a href=\"http:\/\/openbsd.org\">OpenBSD<\/a>\u00a0on a single image and wanted to have two instances of it communicating via network. Installing the system was easy, but the networking setup was quite a pain. See how I did that&#8230; To make QEMU instances communicate with each other I needed to plug them to a &#8220;network&#8221;. That&#8217;s why I&#8217;ve created a bridge to which Virtual Instances would connect to. <\/p>\n<p>I&#8217;ve used the following script: <\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\r\n#!\/bin\/bash                                                                                                                                                 \r\n# 1st, release all DHCP address and remove all IP address associated\r\n# with the original eth0\r\n#\/sbin\/dhcpcd -k\r\nkill <code data-enlighter-language=\"raw\" class=\"EnlighterJSRAW\">pidof dhclient<\/code>\r\n\/sbin\/ip addr flush eth0\r\n# then take the interface down so we can rename it\r\n\/sbin\/ip link set eth0 down\r\n# now rename the original eth0 to reth0 (Real ETH0)\r\nnameif reth0 00:24:81:43:61:5b\r\n# OK, bring the same interface (with new name though) back up\r\n\/sbin\/ip link set reth0 up\r\n# 2nd let's create a bridge called eth0 so other programs think they are\r\n# talking to the same old interface (actually they will talk to the\r\n# bridge which is a clone of the original eth0 - with name MAC addr)\r\n\/usr\/sbin\/brctl addbr eth0\r\n# then add both origianl eth0 and tap1 device to the bridge\r\n\/sbin\/brctl addif eth0 tap1\r\n\/usr\/sbin\/brctl addif eth0 reth0\r\necho \"showing bridge mac addresses\"\r\n\/usr\/sbin\/brctl showmacs eth0\r\n# 3rd, we need to bring the newly created bridge UP\r\n\/sbin\/ip link set eth0 up\r\n# 4th, renew the DHCP address if possible\r\n#\/sbin\/dhcpcd -n\r\ndhclient eth0\r\n\/sbin\/ip addr show\r\n<\/pre>\n<p>Then I just needed to start Qemu with this command line:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\r\nsudo qemu openbsd-4.7.img  -net tap -net nic,macaddr=52:54:00:12:34:57,model=ne2k_pci\r\n<\/pre>\n<p>Since I&#8217;ve set up bridge for Qemu instances, I&#8217;ve plugged\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/TUN\/TAP\">TAP<\/a>\u00a0interfaces into it. That&#8217;s why I&#8217;ve needed to specify this in my qemu exec line. I&#8217;ve also added macaddress setting since both my instances were getting the same one. And that&#8217;s all! It works like a charm. Now on to some harder things!<\/p>\n","protected":false},"excerpt":{"rendered":"This weekend I&#8217;ve been fiddling with QEMU. I&#8217;ve installed\u00a0OpenBSD\u00a0on a single image and wanted to have two instances&hellip;\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[697,157],"_links":{"self":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/733"}],"collection":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/comments?post=733"}],"version-history":[{"count":8,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/733\/revisions"}],"predecessor-version":[{"id":9393,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/733\/revisions\/9393"}],"wp:attachment":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/media?parent=733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/categories?post=733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/tags?post=733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}