LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 12-05-2019, 08:06 AM   #1
bionor
Member
 
Registered: Dec 2019
Posts: 44

Rep: Reputation: 1
How to create tun device for OpenVPN in (B)LFS 9.0 System V?


Hey guys

I've been trying for a while to get a working VPN in my LFS build. I've installed bridge-utils (although not sure if needed or how to use it), IProute2 and Openvpn. I've enabled the universal tun/tap driver in the kernel with (*) not (m) if that's relevant info.

I've read various info on the web and tried the following:
Code:
root@bioLinux[/home/bio]# mkdir /dev/net
root@bioLinux[/home/bio]# mknod /dev/net/tun c 10 200
root@bioLinux[/home/bio]# chmod 0666 /dev/net/tun
root@bioLinux[/home/bio]# modprobe tun
root@bioLinux[/home/bio]# openvpn --mktun --dev tun0
With the following result:

Code:
Thu Dec  5 14:55:23 2019 ERROR: Cannot open TUN/TAP dev /dev/net/tun: No such device (errno=19)
Thu Dec  5 14:55:23 2019 Exiting due to fatal error
Modinfo tun reveals driver is not loaded:
Code:
root@bioLinux[/home/bio]# modinfo tun
modinfo: ERROR: Module tun not found.
What is the proper procedure for creating a tun device for working VPN in LFS (SysV)?
 
Old 12-05-2019, 12:19 PM   #2
/dev/random
Member
 
Registered: Aug 2012
Location: Ontario, Canada
Distribution: Slackware 14.2, LFS-current, NetBSD 6.1.3, OpenIndiana
Posts: 319

Rep: Reputation: 112Reputation: 112
Quote:
Originally Posted by bionor View Post
Hey guys

I've been trying for a while to get a working VPN in my LFS build. I've installed bridge-utils (although not sure if needed or how to use it), IProute2 and Openvpn. I've enabled the universal tun/tap driver in the kernel with (*) not (m) if that's relevant info.

I've read various info on the web and tried the following:
Code:
root@bioLinux[/home/bio]# mkdir /dev/net
root@bioLinux[/home/bio]# mknod /dev/net/tun c 10 200
root@bioLinux[/home/bio]# chmod 0666 /dev/net/tun
root@bioLinux[/home/bio]# modprobe tun
root@bioLinux[/home/bio]# openvpn --mktun --dev tun0
With the following result:

Code:
Thu Dec  5 14:55:23 2019 ERROR: Cannot open TUN/TAP dev /dev/net/tun: No such device (errno=19)
Thu Dec  5 14:55:23 2019 Exiting due to fatal error
Modinfo tun reveals driver is not loaded:
Code:
root@bioLinux[/home/bio]# modinfo tun
modinfo: ERROR: Module tun not found.
What is the proper procedure for creating a tun device for working VPN in LFS (SysV)?
Code:
mkdir -p /dev/net
mknod /dev/net/tun c 10 200
chmod 666 /dev/net/tun

Add this udev rule to make it work when the tun is loaded.
Code:
KERNEL=="tun", NAME="net/%k",MODE:="666"

Last edited by /dev/random; 12-05-2019 at 12:27 PM. Reason: udev rule
 
Old 12-05-2019, 01:54 PM   #3
bionor
Member
 
Registered: Dec 2019
Posts: 44

Original Poster
Rep: Reputation: 1
Thanks. I tried adding the rule as you said to "/etc/udev/rules.d/70-persistent-net.rules" but it didn't seem to change much. Still get the same result. Should I try enabling the driver as a module instead of built in by the kernel?
 
Old 12-08-2019, 06:00 AM   #4
bionor
Member
 
Registered: Dec 2019
Posts: 44

Original Poster
Rep: Reputation: 1
I recompiled the kernel to use the tun driver as a module, which I guess makes much more sense as the driver won't actually load until there is something to load, and this seems to have worked. Running "modinfo tun" now after the other commands posted above reveals the driver is now running

However, when starting openvpn or adding the tun device with "ip tuntap add mode tun tun0" the console now freezes. It won't react to any commands such as ctrl-c or ctrl-z. I found out that doing this crashes network manager. Even restarting won't work and I have to use the power button.

At least now I'm closer to a solution, but I wonder why it crashes. I'll try and check /var/log/sys.log, but I'm not entirely sure what to look for and that file is huge by now.
 
Old 12-08-2019, 06:27 AM   #5
bionor
Member
 
