{"id":10366,"date":"2026-06-16T17:57:03","date_gmt":"2026-06-16T12:27:03","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=10366"},"modified":"2026-06-16T17:57:27","modified_gmt":"2026-06-16T12:27:27","slug":"fixing-the-dev-net-tun-error-in-an-openvz-container","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/fixing-the-dev-net-tun-error-in-an-openvz-container\/","title":{"rendered":"Fixing the \/dev\/net\/tun Error in an OpenVZ Container"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Introduction<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">While setting up Container1 inside an OpenVZ container, I encountered the following error:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ls: cannot access \/dev\/net\/tun: No such file or directory<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This occurs when the TUN\/TAP device is not enabled for the container. Since many networking applications rely on <code>\/dev\/net\/tun<\/code> to create virtual network interfaces, its absence can prevent services from starting correctly. This article explains the cause of the issue and the steps required to enable the TUN device and restore functionality.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Understanding the Problem<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In OpenVZ environments, containers do not automatically receive access to host devices. The TUN device must be explicitly enabled by the host node administrator. If it is not enabled, applications that depend on a TUN\/TAP interface will fail to start.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This issue can occur after:<br>Deployment of a new service requiring TUN\/TAP access<br>Container migrations<br>Host-level configuration changes<br>Node reboots<br>Container recreation<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Solution<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The fix must be applied on the OpenVZ host node, not inside the container.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enable TUN support using the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vzctl set &lt;CTID> --devnodes net\/tun:rw --save\nvzctl set &lt;CTID> --devices c:10:200:rw --save\nvzctl restart &lt;CTID><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <strong>&lt;CTID><\/strong> with your actual container ID.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What These Commands Do<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Enable the TUN Device Node<\/strong>: <code>vzctl set &lt;CTID> --devnodes net\/tun:rw --save<\/code> \u2014 This allows the container to access \/dev\/net\/tun with read and write permissions.<\/li>\n\n\n\n<li><strong>Allow the TUN Character Device<\/strong>: <code>vzctl set &lt;CTID> --devices c:10:200:rw --save<\/code> \u2014 This grants access to the Linux TUN\/TAP character device (major number 10, minor number 200).<\/li>\n\n\n\n<li><strong>Restart the Container<\/strong>: <code>vzctl restart <\/code>&lt;CTID>\u2014 A restart is required for the changes to take effect.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Verifying the Fix<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After the container restarts, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -l \/dev\/net\/tun<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>crw-rw-rw- 1 root root 10, 200 ... \/dev\/net\/tun<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also test the device using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/dev\/net\/tun<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The message &#8216;File descriptor in bad state&#8217; is normal and confirms that the TUN device is present and functioning correctly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Additional Host Verification<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If the problem persists, verify that the TUN kernel module is loaded on the host:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>lsmod | grep tun<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If no output is returned, load the module using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>modprobe tun<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then restart the container and test again.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>\/dev\/net\/tun: No such file or directory<\/code> error is a common issue in OpenVZ containers when TUN device access has not been enabled. Fortunately, the solution is straightforward once you know that the TUN device must be enabled at the host level.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By granting the required device permissions and restarting the container, <strong>Container1<\/strong> can successfully create tunnel interfaces and operate normally. Understanding how OpenVZ handles device access can help administrators quickly diagnose and resolve similar networking and container-related issues in the future.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction While setting up Container1 inside an OpenVZ container, I encountered the following error: ls: cannot access \/dev\/net\/tun: No such [&hellip;]<\/p>\n","protected":false},"author":532,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_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},"jetpack_post_was_ever_published":false},"categories":[1020],"tags":[],"class_list":["post-10366","post","type-post","status-publish","format-standard","hentry","category-containers-kubernetes","psol-cat-containers-kubernetes"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2Hc","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/10366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/532"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=10366"}],"version-history":[{"count":3,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/10366\/revisions"}],"predecessor-version":[{"id":10371,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/10366\/revisions\/10371"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=10366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=10366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=10366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}