{"id":471,"date":"2012-05-09T10:04:21","date_gmt":"2012-05-09T14:04:21","guid":{"rendered":"http:\/\/www.deadcodersociety.org\/?p=471"},"modified":"2012-05-06T16:45:45","modified_gmt":"2012-05-06T20:45:45","slug":"forwarding-a-range-of-ports-in-virtualbox","status":"publish","type":"post","link":"http:\/\/www.deadcodersociety.org\/blog\/forwarding-a-range-of-ports-in-virtualbox\/","title":{"rendered":"Forwarding a Range of Ports in VirtualBox"},"content":{"rendered":"<figure id=\"attachment_473\" aria-describedby=\"caption-attachment-473\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/Virtualbox_logo.png\"><img loading=\"lazy\" src=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/Virtualbox_logo-300x300.png\" alt=\"virtualbox_logo\" title=\"Virtualbox_logo\" width=\"300\" height=\"300\" class=\"size-medium wp-image-473\" srcset=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/Virtualbox_logo-300x300.png 300w, http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/Virtualbox_logo-150x150.png 150w, http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/Virtualbox_logo.png 512w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-473\" class=\"wp-caption-text\">Doesn&#039;t allow forwarding a range of ports through the UI<\/figcaption><\/figure>\n<p>I recently had to forward a range of ports to a VirtualBox instance. The VirtualBox GUI doesn&#8217;t provide a method for forwarding a range of ports. The <a title=\"http:\/\/www.virtualbox.org\/manual\/ch06.html\" href=\"http:\/\/www.virtualbox.org\/manual\/ch06.html\" target=\"_blank\">VirtualBox Manual<\/a>\u00a0describes a way for adding the rule via the command-line:<\/p>\n<pre>VBoxManage modifyvm \"VM name\" --natpf1 \"guestssh,tcp,,2222,,22\"<\/pre>\n<p>This forwards any traffic arriving on port 2222 to port 22 on the virtual instance. We can use this to create a short bash loop. In the example below, we&#8217;re forwarding ports 2300-2400 to ports 2300-2400 on the virtual instance (both TCP and UDP):<\/p>\n<pre>for i in {2300..2400}; do<\/pre>\n<pre>VBoxManage modifyvm \"windows\" --natpf1 \"tcp-port$i,tcp,,$i,,$i\";<\/pre>\n<pre>VBoxManage modifyvm \"windows\" --natpf1 \"udp-port$i,udp,,$i,,$i\";<\/pre>\n<pre>done<\/pre>\n<p>You can verify this by going back into the VirtualBox port forwarding page and seeing the newly configured ports. It&#8217;s just as easy to delete them:<\/p>\n<pre>for i in {2300..2400}; do<\/pre>\n<pre>VBoxManage modifyvm \"windows\" --natpf1 delete \"tcp-port$i\"; <\/pre>\n<pre>VBoxManage modifyvm \"windows\" --natpf1 delete \"udp-port$i\"; <\/pre>\n<pre>done<\/pre>\n<p>This should suffice until the capability is added to the VirtualBox UI.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Forward a range of ports in VirtualBox using a for-loop<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_links_to":"","_links_to_target":""},"categories":[4],"tags":[31,34,35,33],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/471"}],"collection":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/comments?post=471"}],"version-history":[{"count":13,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/471\/revisions"}],"predecessor-version":[{"id":486,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/471\/revisions\/486"}],"wp:attachment":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/categories?post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/tags?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}