Registered: Dec 2019
Posts: 44

Original Poster
Rep: Reputation: 1
I've accessed /var/log/sys.log and found this:
Code:
Dec  8 13:17:03 bioLinux kernel: [   72.913967] tun: Universal TUN/TAP device driver, 1.6
Dec  8 13:17:53 bioLinux kernel: [  122.355659] BUG: kernel NULL pointer dereference, address: 00000000000000e8
Dec  8 13:17:53 bioLinux kernel: [  122.355670] #PF: supervisor read access in kernel mode
Dec  8 13:17:53 bioLinux kernel: [  122.355674] #PF: error_code(0x0000) - not-present page
Dec  8 13:17:53 bioLinux kernel: [  122.355678] PGD 800000020fc89067 P4D 800000020fc89067 PUD 211a3b067 PMD 0 
Dec  8 13:17:53 bioLinux kernel: [  122.355688] Oops: 0000 [#1] SMP PTI
Dec  8 13:17:53 bioLinux kernel: [  122.355695] CPU: 0 PID: 1454 Comm: openvpn Not tainted 5.2.8 #3
Dec  8 13:17:53 bioLinux kernel: [  122.355699] Hardware name: FUJITSU LIFEBOOK P772/FJNB25B, BIOS Version 2.05 10/15/2012
Dec  8 13:17:53 bioLinux kernel: [  122.355712] RIP: 0010:cap_capable+0x13/0x70
Dec  8 13:17:53 bioLinux kernel: [  122.355718] Code: ff ff ff e8 3f e3 cf ff 4c 8b 24 24 41 bf f4 ff ff ff e9 19 ff ff ff 4c 8b 87 88 00 00 00 4c 39 c6 74 39 45 8b 88 e8 00 00 00 <44> 39 8e e8 00 00 00 7e 18 48 8b 86 e0 00 00 00 4c 39 c0 74 12 48
Dec  8 13:17:53 bioLinux kernel: [  122.355722] RSP: 0018:ffffa1d980e47d58 EFLAGS: 00010203
Dec  8 13:17:53 bioLinux kernel: [  122.355727] RAX: ffffffff8eb67890 RBX: 0000000000000000 RCX: 0000000000000000
Dec  8 13:17:53 bioLinux kernel: [  122.355731] RDX: 000000000000000c RSI: 0000000000000000 RDI: ffff9baec79ec840
Dec  8 13:17:53 bioLinux kernel: [  122.355734] RBP: ffffa1d980e47d88 R08: ffffffff90041120 R09: 0000000000000000
Dec  8 13:17:53 bioLinux kernel: [  122.355738] R10: ffffa1d980e47eb8 R11: ffffffff90334b60 R12: 000000000000000c
Dec  8 13:17:53 bioLinux kernel: [  122.355741] R13: 0000000000000000 R14: ffff9baec79ec840 R15: ffffffff900970e0
Dec  8 13:17:53 bioLinux kernel: [  122.355747] FS:  00007ff0680de740(0000) GS:ffff9baed6000000(0000) knlGS:0000000000000000
Dec  8 13:17:53 bioLinux kernel: [  122.355751] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
Dec  8 13:17:53 bioLinux kernel: [  122.355754] CR2: 00000000000000e8 CR3: 000000020bba2002 CR4: 00000000001606f0
Dec  8 13:17:53 bioLinux kernel: [  122.355758] Call Trace:
Dec  8 13:17:53 bioLinux kernel: [  122.355768]  ? security_capable+0x42/0x60
Dec  8 13:17:53 bioLinux kernel: [  122.355778]  ns_capable_common+0x2d/0x50
Dec  8 13:17:53 bioLinux kernel: [  122.355784]  ns_capable+0xb/0x10
Dec  8 13:17:53 bioLinux kernel: [  122.355794]  __tun_chr_ioctl+0x92d/0x1260 [tun]
Dec  8 13:17:53 bioLinux kernel: [  122.355803]  tun_chr_ioctl+0xe/0x10 [tun]
Dec  8 13:17:53 bioLinux kernel: [  122.355811]  do_vfs_ioctl+0x3eb/0x650
Dec  8 13:17:53 bioLinux kernel: [  122.355818]  ksys_ioctl+0x62/0x90
Dec  8 13:17:53 bioLinux kernel: [  122.355824]  __x64_sys_ioctl+0x15/0x20
Dec  8 13:17:53 bioLinux kernel: [  122.355831]  do_syscall_64+0x48/0x120
Dec  8 13:17:53 bioLinux kernel: [  122.355838]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
Dec  8 13:17:53 bioLinux kernel: [  122.355843] RIP: 0033:0x7ff0681f5357
Dec  8 13:17:53 bioLinux kernel: [  122.355848] Code: 00 00 90 48 8b 05 39 cb 0c 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 09 cb 0c 00 f7 d8 64 89 01 48
Dec  8 13:17:53 bioLinux kernel: [  122.355852] RSP: 002b:00007ffc21b1d7a8 EFLAGS: 00000202 ORIG_RAX: 0000000000000010
Dec  8 13:17:53 bioLinux kernel: [  122.355857] RAX: ffffffffffffffda RBX: 00000000019de8f0 RCX: 00007ff0681f5357
Dec  8 13:17:53 bioLinux kernel: [  122.355860] RDX: 00007ffc21b1d7b0 RSI: 00000000400454ca RDI: 0000000000000003
Dec  8 13:17:53 bioLinux kernel: [  122.355864] RBP: 0000000000000003 R08: 000000000000000b R09: 0000000000000000
Dec  8 13:17:53 bioLinux kernel: [  122.355867] R10: 00007ff0686c5e40 R11: 0000000000000202 R12: 00000000004888e0
Dec  8 13:17:53 bioLinux kernel: [  122.355870] R13: 00007ffc21b1f1d3 R14: 0000000000000000 R15: 0000000000000001
Dec  8 13:17:53 bioLinux kernel: [  122.355875] Modules linked in: tun x86_pkg_temp_thermal coretemp
Dec  8 13:17:53 bioLinux kernel: [  122.355883] CR2: 00000000000000e8
Dec  8 13:17:53 bioLinux kernel: [  122.355910] ---[ end trace 881cad720eb637f3 ]---
Dec  8 13:17:53 bioLinux kernel: [  122.355919] RIP: 0010:cap_capable+0x13/0x70
Dec  8 13:17:53 bioLinux kernel: [  122.355935] Code: ff ff ff e8 3f e3 cf ff 4c 8b 24 24 41 bf f4 ff ff ff e9 19 ff ff ff 4c 8b 87 88 00 00 00 4c 39 c6 74 39 45 8b 88 e8 00 00 00 <44> 39 8e e8 00 00 00 7e 18 48 8b 86 e0 00 00 00 4c 39 c0 74 12 48
Dec  8 13:17:53 bioLinux kernel: [  122.355950] RSP: 0018:ffffa1d980e47d58 EFLAGS: 00010203
Dec  8 13:17:53 bioLinux kernel: [  122.355968] RAX: ffffffff8eb67890 RBX: 0000000000000000 RCX: 0000000000000000
Dec  8 13:17:53 bioLinux kernel: [  122.355983] RDX: 000000000000000c RSI: 0000000000000000 RDI: ffff9baec79ec840
Dec  8 13:17:53 bioLinux kernel: [  122.355997] RBP: ffffa1d980e47d88 R08: ffffffff90041120 R09: 0000000000000000
Dec  8 13:17:53 bioLinux kernel: [  122.356009] R10: ffffa1d980e47eb8 R11: ffffffff90334b60 R12: 000000000000000c
Dec  8 13:17:53 bioLinux kernel: [  122.356023] R13: 0000000000000000 R14: ffff9baec79ec840 R15: ffffffff900970e0
Dec  8 13:17:53 bioLinux kernel: [  122.356036] FS:  00007ff0680de740(0000) GS:ffff9baed6000000(0000) knlGS:0000000000000000
Dec  8 13:17:53 bioLinux kernel: [  122.356051] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
Dec  8 13:17:53 bioLinux kernel: [  122.356065] CR2: 00000000000000e8 CR3: 000000020bba2002 CR4: 00000000001606f0
But I have no idea what to make of it
 
Old 12-09-2019, 12:46 PM   #6
bionor
Member
 
Registered: Dec 2019
Posts: 44

Original Poster
Rep: Reputation: 1
I tried removing the udev rule, but the kernel still panics when making the device. What could be causing this?
 
Old 12-19-2019, 08:50 AM   #7
bionor
Member
 
Registered: Dec 2019
Posts: 44

Original Poster
Rep: Reputation: 1
I've rebuilt my entire system most everything seems to work better now. The kernel no longer panicks when adding a tun device and openvpn actually seems to be able to create one by itself without me having to do it manually.

So good progress then, but, openvpn now gets stuck when trying to add routes. Some googling reveals many have had similar issues and I've tried some of the suggested fixes but no luck.

This is the output openvpn now gives:
Quote:
Thu Dec 19 15:37:35 2019 WARNING: --ping should normally be used with --ping-restart or --ping-exit
Thu Dec 19 15:37:35 2019 NOTE: --fast-io is disabled since we are not using UDP
Thu Dec 19 15:37:35 2019 Outgoing Control Channel Authentication: Using 512 bit message hash 'SHA512' for HMAC authentication
Thu Dec 19 15:37:35 2019 Incoming Control Channel Authentication: Using 512 bit message hash 'SHA512' for HMAC authentication
Thu Dec 19 15:37:35 2019 TCP/UDP: Preserving recently used remote address: [AF_INET]95.174.66.187:443
Thu Dec 19 15:37:35 2019 Socket Buffers: R=[131072->131072] S=[16384->16384]
Thu Dec 19 15:37:35 2019 Attempting to establish TCP connection with [AF_INET]95.174.66.187:443 [nonblock]
Thu Dec 19 15:37:36 2019 TCP connection established with [AF_INET]95.174.66.187:443
Thu Dec 19 15:37:36 2019 TCP_CLIENT link local: (not bound)
Thu Dec 19 15:37:36 2019 TCP_CLIENT link remote: [AF_INET]95.174.66.187:443
Thu Dec 19 15:37:36 2019 TLS: Initial packet from [AF_INET]95.174.66.187:443, sid=94991d5b fd9a8265
Thu Dec 19 15:37:36 2019 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this
Thu Dec 19 15:37:36 2019 VERIFY OK: depth=2, C=PA, O=NordVPN, CN=NordVPN Root CA
Thu Dec 19 15:37:36 2019 VERIFY OK: depth=1, C=PA, O=NordVPN, CN=NordVPN CA4
Thu Dec 19 15:37:36 2019 VERIFY KU OK
Thu Dec 19 15:37:36 2019 Validating certificate extended key usage
Thu Dec 19 15:37:36 2019 ++ Certificate has EKU (str) TLS Web Server Authentication, expects TLS Web Server Authentication
Thu Dec 19 15:37:36 2019 VERIFY EKU OK
Thu Dec 19 15:37:36 2019 VERIFY OK: depth=0, CN=no81.nordvpn.com
Thu Dec 19 15:37:36 2019 Control Channel: TLSv1.2, cipher TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384, 4096 bit RSA
Thu Dec 19 15:37:36 2019 [no81.nordvpn.com] Peer Connection Initiated with [AF_INET]95.174.66.187:443
Thu Dec 19 15:37:38 2019 SENT CONTROL [no81.nordvpn.com]: 'PUSH_REQUEST' (status=1)
Thu Dec 19 15:37:38 2019 PUSH: Received control message: 'PUSH_REPLY,redirect-gateway def1,dhcp-option DNS 103.86.96.100,dhcp-option DNS 103.86.99.100,sndbuf 524288,rcvbuf 524288,explicit-exit-notify,comp-lzo no,route-gateway 10.7.2.1,topology subnet,ping 60,ping-restart 180,ifconfig 10.7.2.6 255.255.255.0,peer-id 0,cipher AES-256-GCM'
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: timers and/or timeouts modified
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: --explicit-exit-notify can only be used with --proto udp
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: compression parms modified
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: --sndbuf/--rcvbuf options modified
Thu Dec 19 15:37:38 2019 Socket Buffers: R=[131072->425984] S=[87040->425984]
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: --ifconfig/up options modified
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: route options modified
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: route-related options modified
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: peer-id set
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: adjusting link_mtu to 1659
Thu Dec 19 15:37:38 2019 OPTIONS IMPORT: data channel crypto options modified
Thu Dec 19 15:37:38 2019 Data Channel: using negotiated cipher 'AES-256-GCM'
Thu Dec 19 15:37:38 2019 Outgoing Data Channel: Cipher 'AES-256-GCM' initialized with 256 bit key
Thu Dec 19 15:37:38 2019 Incoming Data Channel: Cipher 'AES-256-GCM' initialized with 256 bit key
Thu Dec 19 15:37:38 2019 ROUTE_GATEWAY 192.168.1.1/255.255.255.0 IFACE=wlan0 HWADDR=60:67:20:6a:22:66
Thu Dec 19 15:37:38 2019 TUN/TAP device tun1 opened
Thu Dec 19 15:37:38 2019 TUN/TAP TX queue length set to 100
Thu Dec 19 15:37:38 2019 /sbin/ifconfig tun1 10.7.2.6 netmask 255.255.255.0 mtu 1500 broadcast 10.7.2.255
Thu Dec 19 15:37:38 2019 /sbin/route add -net 95.174.66.187 netmask 255.255.255.255 gw 192.168.1.1
Thu Dec 19 15:37:38 2019 /sbin/route add -net 0.0.0.0 netmask 128.0.0.0 gw 10.7.2.1
SIOCADDRT: Network is unreachable
Thu Dec 19 15:37:38 2019 ERROR: Linux route add command failed: external program exited with error status: 7
Thu Dec 19 15:37:38 2019 /sbin/route add -net 128.0.0.0 netmask 128.0.0.0 gw 10.7.2.1
SIOCADDRT: Network is unreachable
Thu Dec 19 15:37:38 2019 ERROR: Linux route add command failed: external program exited with error status: 7
Thu Dec 19 15:37:38 2019 Initialization Sequence Completed
Edit:
I somehow managed to get it to work, problem is I was just experimenting and shooting in the dark, but what I (think I) did was to put the tun device up manually before running opevpn with this command:
Code:
ip link set dev tun0 up mtu 1500
Then I checked the routes which looked like this:
Code:
root [ /home/bio ]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    600    0        0 wlan0
10.7.3.0        *               255.255.255.0   U     0      0        0 tun1
95.174.66.187   192.168.1.1     255.255.255.255 UGH   0      0        0 wlan0
192.168.1.0     *               255.255.255.0   U     304    0        0 wlan0
192.168.1.0     *               255.255.255.0   U     600    0        0 wlan0
But my traffic still seemed to not through the vpn, which is probably obvious to someone who understands this by looking at the table.

I then manually ran the route commands which openvpn claims to have done (which it did without any without any errors):
Code:
route add -net 0.0.0.0 netmask 128.0.0.0 gw 10.7.3.1
route add -net 128.0.0.0 netmask 128.0.0.0 gw 10.7.3.1
Typing "route" now gave me this:
Code:
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.7.3.1        128.0.0.0       UG    0      0        0 tun1
default         192.168.1.1     0.0.0.0         UG    600    0        0 wlan0
10.7.3.0        *               255.255.255.0   U     0      0        0 tun1
95.174.66.187   192.168.1.1     255.255.255.255 UGH   0      0        0 wlan0
128.0.0.0       10.7.3.1        128.0.0.0       UG    0      0        0 tun1
192.168.1.0     *               255.255.255.0   U     304    0        0 wlan0
192.168.1.0     *               255.255.255.0   U     600    0        0 wlan0
At which point everything seems to work. Problem is although I'll probably manage to reproduce this with some fiddling, I need to understand exactly what's going on. I also did some "ifconfig tun0 up" which may or may not have contributed to this result, but it's all a bit chaotic at this point.

Last edited by bionor; 12-19-2019 at 09:32 AM.
 
Old 12-19-2019, 10:13 AM   #8
bionor
Member
 
Registered: Dec 2019
Posts: 44

Original Poster
Rep: Reputation: 1
Sorry for the spamming, but I sort of have a way of getting it to work now. First I start the openvpn client with
Quote:
openvpn --config <config file>
Which will open the connection to the server, but fail with the route commands. Then I type
Quote:
ifconfig tun1 up
[the two route commands that fails when openvpn tries itself]
This works, but it would be better if I understood why it fails when the openvpn software tries to do it itself and what the procedure should actually be. There also seems to be a tun0 device there already from boot, but which openvpn doesn't try to use, even when I pass the "--dev tun0" argument to it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error /dev/net/tun No such device - openvpn tonz18 Linux - Server 7 08-16-2015 02:02 PM
create TUN/TAP device with non default name vofka Linux - Networking 2 04-29-2010 03:11 AM
tun device for OpenVPN "disapears" after reboot Tux-Slack Slackware 1 06-16-2007 06:30 AM
vnuml tun device /dev/net/tun not found. asalford Linux - Networking 1 01-30-2007 10:11 PM
OpenAFS on an OpenVPN tun device Gsee *BSD 0 05-08-2006 05:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 07:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration