在我的網關伺服器上的 Ubuntu 18.04 上,我已經安裝並設定了 isc-dhcp-server,但如果重新啟動後沒有任何內容連接到 enp2s0,它就不會啟動(即無法啟動)。
注意它說“未配置為偵聽任何介面!」
$ service isc-dhcp-server status
● isc-dhcp-server.service - ISC DHCP IPv4 server
Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2020-01-18 19:05:34 GMT; 1s ago
Docs: man:dhcpd(8)
Process: 3475 ExecStart=/bin/sh -ec CONFIG_FILE=/etc/dhcp/dhcpd.conf; if [ -f /etc/ltsp/dhcpd.conf ]; then CONFIG_FILE=/etc/ltsp/dhcpd.conf; fi; [ -e /var/lib/dhcp/dhcpd.leases ] || touch /v
Main PID: 3475 (code=exited, status=1/FAILURE)
Jan 18 19:05:34 user-Default-string dhcpd[3475]:
Jan 18 19:05:34 user-Default-string dhcpd[3475]: Not configured to listen on any interfaces!
Jan 18 19:05:34 user-Default-string dhcpd[3475]:
Jan 18 19:05:34 user-Default-string dhcpd[3475]: If you think you have received this message due to a bug rather
Jan 18 19:05:34 user-Default-string dhcpd[3475]: than a configuration issue please read the section on submitting
Jan 18 19:05:34 user-Default-string dhcpd[3475]: bugs on either our web page at www.isc.org or in the README file
Jan 18 19:05:34 user-Default-string dhcpd[3475]: before submitting a bug. These pages explain the proper
Jan 18 19:05:34 user-Default-string dhcpd[3475]: process and the information we find helpful for debugging..
Jan 18 19:05:34 user-Default-string dhcpd[3475]:
Jan 18 19:05:34 user-Default-string dhcpd[3475]: exiting.
我的網關伺服器有兩個乙太網路連接埠:enp1s0 和 enp2s0。我使用 enp1s0 透過路由器存取互聯網,而 enp2s0 僅用於為乙太網路連接的筆記型電腦提供 Web 應用程式。 enp2s0 是 DHCP 伺服器指派 IP 位址的位址(適用於需要 Web 應用程式的筆記型電腦)。我想enp1s0 從 192.168.1.0 子網路連接網際網路的路由器取得隨機 IP 位址,以便該介面不受 isc-dhcp-server 管理,僅由 enp2s0 管理。
這是“ip 路由”,沒有任何內容連接到 enp2s0,如果這可能有幫助...
$ ip route
default via 192.168.1.254 dev enp1s0 proto dhcp metric 100
169.254.0.0/16 dev enp1s0 scope link metric 1000
192.168.1.0/24 dev enp1s0 proto kernel scope link src 192.168.1.76 metric 100
這是我的 dhcpd.conf 設定:
default-lease-time 600;
max-lease-time 7200;
# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
# This is a very basic subnet declaration.
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.200 192.168.2.250;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
option broadcast-address 192.168.2.255;
}
這是我的 isc-dhcp-server 設定:
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="enp2s0"
INTERFACESv6=""
一種解決方案是將筆記型電腦插入 enp2s0 後重新啟動 isc-dhcp-server,但我不想在每次重新啟動後或每次有人將筆記型電腦插入 enp2s0 時都必須這樣做。重啟服務後DHCP伺服器就可以工作了...
$ sudo service isc-dhcp-server restart
$ service isc-dhcp-server status
● isc-dhcp-server.service - ISC DHCP IPv4 server
Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020-01-18 18:22:01 GMT; 14min ago
Docs: man:dhcpd(8)
Main PID: 2437 (dhcpd)
Tasks: 1 (limit: 2016)
CGroup: /system.slice/isc-dhcp-server.service
└─2437 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf enp2s0
有任何想法嗎?我確信我缺少一個配置,這將解決這個問題...
編輯: 指令「nmcli connection show lan」的輸出(又稱:nmcli cs lan)
$ nmcli connection show lan
connection.id: lan
connection.uuid: 96fbb458-1178-4af2-a1b7-ccce301176e0
connection.stable-id: --
connection.type: 802-3-ethernet
connection.interface-name: enp2s0
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.autoconnect-retries: -1 (default)
connection.auth-retries: -1
connection.timestamp: 1579379514
connection.read-only: no
connection.permissions: --
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries: --
connection.gateway-ping-timeout: 0
connection.metered: unknown
connection.lldp: default
connection.mdns: -1 (default)
802-3-ethernet.port: --
802-3-ethernet.speed: 0
802-3-ethernet.duplex: --
802-3-ethernet.auto-negotiate: no
802-3-ethernet.mac-address: --
802-3-ethernet.cloned-mac-address: --
802-3-ethernet.generate-mac-address-mask:--
802-3-ethernet.mac-address-blacklist: --
802-3-ethernet.mtu: auto
802-3-ethernet.s390-subchannels: --
802-3-ethernet.s390-nettype: --
802-3-ethernet.s390-options: --
802-3-ethernet.wake-on-lan: default
802-3-ethernet.wake-on-lan-password: --
ipv4.method: manual
ipv4.dns: --
ipv4.dns-search: --
ipv4.dns-options: ""
ipv4.dns-priority: 0
ipv4.addresses: 192.168.2.2/24
ipv4.gateway: --
ipv4.routes: --
ipv4.route-metric: -1
ipv4.route-table: 0 (unspec)
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-timeout: 0 (default)
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.dhcp-fqdn: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv4.dad-timeout: -1 (default)
ipv6.method: auto
ipv6.dns: --
ipv6.dns-search: --
ipv6.dns-options: ""
ipv6.dns-priority: 0
ipv6.addresses: --
ipv6.gateway: --
ipv6.routes: --
ipv6.route-metric: -1
ipv6.route-table: 0 (unspec)
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: -1 (unknown)
ipv6.addr-gen-mode: stable-privacy
ipv6.dhcp-send-hostname: yes
ipv6.dhcp-hostname: --
ipv6.token: --
proxy.method: none
proxy.browser-only: no
proxy.pac-url: --
proxy.pac-script: --
EDIT2:新增了「nmcli -f名稱,自動連接連接顯示」的輸出
$ nmcli -f name,autoconnect connection show
NAME AUTOCONNECT
Wired connection 1 yes
lan yes
EDIT3:新增了「cat /etc/NetworkManager/system-connections/lan」的輸出
[connection]
id=lan
uuid=96fbb458-1178-4af2-a1b7-ccce301176e0
type=ethernet
interface-name=enp2s0
permissions=
timestamp=1579379263
[ethernet]
mac-address-blacklist=
[ipv4]
address1=192.168.2.2/24
dns-search=
method=manual
[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto
答案1
介面 (enp2s0) 是否已啟動?需要新增ipv4位址然後啟動(up)
是否有任何客戶端連接到集線器/交換器都沒關係。
編輯:網路經理?
我非常討厭那件事,但無論如何:如果 iface 沒有正確的位址,dhcpd 將無法啟動,因此您需要弄清楚如何使用 nmcli 建立一個始終處於運行狀態的靜態配置。
編輯:這說明了什麼?
nmcli connection show lan
connection.autoconnection 屬性很有趣。
編輯:什麼顯示了這個:
nmcli -f name,autoconnect connection show
好的,狀態如何
nmcli -f name,autoconnect connection show
重新啟動後沒有你的黑客? autoconnect 屬性應該足以調出介面...不知道為什麼某些事情會在基本上非常簡單的事情中失敗是我對NetworkManager 的不喜歡之一(對於未知的好處來說太複雜,我看到客戶端不斷地這樣做的一點在移動中,但伺服器必須簡單地工作?
編輯:etc/NetworkManger/system-connections 中有任何檔案嗎?這至少是我在系統中配置設備的方式(它是橋接配置),所以我確實使用 NetworkManager 來啟動機器。該機器是三個來賓的主機,因此 enp1s0 設備是從屬設備。
編輯:如果您定義區域網路設備(首先將其完全刪除)會發生什麼,即:
nmcli connection down lan
nmcli connection delete lan
nmcli connection add type ethernet ifname enp2s0 con-name lan autoconnect on
nmcli connection modify lan ipv4.method manual ipv4.addresses 192.168.2.2/24
nmcli connection lan up
答案2
除非有更好的解決方案,否則目前這對我有用:當我的網頁應用程式啟動時,它所做的前兩件事是:
- 須藤 nmcli 康恩向上lan(「lan」是指派給 enp2s0 的 NetworkManager 連線名稱)
- sudo 服務 isc-dhcp-伺服器重新開始
Web 應用程式按 cron 計畫啟動 @reboot,因此 NetworkManager 已在此時啟動。
如果 enp2s0 尚未“啟動”,isc-dhcp-server 總是會失敗,因此我必須將其設為“啟動”,然後重新啟動 isc-dhcp-server 服務。它不是很優雅,但目前已經可以完成工作了。
答案3
如果它對任何人有幫助,我剛剛在 Pi Zero W 上的 DietPi (Debian Buster) 上解決了這個令人惱火的問題,並且已經解決了問題。
isc-dhcp-server 非常出色,但確實有這個怪癖,正如上面原始詢問者所指出的。我已經解決了這個問題 - 這不是一個錯誤 - 這是原因的細節:
如果 isc-dhcp-server 在啟動時看不到 UP 乙太網路子網,則會拒絕(引發錯誤);它不需要(與某些評論者相反)實際連接到與其關聯的乙太網路連接埠。
在開發WiFi熱點設備時,通常會使用hostapd作為AP伺服器功能(重新配置WiFi硬體以切換到AP模式),並且除了hostapd之外,您還需要像isc-dhcp-server這樣的dhcp伺服器來提供IP位址租賃服務。
SO:通常起始點是 WiFi 設備,在啟動時被配置為客戶端設備,但需要切換到主機模式才能充當熱點。因此,早期的步驟是在啟動 hostapd 之前將 wlan0 (或其他)設定為 DOWN。
但這種情況是 isc-dhcp-server 不喜歡的情況之一:如果您嘗試在 hostapd 之前啟動它,它將失敗,並抱怨沒有子網可供其監聽。
因此,您可能會天真地嘗試將新的IP位址(用於主機)新增至您的wlan0(或同等位址)並重試:這也不起作用,因為儘管您現在有一個連接到乙太網路連接埠的新IP,您還會發現無法將其設定為「UP」(ip link set wlan0 up 將會失敗)。這是因為該連接埠被仍然活動的陳舊位址和使用該位址的 wpa 請求進程「污染」。
長話短說:您需要殺死 wpa-supplicant,以「釋放」舊位址/刷新連接埠的 ip 設定/然後為主機新增新的 IP 位址;即使如此,您也會發現 isc-dhcp-server 仍然無法啟動,因為您還無法設定介面。最後 - 現在在 isc 之前運行 hostapd,IT 將(在重新配置晶片組時)也將 wlan0 介面設定為 UP。所以現在 - 最後 - 你可以運行 isc-dhcp-server,它將乾淨地啟動,並且你的熱點將會啟動。
我花了大約五個小時,我希望這可以節省一些時間。我的提煉筆記:
將 ISC-DHCP-SERVER 與 HOSTAPD 一起排序:解決方案
您必須遵循以下順序:
透過以下方式終止 wpa 請求者程序(維持客戶端 conn):
kill -2 $( cat /run/wpa_supplicant.wlan0.pid ) sleep 1 kill -9 $( cat /run/wpa_supplicant.wlan0.pid )
使用以下命令刷新 WLAN IP 設定:
ip addr flush dev wlan0
使用下列命令新增主機 IP 位址:
ip addr add 10.1.1.1/24 dev wlan0
啟動 hostapd,這也會將 wlan0 UP:
/usr/sbin/hostapd /etc/hostapd/hostapd.conf &
啟動 isc-dhcp-server ( WLAN 已啟動,現在作為主機):
sudo service isc-dhcp-server restart
然後接入點應該已啟動並準備好接受客戶端。
這些當然是我的地址/編輯以滿足您的需求。
還有兩個提示:設定檔 hostapd.conf 和 dhcp.conf 也會讓您抓狂: - 這裡是工作範例。重要提示:不要擔心 hostapd.conf 中的「驅動程式名稱」:不需要它。 「註解掉」很好:
主機設定檔
interface=wlan0
#driver=brcmfmac
ssid=THIS-IS-MY-AP
country_code=US
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1
dhcpd設定檔
# COMMENT OUT BOTH OF THE TEMPLATES' 'option domain..' lines..
# then ADD THIS AT BOTTOM
#
#
subnet 10.1.1.0 netmask 255.255.255.0 {
range 10.1.1.100 10.1.1.109;
option broadcast-address 10.1.1.255;
option routers 10.1.1.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "mynetwork.org";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
#
#
雖然這項工作是在 Pi 上進行的,但它是在 DietPi 上進行的,而 DietPi 是直接的 Debian,所以同樣的建議應該適合許多 Linux,包括多種風格的 Ububtus。
祝大家好運