moneyslow.com

tinc ready before

拿到ubuntu22.04,先改造dns:

$ resolvectl status
Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub

Link 2 (eth0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 183.60.83.19
       DNS Servers: 183.60.83.19 183.60.82.98


root@VM-24-15-ubuntu:~# systemctl stop systemd-resolved
root@VM-24-15-ubuntu:~# systemctl disable systemd-resolved
Removed "/etc/systemd/system/dbus-org.freedesktop.resolve1.service".
Removed "/etc/systemd/system/sysinit.target.wants/systemd-resolved.service".
root@VM-24-15-ubuntu:~# resolvectl status
Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found.

root@VM-24-15-ubuntu:~# ll /etc/resolv.conf 
lrwxrwxrwx 1 root root 39 Apr 23  2024 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
删软连接:
root@VM-24-15-ubuntu:~# rm -f /etc/resolv.conf 
新建文件:
root@VM-24-15-ubuntu:~# cat /etc/resolv.conf 
#nameserver 127.0.0.53
nameserver 183.60.83.19
nameserver 183.60.82.98
options edns0 trust-ad
search .

验证解析路径,走的自定义的183.60.83.19 :

root@VM-24-15-ubuntu:~# nslookup google.com
Server:         183.60.83.19
Address:        183.60.83.19#53

Non-authoritative answer:
Name:   google.com
Address: 142.251.45.142

再改造网络配置,防止启动tinc就断网

1、记住网关:
root@VM-24-15-ubuntu:~# ip r | grep ^def
default via 10.0.24.1 dev eth0 proto dhcp src 10.0.24.15 metric 100 

2、加route2网关
root@VM-24-15-ubuntu:~# cat /etc/iproute2/rt_tables
#
# reserved values
#
255     local
254     main
253     default
0       unspec
#
# local
#
#1      inr.ruhep
100     100  #eth0

3、加配置:
# cat /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
network: {config: disabled}

4、,改网络配置,
原始文件:
root@VM-24-15-ubuntu:~# cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            match:
                macaddress: 52:54:00:c2:7b:34
            set-name: eth0


改为:

root@VM-24-15-ubuntu:~# cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            match:
                macaddress: 52:54:00:c2:7b:34
            set-name: eth0
            addresses:
                    - 10.0.24.15/22 # 私有IP/子网掩码
            routes:
                    - to: default
                      via: 10.0.24.1
            nameservers:
                    addresses:
                            - 183.60.83.19 #上面命令中查到的腾讯云dns
                            - 183.60.82.98 #上面命令中查到的腾讯云dns
            routes:
                    - to: 0.0.0.0/0 # 路由的目标地址。
                      via: 10.0.24.1 # 为通过路由的流量设置源 IP 地址。(网关)
                      table: 100 # eth0对应的路由表
            routing-policy:
                    - from: 10.0.24.15 # 主网卡私网ip,设置源 IP 地址以匹配此策略规则的流量。
                      table: 100 # 路由表编号
                      priority: 300 # 指定路由策略规则的优先级,以影响处理路由规则的顺序。
                                    # 数字越大,优先级越低:规则按优先级数字递增的顺序处理。



root@VM-24-15-ubuntu:~# netplan apply

** (generate:1964): WARNING **: 15:16:18.288: Permissions for /etc/netplan/50-cloud-init.yaml are too open. Netplan configuration should NOT be accessible by others.

减小权限:
root@VM-24-15-ubuntu:/etc/netplan# chmod 600 50-cloud-init.yaml 
再次:
root@VM-24-15-ubuntu:/etc/netplan# netplan apply

tips:
如果是阿里云轻量服务器,会报错:
WARNING:root:Cannot call Open vSwitch: ovsdb-server.service is not running
这个不用理会,但是重启服务器会断网,显示network is unreachable
禁用 cloud-init 防止覆盖你的配置,阿里云轻量云默认会强制用 DHCP,会覆盖你手动写的静态 IP,必须禁用:
touch /etc/cloud/cloud-init.disabled
再次重启服务器,应该会好。

Exit mobile version