Debian

如何強制 Debian 等待 DHCP

  • October 12, 2012

我在虛擬機(VirtualBox)中執行 Debian 擠壓。本機有兩個介面:

  • eth0 處於“僅主機”模式,以便可以從外部訪問機器;和
  • eth1 處於“NAT”模式,以便機器可以訪問 Internet。

此外,我在主機上執行 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

然後刪除allow-hotplug eth0配置中的

因此它將等待網路配置完成。

引用自:https://unix.stackexchange.com/questions/50675