Dav*_*vid 4 command-line network-manager networking dhcp
我正在使用使用网络管理器的现代版本的 Ubuntu,我想通过命令行发布和更新我的网络设置。
在过去,Ubuntu 使用该interfaces文件时,我只会这样做:
sudo /etc/init.d/networking restart但现在不再有效。
我正在寻找类似于 Windowsipconfig /release和ipconfig /renew.
如何从命令行界面释放和更新网络设置?
要释放和更新 IP 地址,它是:
sudo dhclient -r eth0
sudo dhclient eth0
Run Code Online (Sandbox Code Playgroud)
或者您可以尝试从netstat以下位置获取默认以太网名称的单行:
NIC=$(netstat -r | awk '/default/ {print $NF}' | head -1); sudo dhclient -r $NIC && sudo dhclient $NIC
Run Code Online (Sandbox Code Playgroud)
从dhclient联机帮助页:
-r Release the current lease and stop the running DHCP client as
previously recorded in the PID file. When shutdown via this
method dhclient-script will be executed with the specific reason
for calling the script set. The client normally doesn't release
the current lease as this is not required by the DHCP protocol
but some cable ISPs require their clients to notify the server
if they wish to release an assigned IP address.
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
实现此目的的一种方法是告诉网络管理器短暂断开设备连接并再次连接:
nmcli device disconnect wlan0; nmcli device connect wlan0
Run Code Online (Sandbox Code Playgroud)
(替换wlan0为系统上正确的设备名称)