修改網路設定、排除故障或套用新 IP 時,常需重啟網卡。本文介紹三種方法,適用不同場景與發行版。
systemctl restart network
# 或
service network restart
優點:一次套用所有介面設定檔變更。
缺點:會中斷所有網路連線,遠端操作需謹慎。
# ifconfig 法
ifconfig eth0 down
ifconfig eth0 up
# ip 指令法(推薦)
ip link set eth0 down
ip link set eth0 up
優點:不影響其他介面,適合遠端維運。
注意:若 IP 由 DHCP 取得,up 後需再執行 dhclient eth0 重新租約。
ifdown eth0
ifup eth0
優點:會重新讀取 /etc/sysconfig/network-scripts/ifcfg-eth0,套用靜態 IP 變更。
缺點:需安裝 network-scripts 套件(CentOS 7/8 預設不裝)。
nmcli con down eth0
nmcli con up eth0
# 或
nmcli device reapply eth0 # 僅重新套用設定,不斷開連線
ip addr show eth0
ethtool eth0 | grep "Link detected"
ping -c 3 gateway_ip
systemctl restart networkip link set ... down/up 或 nmcliifdown/ifup 或 nmcli con up根據環境與風險選擇適當方式,避免斷線鎖死自己。