# /dev/tun jail cloning: tunX always increased



## walder (Jun 25, 2016)

Hello,

I can't find answer to the /dev/tun usage - situation:
- In the host I don't use /dev/tun
- In the jail I have (the only one I consider relevant) cloned_interfaces="tun"
- When I restart the jail the /dev/tunX gets increased, like X++
- It doesn't help even to clean up manually like `ifconfig tun19 destroy` and remove all the devs `rm /dev/tun*`: after jail restart, the tun20 is created :-o

This results in:
- Increasing /dev/tun* files; already after a few restarts, I have like 20 of them
- I can't configure stuff like openvpn correctly, as the `dev tunX` has to match to the /dev/tunX

I've spent a few days struggling with this and can't find out how FreeBSD (am running 10.3 under my jail, host is FreeNAS 9.10 - but it seems to be a FreeBSD general question, plus I didn't get any answers there) is managing the "tun" interface cloning (I guess it comes from cloning in the rc.conf, as no startup script is running talking to the /dev/tun AFAIK).

Thx a lot,
Andrej


----------



## tobik@ (Jun 25, 2016)

walder said:


> I can't configure stuff like openvpn correctly, as the  dev tunX has to match to the /dev/tunX


Let OpenVPN create a tun device for you. Just use dev tun instead of dev tunX and OpenVPN will create it itself (cloned_interfaces="tun" can be removed). It also destroys it on exit.


----------



## walder (Jun 25, 2016)

Exactly this did not work :-(.. When used like that, e.g. "tun" and not "tunX", the OpenVPN complains it can't ifconfig up "dev" - that's why I inserted "tunX" at the end, which works only until rebooting the jail.


----------



## walder (Jun 25, 2016)

Hey Tobik, you saved my mental health man :-D! I've tried it once again after I've rebootet the host: there are now only tun0 and tun1 under the host and tun0 under the jail, also after jail reboot. Thank you so much! Bye, Andrej


----------



## walder (Jun 25, 2016)

Tobik, sorry, one more problem with this: now the server part is working, but the client is not.

When I start the OpenVPN now I get this err log:

```
Sat Jun 25 17:58:01 2016 /sbin/ifconfig tun1 10.9.0.6 10.9.0.5 mtu 1500 netmask 255.255.255.255 up
ifconfig: interface tun1 does not exist
Sat Jun 25 17:58:01 2016 FreeBSD ifconfig failed: external program exited with error status: 1
Sat Jun 25 17:58:01 2016 Exiting due to fatal error
```

As there is only the tun0 (the server part is using it) and no tun1. I tried of course to put "tun1" into the client.config but that doesn't work either. I need to have both:
1. the server running for dialing-in and
2. the client sometimes connecting to another server out.

In the same jail. Do I have to create somehow manually the tun1 inside this jail?

Thank you so much,
Andrej


----------

