{"id":864,"date":"2011-03-31T15:28:49","date_gmt":"2011-03-31T09:58:49","guid":{"rendered":"http:\/\/judepereira.com\/blog\/?p=864"},"modified":"2011-03-31T15:28:49","modified_gmt":"2011-03-31T09:58:49","slug":"qemu-quick-networking-for-tcpudp","status":"publish","type":"post","link":"https:\/\/judepereira.com\/blog\/qemu-quick-networking-for-tcpudp\/","title":{"rendered":"QEMU | Quick Networking for TCP\/UDP"},"content":{"rendered":"<p>Networking with a guest in QEMU is often a headache, TUN\/TAP, seriously? Too hectic, let&#8217;s stick to the basics, TCP\/UDP based. Instead of setting up a really complex set of configuration files, wouldn&#8217;t it be easy to just emulate the network card, DHCP the guest, and let it work right out of the box?<\/p>\n<p>Well certainly yes. QEMU can do all this very easily.<\/p>\n<p>Cut the chase, hit the code:<br \/>\n[sourcecode lang=bash]<br \/>\n#!\/bin\/sh<br \/>\nqemu=&#8221;qemu-system-x86_64&#8243;<br \/>\ncpu_args=&#8221;-cpu qemu64 -smp 2&#8243;<br \/>\nmem_args=&#8221;-m 128M&#8221;<br \/>\ndrive=&#8221;-hda \/media\/fowlmanordisk1\/devel\/virtual\/red.tvway&#8221;<br \/>\nnet_args=&#8221;-net user -net nic,model=rtl8139&#8243;<br \/>\nredirs=&#8221;-redir tcp:8022::22&#8243;<br \/>\n${qemu} ${cpu_args} ${mem_args} ${drive} ${net_args} ${redirs} -nographic &#038;<br \/>\n[\/sourcecode]<br \/>\nis one of my virtual servers&#8217; running on Ubuntu server. Take a look at the network arguments:<br \/>\n-net user -net nic,model=rtl8139<br \/>\nPretty simple? The QEMU emulator runs an inbuilt DHCP server, if the guest recognises the network card, and requests the configuration from the DHCP server, it acquires the required IP address, and viola! Instant access to the outside world. The file \/etc\/resolv.conf still needs to be configured to your preferable DNS servers. OpenDNS is usually a good solution.<\/p>\n<p>Notice the -redir argument, it specifies that an issue to port 8022 on the outside be mapped to port 22 on the inside(guest). So basically you could <strong>ssh localhost -p 8022<\/strong> and get access to your guest machine.<\/p>\n<p>The -redir is as follows(from the QEMU manual pages):<\/p>\n<pre>\r\n-redir [tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport\r\n         Redirect incoming TCP or UDP connections to the host port\r\n         hostport to the guest IP address guestaddr on guest port\r\n         guestport. If guestaddr is not specified, its value is x.x.x.15\r\n         (default first address given by the built-in DHCP server). By\r\n         specifying hostaddr, the rule can be bound to a specific host\r\n         interface. If no connection type is set, TCP is used. This\r\n         option can be given multiple times.\r\n<\/pre>\n<p><em>Enjoy virtual machines with QEMU.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Networking with a guest in QEMU is often a headache, TUN\/TAP, seriously? Too hectic, let&#8217;s stick to the basics, TCP\/UDP based. Instead of setting up a really complex set of configuration files, wouldn&#8217;t it be easy to just emulate the network card, DHCP the guest, and let it work right out of the box? Well [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[52,10],"tags":[168,167,166,169,170],"class_list":["post-864","post","type-post","status-publish","format-standard","hentry","category-code","category-linux","tag-guest-host-network","tag-networking","tag-qemu","tag-qemu-dhcp","tag-qemu-map-ports"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pqtyx-dW","jetpack-related-posts":[{"id":903,"url":"https:\/\/judepereira.com\/blog\/usrlocalbinwaitpid\/","url_meta":{"origin":864,"position":0},"title":"\/usr\/local\/bin\/waitpid","author":"Jude Pereira","date":"April 26, 2011","format":false,"excerpt":"A quick script to wait for a certain pid, then once that quits, execute a command. You may ask, why not just do command1 && command2 ? Well, if command1 exits with a non-zero exit status value, command2 will not get executed. Hence, I've brewed a quick script for this\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1918,"url":"https:\/\/judepereira.com\/blog\/sending-ota-updates-over-wifi-to-your-esp8266\/","url_meta":{"origin":864,"position":1},"title":"Sending OTA updates over WiFi to your ESP8266","author":"Jude Pereira","date":"December 21, 2020","format":false,"excerpt":"This Christmas, I added a whole bunch of lights powered by 5V power sources. My goal was to switch them on at sunset, and switch them off on sunrise, by using a MOSFET for power control :) While I was doing this, I wanted to send OTA updates of my\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":694,"url":"https:\/\/judepereira.com\/blog\/visual-basic-6-revisited-linux-wine\/","url_meta":{"origin":864,"position":2},"title":"visual basic 6 revisited &#8211; linux &#8211; wine","author":"Jude Pereira","date":"August 5, 2010","format":false,"excerpt":"Earlier this year, I had written an article on running Visual Basic 6 on linux under wine, this is an update for it, the prior one is deprecated Getting Visual Basic 6 to work on linux is pretty easy, not much trouble, all the basic things work, as of what\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1830,"url":"https:\/\/judepereira.com\/blog\/ios-mac-ipsec\/","url_meta":{"origin":864,"position":3},"title":"How to tunnel all traffic from your iOS device to your own server via IPSec","author":"Jude Pereira","date":"May 11, 2018","format":false,"excerpt":"TL;DR: A DigitalOcean droplet, strongSwan, and a custom Configuration Profile for iOS routes all the traffic from my iPhone via my droplet. Why? Just because I can. Note: This setup does not require you to download Apple Configurator and switch your iPhone into Supervised mode (we will create a configuration\u2026","rel":"","context":"In &quot;gnu linux&quot;","block_context":{"text":"gnu linux","link":"https:\/\/judepereira.com\/blog\/category\/linux\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screen-Shot-2018-05-10-at-20.34.32-1024x134.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screen-Shot-2018-05-10-at-20.34.32-1024x134.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screen-Shot-2018-05-10-at-20.34.32-1024x134.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":893,"url":"https:\/\/judepereira.com\/blog\/coloured-varlogmessages-at-tty12\/","url_meta":{"origin":864,"position":4},"title":"Coloured \/var\/log\/messages at tty12","author":"Jude Pereira","date":"April 26, 2011","format":false,"excerpt":"Reading logs could never become any more easier, at just a keystroke, you have your logs displayed where you want, in some fancy colour. They look great too. TTY's can be accessed by pressing Alt + Ctrl + F[1 - 12] simultaneously. In the following, you'll get a decent, colourized\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1675,"url":"https:\/\/judepereira.com\/blog\/sending-notifications-via-apples-new-http2-api-using-jetty-9-3-6\/","url_meta":{"origin":864,"position":5},"title":"Sending notifications via Apple&#8217;s new HTTP\/2 API (using Jetty 9.3.6)","author":"Jude Pereira","date":"January 9, 2016","format":false,"excerpt":"HTTP\/2 is still very much new to Java, and as such, there are just two libraries who support it - Jetty (from 9.3), and Netty (in alpha). If you're going the Jetty way (as I have), you'll need to add their ALPN library to your boot classpath. Note: Jetty 9.3.x\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/comments?post=864"}],"version-history":[{"count":7,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/864\/revisions"}],"predecessor-version":[{"id":871,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/864\/revisions\/871"}],"wp:attachment":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/media?parent=864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/categories?post=864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/tags?post=864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}