--
Windows 設定 DHCP 時,沒有 DHCP 服務時會自己產生一個 169.254.x.x 的 IP,Linux 遇到沒有 DHCP 服務除了開機不斷重試浪費時間之外,失敗後什麼 IP 都沒有,導致臨時要使用 IP 連線都沒有辦法。
Linux 該如何在使用 DHCP 卻沒有 DHCP 分配 IP 的情況還可以像 Windows 產生一組 IP ?
--
參考資源
- ZeroConfNetworking
- How can I get avahi-autoipd to get an address on an alias, regardless of the state of the interface?
Windows 使用的是 Zero-configuration networking (zeroconf) 技術, RFC3927 ,Apple Bonjour 也是相同的技術
--
安裝
1 |
# apt-get install avahi-autoipd |
Hoyo 在 DietPi 上測試時是裝 avahi-autoipd,網路上大多是教安裝 avahi-daemon,實際裝過不知道用途為何
avahi-autoipd 安裝完就完成了,預設設定有一些問題不過問題不大可以正常使用,Hoyo 是打算就這樣使用
--
實際使用
沒有 DHCP
1 2 3 4 5 6 7 8 9 10 11 12 13 |
root@DietPi:~# ifconfig eth0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether f6:10:e5:d0:32:3a txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 47 eth0:avahi: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 169.254.7.53 netmask 255.255.0.0 broadcast 169.254.255.255 ether f6:10:e5:d0:32:3a txqueuelen 1000 (Ethernet) device interrupt 47 |
接上網路線或是 DHCP 恢復後
1 2 3 4 5 6 7 8 |
root@DietPi:~# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether f6:10:e5:d0:32:3a txqueuelen 1000 (Ethernet) RX packets 16 bytes 1264 (1.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3 bytes 726 (726.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 47 |
eth0:avahi 網路會消失
--
設定檔
/etc/dhcp/dhclient-enter-hooks.d/avahi-autoipd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#!/bin/sh # This file is part of avahi. # # avahi is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # avahi is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public # License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with avahi; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA. case "$reason" in MEDIUM|ARPCHECK|ARPSEND|NBI) ;; PREINIT|BOUND|RENEW|REBIND|REBOOT|STOP|RELEASE) if [ -x /usr/sbin/avahi-autoipd ] && /usr/sbin/avahi-autoipd -c $interface; then /usr/sbin/avahi-autoipd -k $interface 2> /dev/null fi ;; EXPIRE|FAIL|TIMEOUT) # Starting avahi-autoipd is left for the exit hook ;; esac |
--
問題
登入時需要 Ctrl + C 中斷
--
974 total views, 1 views today