unbuntu 加载tun模块

混江龙づ霸主 提交于 2020-02-07 21:37:43

1.查看自己系统内核版本

zc@zc-HP-ZHAN-99-Mobile-Workstation-G1:~$ uname -a

Linux zc-HP-ZHAN-99-Mobile-Workstation-G1 5.3.13 #1 SMP Fri Feb 7 15:01:04 CST 2020 x86_64 x86_64 x86_64 GNU/Linux

2.下载源码

查看linux可下载版本

zc@zc-HP-ZHAN-99-Mobile-Workstation-G1:~$ sudo apt-cache search linux-source

linux-source - Linux kernel source with Ubuntu patches
linux-source-4.15.0 - Linux kernel source for version 4.15.0 with Ubuntu patches
linux-source-4.18.0 - Linux kernel source for version 4.18.0 with Ubuntu patches
linux-source-5.0.0 - Linux kernel source for version 5.0.0 with Ubuntu patches
linux-source-5.3.0 - Linux kernel source for version 5.3.0 with Ubuntu patches
linux-source-3.13.0 - Linux kernel source for version 3.13.0 with Ubuntu patches

下载与内核相近的版本

zc@zc-HP-ZHAN-99-Mobile-Workstation-G1:~$ sudo apt-get install linux-source-xxx

进入下载后的目录

zc@zc-HP-ZHAN-99-Mobile-Workstation-G1:~$ cd /usr/src/linux-source-xxx
zc@zc-HP-ZHAN-99-Mobile-Workstation-G1: /usr/src/linux-source-5.3.0$ ls
debian debian.hwe linux-source-5.3.0.tar.bz2

解压文件

zc@zc-HP-ZHAN-99-Mobile-Workstation-G1: /usr/src/linux-source-5.3.0$ tar xvjf linux-source-5.3.0.tar.bz2

进入解压好的目录

zc@zc-HP-ZHAN-99-Mobile-Workstation-G1: /usr/src/linux-source-5.3.0$ cd linux-source-5.3.0/

3.配置选项并开始编译内核

zc@zc-HP-ZHAN-99-Mobile-Workstation-G1: /usr/src/linux-source-5.3.0/linux-source-5.3.0$sudo make menuconfig

找到Device Drivers -->,回车选择;
继续找到Network Device Support -->,回车选择;
找到Universal TUN/TAP device driver support,看到前面是<*>,键盘输入M,变成,退出并保存,回到终端。

sudo make -j8     #8表示8线程编译

编译中可能出现的错误

第一个错误是fatal error: openssl/opensslv.h: No such file or directory,
这是因为没有安装openssl的,需要先安装openssl:
sudo apt-get install libssl-dev
第二个错误是bc: not found,需要安装bc:
sudo apt-get install bc

编译可能花费较长时间。。。。

4.安装modules

sudo make modules_install

5.安装内核

sudo make install

6.重启并检验是否加载成功

zc@zc-HP-ZHAN-99-Mobile-Workstation-G1:$ modinfo tun

如果显示为下面结果,恭喜你成功了

filename: /lib/modules/5.3.13/kernel/drivers/net/tun.ko
alias: devname:net/tun
alias: char-major-10-200
license: GPL
author: © 1999-2004 Max Krasnyansky maxk@qualcomm.com
description: Universal TUN/TAP device driver
srcversion: 6F33DADD625CFF3A126D0D0
depends:
retpoline: Y
intree: Y
name: tun
vermagic: 5.3.13 SMP mod_unload
signat: PKCS#7
signer:
sig_key:
sig_hashalgo: md4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!