Debian切换到netplan管理网络
source link: https://www.taterli.com/8514/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Debian切换到netplan管理网络
- 由 TaterLi
- 2022年1月2日2022年1月3日
先备份当前的网络配置(举例说明):
auto ens3
iface ens3 inet static
address 139.28.235.225
netmask 255.255.255.0
gateway 139.28.235.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 8.8.8.8
iface ens3 inet6 static
address 2402:d0c0:0002:0713:0000:0000:0000:0001
netmask 64
gateway 2402:d0c0:0002:0000:0000:0000:0000:0001
dns-nameservers 2606:4700:4700::1111
然后可以删除网络配置文件:
rm /etc/network/interfaces
启用SystemdNetworkd,但是不用启动.
systemctl enable systemd-networkd
安装netplan.io程序:
apt install netplan.io
配置netplan配置文件,这里要新建一个,比如/etc/netplan/00-default.yaml文件,内容如下(根据实际):
这里有值得注意的,V6的配置中,由于网关和IP不在一个网段,因为不能以gateway6方式声明.
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses:
- "139.28.235.225/24"
- "2402:d0c0:2:713::1/64"
gateway4: 139.28.235.1
nameservers:
addresses: [8.8.8.8,8.8.4.4,2001:4860:4860::8888,2001:4860:4860::8844]
routes:
- to: "::/0"
via: "2402:d0c0:2::1"
on-link: true
应用netplan配置:
netplan apply
这时候重启后便可发现SystemdNetworkd已配置:
systemctl status systemd-networkd
● systemd-networkd.service - Network Service
Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-01-01 23:33:46 CST; 7h ago
TriggeredBy: ● systemd-networkd.socket
Docs: man:systemd-networkd.service(8)
Main PID: 213 (systemd-network)
Status: "Processing requests..."
Tasks: 1 (limit: 529)
Memory: 3.9M
CPU: 27ms
CGroup: /system.slice/systemd-networkd.service
└─213 /lib/systemd/systemd-networkd
1月 01 23:33:46 debian systemd[1]: Starting Network Service...
1月 01 23:33:46 debian systemd-networkd[213]: Enumeration completed
1月 01 23:33:46 debian systemd[1]: Started Network Service.
1月 01 23:33:46 debian systemd-networkd[213]: ens3: Link UP
1月 01 23:33:46 debian systemd-networkd[213]: ens3: Gained carrier
1月 02 07:16:53 debian systemd-networkd[213]: ens3: Gained IPv6LL
个人感觉netplan配置起来更符合程序员使用习惯?而且netplan很强大,基本上兼顾了网络的一切,隧道和WG都能配置,具体还可以看Ubuntu写的例子:
SIT封装隧道例子:
服务器端(/64 Link Prefix + /64 Routed Prefix):
tunnels:
tun0:
mode: sit
remote: 139.28.235.225
local: 185.243.217.76
addresses:
- "2a03:94e0:214b:1000::1/64"
routes:
- to: 2a03:94e0:214b:2000::/64
scope: link
tunnels:
tun0:
mode: sit
remote: 185.243.217.76
local: 139.28.235.225
addresses:
- "2a03:94e0:214b:1000::2/64"
routes:
- to: "::/0"
via: "2a03:94e0:214b:1000::1"
指定出口:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses:
- "185.175.90.10/25"
- "2a10:4740:0040:0000:2222:1c04:f9c0:0001/112"
- "2a10:4740:0041:0000:0000:0000:0000:0001/128"
gateway4: 185.175.90.1
nameservers:
addresses:
- 8.8.8.8
- 1.1.1.1
- "2606:4700:4700::1111"
routes:
- to: "::/0"
via: "2a10:4740:0040:0000:0000:0000:0000:0001"
on-link: true
from: "2a10:4740:0040:0000:2222:1c04:f9c0:0001"
metric: 1
- to: "::/0"
via: "2a10:4740:0040:0000:0000:0000:0000:0001"
on-link: true
metric: 100
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK