I'm trying open a TUN device in a Linux (hopefully ultimately in a Java application). Since I don't want to use any native code (I want to avoid JNI if possible) I want to do as much as possible through the commandline. Here's what I'm trying to do:
- Create a TUN interface using
ip tuntap add dev tun0 mode tun
- Set it to up, and give it an IP address (simple enough with the
ip
command) - Open some kind of
/dev/tun0
file to write traffic from the network side.
The last step is where I'm a little confused - I gather this would work on Unix because network adapters are files, but I'm on Linux and I don't think I can access NICs that way. I understand this is simple with native code (make a few calls to ioctl
and get a file descriptor) but unless there's some way to do that from the commandline it won't work.
Is there any way I can open an already configured tun
interface (configured with ip tuntap
) with an open
call, and start writing network-side IP packets to it (without using ioctl
)?