如何强制 Debian 等待 DHCP

如何强制 Debian 等待 DHCP

我在虚拟机(VirtualBox)中运行 Debian squeeze。本机有两个接口:

  • eth0 处于“仅主机”模式,以便可以从外部访问机器;和
  • eth1处于“NAT”模式,这样机器就可以访问互联网了。

此外,我在主机上运行 dnsmasq 来为虚拟机分配静态 IP 地址(VirtualBox 为 NAT 提供 IP 地址)。

虚拟机运行sshd和mysql。启动时,有时两个服务都无法启动:

sshd[1145]: Set /proc/self/oom_adj from 0 to -17
sshd[1145]: Server listening on 0.0.0.0 port 22.
sshd[1145]: Server listening on :: port 22.
sshd[1145]: Received signal 15; terminating.
sshd[1299]: Set /proc/self/oom_adj from -17 to -17
sshd[1299]: Server listening on 0.0.0.0 port 22.
sshd[1299]: Server listening on :: port 22.
sshd[1301]: Set /proc/self/oom_adj from -17 to -17
sshd[1301]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use.
sshd[1301]: error: Bind to port 22 on :: failed: Address already in use.
sshd[1301]: fatal: Cannot bind any address.

和:

mysqld: 121012 10:36:24 [ERROR] Can't start server: Bind on TCP/IP port: Cannot assign requested address
mysqld: 121012 10:36:24 [ERROR] Do you already have another mysqld server running on port: 3306 ?
mysqld: 121012 10:36:24 [ERROR] Aborting

我观察到每次服务失败时,eth0 上的 DHCPDISCOVER 都会出现失败。当服务启动成功后,会出现DHCPDISCOVER

我假设 Debian 不会等待两个接口都收到 IP 地址。有没有办法强制 Debian 在两个接口上等待 DHCP?

根据用户请求更新warl0ck

文件内容/etc/network/interfaces

  # The loopback network interface
  auto lo
  iface lo inet loopback

  # The primary network interface
  allow-hotplug eth0
  iface eth0 inet dhcp
    # routing for VPN
    post-up route add -net x.x.20.0 netmask 255.255.255.0 gw x.x.10.1
    pre-down route del -net x.x.20.0 netmask 255.255.255.0 gw x.x.10.1


  # 2nd interface for NAT
  allow-hotplug eth1
  iface eth1 inet dhcp

答案1

allow-hotplug eth0然后删除您的配置中的

因此它将等待网络配置完成。

相关内容