Linux—DHCP

Situation

# 網路介面取得IP
The network interface obtains an IP address.

Solution - 1

[1]
# 確認目前的介面與IP
CMD > ip addr show

[2]
# apt安裝dhclient
sudo apt update
sudo apt install isc-dhcp-client

[3]
# 取得IP
sudo dhclient "interface"

# 如果已有IP
sudo dhclient -r "interface"

Solution - 2

[1]
# 確認目前的介面與IP
CMD > ip addr show

[2]
# 查看網卡設定檔
cat /etc/netplan/*.yaml

[3]
# 編輯網卡設定檔
vi /etc/netplan/*.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: true

[4]
# 套用
sudo netplan apply

TroubleShooting

# 如果沒有IP
sudo dhclient -v "interface"