前言
我在“碳云”购买了一台Lumen线路的移动快乐鸡,但价格实在太实惠,开机两天后就一直被D哥D,所以IPv4就使用不了。由于IPv6还是能够使用的,因此想在IPv6搭建科学上网。但搭建成功后还是无法连通,因此可能是由于DNS服务器使用的是IPv4地址,所以使用Netplan来更改DNS服务器为IPv6地址且删除VPS的IPv4地址和网关。
Netplan
The network configuration abstraction renderer
Netplan is a utility for easily configuring networking on a linux system. You simply create a YAML description of the required network interfaces and what each should be configured to do. From this description Netplan will generate all the necessary configuration for your chosen renderer tool.
Netplan配置流程
Netplan在Ubuntu中已经自带了,因此直接输入命令即可使用。
查看配置文件
1ls /etc/netplan
编辑配置文件(假设已在root权限下操作)
1nano /etc/netplan/*.yaml
下面是我的配置
1network:
2 ethernets:
3 eth0:
4 addresses:
5 - VPS IPv4地址
6 - VPS IPv6地址
7 gateway4: VPS IPv4网关
8 gateway6: VPS IPv6网关
9 nameservers:
10 addresses:
11 - **.**.**.** #VPS的IPv4 DNS服务器
12 - 1.1.1.1
13
14 version: 2
将配置文件中与IPv4有关的都添加#
注释来达到删除效果
1network:
2 ethernets:
3 eth0:
4 addresses:
5 # - VPS IPv4地址
6 - VPS IPv6地址
7 # gateway4: VPS IPv4网关
8 gateway6: VPS IPv6网关
9 nameservers:
10 addresses:
11 # - **.**.**.** #VPS的IPv4 DNS服务器
12 # - 1.1.1.1
13
14 version: 2
配置中IPv4的DNS服务器已经被删除了,那么我们就要添加一个IPv6的DNS服务,这里我使用Cloudflare的DNS服务器。
1network:
2 ethernets:
3 eth0:
4 addresses:
5 # - VPS IPv4地址
6 - VPS IPv6地址
7 # gateway4: VPS IPv4网关
8 gateway6: VPS IPv6网关
9 nameservers:
10 addresses:
11 # - **.**.**.** #VPS的IPv4 DNS服务器
12 # - 1.1.1.1
13 - 2606:4700:4700::1111 #Cloudflare的DNS服务器
14 version: 2
测试配置文件
1netplan try
应用配置文件
1netplan apply
这样利用Netplan修改网络配置就完成了,可以使用IP命令查看效果
1ip addr