我的 Debian 9 机器上有三个接口。我需要为整个系统永久设置默认路由。我尝试以不同的方式将其添加到 /etc/network/interfaces 文件中,但似乎找不到正确的选项。我已将下行路线放在接口部分以及文件底部,但似乎没有一个对我有用。正确的语法是什么?所有路由应从 ens256 发出,所有本地路由应从其他接口发出。
# The primary network interface
allow-hotplug ens192
iface ens192 inet static
address 10.21.30.10
netmask 255.255.255.0
gateway 10.21.30.254
down route del default gw 10.21.30.254
allow-hotplug ens224
iface ens224 inet static
address 10.21.10.10
netmask 255.255.255.0
gateway 10.21.10.254
down route del default gw 10.21.10.254
allow-hotplug ens256
iface ens256 inet static
address 1.2.3.157
netmask 255.255.255.248
gateway 1.2.3.153
dns-nameservers 4.2.2.2 8.8.8.8
up route add default gw 1.2.3.153
如果我将帖子配置放在文件末尾。 “post-up /bin/ip 路由通过 1.2.3.153 dev ens256 添加默认值”这有效,我能够 ping 通互联网,但似乎无法运行 apt-get。当我运行这个时,我收到以下错误。
Ign:1 http://security.debian.org/debian-security stretch/updates InRelease
Err:2 http://security.debian.org/debian-security stretch/updates Release
Connection failed [IP: 199.232.32.204 80]
Ign:3 http://ftp.us.debian.org/debian stretch InRelease
Ign:4 http://ftp.us.debian.org/debian stretch-updates InRelease
Err:5 http://ftp.us.debian.org/debian stretch Release
Connection failed [IP: 208.80.154.15 80]
Err:6 http://ftp.us.debian.org/debian stretch-updates Release
Connection failed [IP: 64.50.233.100 80]
Reading package lists... Done
E: The repository 'http://security.debian.org/debian-security stretch/updates Release' does no longer have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://ftp.us.debian.org/debian stretch Release' does no longer have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://ftp.us.debian.org/debian stretch-updates Release' does no longer have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
答案1
我相信你一定只有一根网关线。
答案2
我有类似的东西这里
allow-hotplug ens192
iface ens192 inet static
address 10.21.30.10/24
gateway 10.21.30.254
down /bin/ip route del default via 10.21.30.254
allow-hotplug ens224
iface ens224 inet static
address 10.21.10.10/24
gateway 10.21.10.254
down /bin/ip route del default via 10.21.10.254
allow-hotplug ens256
iface ens256 inet static
address 1.2.3.157/29
up /bin/ip route add default via 1.2.3.153 dev ens256
在up
orpost-up
指令之后,您实际上可以添加任何您喜欢的命令。在这种情况下,我使用了/bin/ip route
。
您的问题主要是关于该方法的语法static
。这是什么man interfaces
不得不说一下可用的东西:
IFACE OPTIONS
The following "command" options are available for every family and
method. Each of these options can be given multiple times in a single
stanza, in which case the commands are executed in the order in which
they appear in the stanza. (You can ensure a command never fails by
suffixing them with "|| true".)
pre-up command
Run command before bringing the interface up. If this command
fails then ifup aborts, refraining from marking the interface as
config‐ured, prints an error message, and exits with status 0. This
behavior may change in the future.
up command
post-up command
Run command after bringing the interface up. If this command fails
then ifup aborts, refraining from marking the interface as configured
(even though it has really been configured), prints an error message,
and exits with status 0. This behavior may change in the future.
down command
pre-down command
Run command before taking the interface down. If this command fails
then ifdown aborts, marks the interface as deconfigured (even though
it has not really been deconfigured), and exits with status 0. This
behavior may change in the future.
post-down command
Run command after taking the interface down. If this command fails
then ifdown aborts, marks the interface as deconfigured, and exits
with status 0. This behavior may change in the future.
description name
Alias interface by name
The static Method
This method may be used to define Ethernet interfaces with statically
allocated IPv4 addresses.
Options
address address
Address (dotted quad/netmask) required
netmask mask
Netmask (dotted quad or number of bits) deprecated
broadcast broadcast_address
Broadcast address (dotted quad, + or -) deprecated.
Default value: "+"
metric metric
Routing metric for default gateway (integer)
gateway address
Default gateway (dotted quad)
pointopoint address
Address of other end point (dotted quad). Note the spelling
of "point-to".
hwaddress address
Link local address or "random".
mtu size
MTU size
scope Address validity scope. Possible values: global, link, host
您可能会注意到这route
不是一个选项。为此,您需要使用/bin/ip route
or 。gateway
另外,dns-nameservers
也不是一个选择。你需要使用解析配置文件为此(或者可能是网络管理员,如果覆盖它的话)。