转载:给debian的单网卡配置多IP时的提示信息

本文介绍了如何在Debian Linux上为单个网络接口分配多个IP地址,通过编辑/etc/network/interfaces文件,创建接口别名实现。在配置过程中,可能会遇到关于NFS挂载的警告,这实际上是由于系统在所有网络接口启动前等待NFS挂载导致的,可以通过禁用或修改相关脚本来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How to assign multiple IP’s in Debian Linux

Debian Linux command to get into network interface card

#vi /etc/network/interfaces

How to assign multiple IP addresses in debian linux:

You can assign multiple IP addresses to the same network interface by using interface alias. This is useful if you need to have more than one server visible on the internet. Note that for multiple Apache servers you can use virtual hosts to add as many servers as you like with one single IP address.Apache simply utilises the domain name supplied by the client in the http host header.

You must turn off dhcp because you must use static assignment if you are configuring multiple IPs, so basically this file is:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.90
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255

Assuming that you interface is eth0, you can assign three IP addresses editing /etc/network/interfaces similar to this:

# the loopback interface
auto lo
iface lo inet loopback

#
auto eth0
iface eth0 inet static
address 192.168.1.42
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1

auto eth0:0
iface eth0:0 inet static
address 192.168.1.41
netmask 255.255.255.0
broadcast 192.168.1.255

auto eth0:1
iface eth0:1 inet static
address 192.168.1.43
netmask 255.255.255.0
broadcast 192.168.1.255

auto eth0:2
iface eth0:2 inet static
address 192.168.1.44
netmask 255.255.255.0
broadcast 192.168.1.255

Note that gateway is only assigned to eth0. If you include dns-nameservers, it should also only be specified for eth0.

If you make changes to this file you can cause them to take effect by running:
/etc/init.d/networking restart

# /etc/init.d/networking restart
Reconfiguring network interfaces…if-up.d/mountnfs[eth0]: waiting for interface eth0:0 before doing NFS mounts (warning).
if-up.d/mountnfs[eth0]: waiting for interface eth0:1 before doing NFS mounts (warning).
if-up.d/mountnfs[eth0]: waiting for interface eth0:2 before doing NFS mounts (warning).
if-up.d/mountnfs[eth0:0]: waiting for interface eth0:1 before doing NFS mounts (warning).
if-up.d/mountnfs[eth0:0]: waiting for interface eth0:2 before doing NFS mounts (warning).
if-up.d/mountnfs[eth0:1]: waiting for interface eth0:2 before doing NFS mounts (warning).
done.

How to fix  if-up.d/mountnfs[eth0:1]: waiting for interface eth0:2 before doing NFS mounts (warning). ?

Reconfiguring network interfaces…if-up.d/mountnfs[eth0]: waiting for interface eth0:0 before doing NFS mounts (warning).
if-up.d/mountnfs[eth0]: waiting for interface eth0:1 before doing NFS mounts (warning).
if-up.d/mountnfs[eth0]: waiting for interface eth0:2 before doing NFS mounts (warning).
if-up.d/mountnfs[eth0:0]: waiting for interface eth0:1 before doing NFS mounts (warning).
if-up.d/mountnfs[eth0:0]: waiting for interface eth0:2 before doing NFS mounts (warning).
if-up.d/mountnfs[eth0:1]: waiting for interface eth0:2 before doing NFS mounts (warning).
done.

Solution:

It means that it is making sure that all ‘net interfaces are up before trying to mount a network based filesystem.

# chmod -x /etc/network/if-up.d/mountnfs

 

合理的解释:

I wouldn't worry too much. It appears to be a warning that can be ignored in the presence of multiple interfaces.

What is happening is that the primary eth0 interface is brought up (via ifup) due to its entry in /etc/network/interfaces. In response to that, scripts in /etc/network/if-up.d will run automatically. And one of those scripts is mountnfs to automatically mount any filesystems in /etc/fstab that are marked as nfs. You'll find the code that generates the warning in /etc/network/if-up.d/mountnfs.

I'm guessing at why the code was written this way, but since the script can't tell with certainty which (if you have multiple) of your network interfaces may be needed for the NFS mount to succeed, it checks all the "auto" interfaces in /etc/network/interfaces and if any aren't configured yet, it exits with the warning you saw. In your case, you have a second, eth0:0, alias interface, that holds your secondary address which isn't up yet - thus the warning.

But since the same script will then re-run on each subsequent interface coming up, when it gets to the final interface it proceeds to mount any network filesystems.

From the script on Debian (assuming Debian 5 - I don't have a Debian 4 image to check), it appears that the "am I the last interface to come up" check is done even before checking fstab so you can get this warning even if you don't have any nfs filesystems configured.

If the message annoys you, and you don't have any nfs mounts, you can always get rid of the mountnfs script in /etc/network/if-up.d, or chmod -x the script, which will cause it to be skipped.

### 配置Debian系统中的双网卡和双网关 在 Debian 系统中配置双网卡以及相应的两个网关涉及个方面,包括但不限于网络接口文件 `/etc/network/interfaces` 的编辑、路由表的管理等。 对于需要自定义虚拟网络接口的情况,在涉及到2个绑定的网卡应当确保其配置的一致性和正确性[^1]。当遇到ping不通网关的问题,可能通过简单的重启虚拟机来解决该bug;然而这并不是针对双网卡双网关配置的具体指导而是潜在问题的一个解决方案提示。 为了实现双网卡双网关的功能,通常的做法是在 `/etc/network/interfaces` 文件内分别定义每个物理网卡及其对应的静态IP地址和其他必要参数,并利用 `ip route add default via GATEWAY dev INTERFACE metric METRIC` 命令为每一个网卡添加不同的默认路由。这里需要注意的是,metric值决定了优先级,较低的数值表示较高的优先级。 另外,如果计划长期维持这种路径访问,则应该考虑创建额外的路由表并修改 `/etc/iproute2/rt_tables` 来支持更复杂的策略路由方案。这样可以更好地控制数据包离开哪个接口去往特定的目的地。 关于SSH服务端软件OpenSSH Server的安装可以通过命令行工具apt-get完成,即执行 `sudo apt install openssh-server` ,这对于远程管理和维护服务器非常重要[^2]。不过这部分内容与当前讨论的主题关系不大。 最后值得注意的是,虽然单破折号(-)和双破折号(--)均作为命令行选项标记存在,但在具体应用场合下二者有着区别对待的方式[^3]。此信息同样不直接影响到双网卡双网关的实际部署过程。 ```bash # 编辑 /etc/network/interfaces 文件样例 auto eth0 iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.1 auto eth1 iface eth1 inet static address 192.168.2.100 netmask 255.255.255.0 post-up ip route add default via 192.168.2.1 dev eth1 metric 2 || true ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值