本文作者:chenzj

Debian 13 永久路由配置指南

chenzj 2025-12-10 9707
Debian 13 永久路由配置指南摘要: NTP服务安装apt-get install ntpsystemctl start ntp...

Debian 13 永久路由配置指南


NTP服务安装

apt-get install ntp

systemctl start ntp

配置文件在/etc/ntpsec/ntp.conf


双网卡IP配置

修改 /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug enp103s0f0np0        //enp103s0f0np0网卡名
iface enp103s0f0np0 inet static
address 10.0.0.80/24
gateway 10.0.0.254
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 114.114.114.114

allow-hotplug enp103s0f3np3        //enp103s0f3np3网卡名
iface enp103s0f3np3 inet static
address 172.16.28.110/24
gateway 10.0.0.254


systemctl restart networking             //重启网络服务



ip route add 172.0.0.0/8 via 172.16.28.126    //临时添加内网路由

Debian 13 永久路由配置指南


在 Debian 13 中,添加永久路由主要有两种方式:使用 Netplan (推荐) 和 传统 Interfaces 文件。请根据你的网络管理工具选择对应的方法。

🛠️ 方案一:Netplan (推荐)

适用于大多数现代 Debian 13 安装,配置更灵活,支持多网关和策略路由。

📜 方案二:/etc/network/interfaces

适用于旧版配置或特定环境(如某些容器/虚拟机),语法较为传统。

1. 方案一:Netplan (Debian 13 默认)

这是最标准的做法。你需要编辑 /etc/netplan/ 目录下的 .yaml 配置文件。

1
定位配置文件
通常位于 /etc/netplan/01-netcfg.yaml 或类似的数字命名文件中。
2
修改配置
找到对应网卡(例如 eth0)的配置块,在 addresses 下添加 routes 字段。
yaml
Copy
network:
 version: 2
 renderer: networkd
 ethernets:
   eth0:
     addresses:
       - 192.168.1.100/24
     routes:
       - to: 192.168.2.0/24
         via: 192.168.1.254
注意:YAML 文件对缩进非常敏感,routes 必须与 addresses 同级且缩进一致。
3
应用更改
保存后运行以下命令使配置生效:
bash
Copy
sudo netplan apply

2. 方案二:/etc/network/interfaces (传统)

如果你的系统依然使用 ifupdown 工具链(部分老旧镜像或特定定制),请使用此方法

1
编辑文件
打开 /etc/network/interfaces 文件。
bash
Copy
auto eth0
iface eth0 inet static
   address 192.168.1.100
   netmask 255.255.255.0
   gateway 192.168.1.1
# 添加永久路由
   up ip route add 192.168.2.0/24 via 192.168.1.254
2
重启服务
保存文件并重启网络服务以应用新路由:
bash
Copy
sudo systemctl restart networking


文章版权及转载声明

作者:chenzj本文地址:https://www.kjjs.net/196.html发布于 2025-12-10
文章转载或复制请以超链接形式并注明出处KJ技术

阅读
分享