Ubuntu
2025年9月5日大约 1 分钟
多网卡配置
注意
配置文件必须是 600 权限
哪个走外网,哪个就需要配置default
ens13f0 是内网, ens13f1 是对外访问
哪个网卡需要出外网 → 就在它上面配置 default via ...。
哪个网卡只用来和本地子网通讯 → 只配置 192.168.x.0/24 的路由,不要配置 default。
root@soft:/etc/netplan# more *
::::::::::::::
50-cloud-init.yaml
::::::::::::::
network:
version: 2
ethernets:
ens13f0:
dhcp4: no
addresses: [192.168.188.201/24]
nameservers:
addresses: [8.8.8.8]
::::::::::::::
xyw.yaml
::::::::::::::
network:
version: 2
ethernets:
ens13f1:
dhcp4: no
addresses: [192.168.252.241/24]
routes:
- to: default
via: 192.168.252.254
nameservers:
addresses: [192.168.250.250]
default 给ens13f1 两个网卡都能用, 给ens13f0 后ens13f1 就不能
激活网卡
ip link set 网卡名称 up
需要重新打开终端查看状态
ip route
查看网卡物理是否在线
sudo apt install ethtool
sudo ethtool [网卡名称]
看 Link detected: yes 或 no,no 就是物理链路问题
ip 配置
root@soft:/etc/netplan# more 50-cloud-init.yaml
network:
version: 2
ethernets:
ens13f0:
dhcp4: no
addresses: [192.168.188.201/24] # 这行定义了入站地址(别人如何找到我)
routes: # 这行定义了出站规则(我如何访问别人)
- to: default
via: 192.168.188.1
nameservers:
addresses: [8.8.8.8]
ens13f1:
dhcp4: no
addresses: [192.168.202.201/24]
nameservers:
addresses: [8.8.8.8]
检查
netplan try
启动
netplan apply
更换镜像
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
24.04
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-backports noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb-src
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-backports noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
ssh 升级
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.7p1.tar.gz