多网卡配置:
metric 120
dns-nameservers 192.168.15.1 166.111.8.28 166.111.8.29 114.114.114.114 8.8.8.8
网关设置: ref: linux - How to configure systemd-resolved and systemd-networkd to use local DNS server for resolving local domains and remote DNS server for remote domains? - Unix & Linux Stack Exchange
We need to specify remote DNS server as our global, system-wide DNS server. We can do this in /etc/systemd/resolved.conf
file:
[Resolve]
DNS=8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844
Don't forget to reload configuration and to restart services:
$ sudo systemctl daemon-reload
$ sudo systemctl restart systemd-networkd
$ sudo systemctl restart systemd-resolved
ref: https://support.us.ovhcloud.com/hc/en-us/articles/360002296020-How-to-Configure-an-IPv6-Address-in-Ubuntu
一个例子:Ubuntu-1604
1. 修改 /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopbackauto eth0
iface eth0 inet dhcpnetmask 24gateway 192.168.15.1metric 99dns-nameservers 192.168.15.1 114.114.114.114iface eth0 inet6 autonetmask 64gateway6 2001:da8:bf:15::1metric 99dns-nameservers 2400:3200::1auto eth1
iface eth1 inet dhcp
netmask 255.255.255.0
metric 120auto eth2
iface eth2 inet static
address 12.12.12.106
netmask 255.255.255.0dns-nameservers 192.168.15.1 8.8.8.8 2400:3200::1
2. 修改DNS /etc/systemd/resolved.conf
[Resolve]
DNS=2400:3200::1 192.168.15.1 8.8.8.8
FallbackDNS=8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844
#Domains=
#LLMNR=yes
#DNSSEC=no
3. 重启网络
sudo /etc/init.d/networking restart
4. 重启DNS
sudo systemctl daemon-reload
sudo systemctl restart systemd-networkd
sudo systemctl restart systemd-resolved
5. 验证网络和dns
route -n # 网络
cat /etc/resolv.conf #查看dns
例子2: Ubuntu1804
ubuntu 1804以后,使用netplan代替了/etc/network/interface。以下是一个例子:
# /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this systemnetwork:version: 2renderer: networkdethernets:eth0:dhcp4: yesdhcp6: yesnameservers:addresses: [192.168.15.1, 8.8.8.8, '2400:3200::1']routes:- to: 0.0.0.0/0via: 192.168.15.1metric: 99on-link: true- to: "::/0"via: "2001:da8:bf:15::1"metric: 99on-link: trueeth1:dhcp4: yesdhcp4-overrides:route-metric: 120wan:match:macaddress: b8:59:9f:12:99:d0addresses:- 12.12.12.115/24dhcp4: nooptional: trueset-name: eth2
配置完成后,应用到网络上:
sudo netplan --debug try