Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Debian/Ubuntu 網路設定完整指南:靜態 IP、DHCP 與 DNS 設定

編輯:Linux 系統常見問題解答

核心設定檔:/etc/network/interfaces

Debian 系列發行版透過此檔案管理網路介面,修改後需重啟網路服務生效:

sudo /etc/init.d/networking restart

情境一:設定靜態 IP

auto lo eth0
iface lo inet loopback

iface eth0 inet static
    address 192.168.1.30
    netmask 255.255.255.0
    broadcast 192.168.1.255
    gateway 192.168.1.1

關鍵字說明:

  • auto:開機自動啟動該介面
  • iface eth0 inet static:eth0 使用 IPv4 靜態 IP
  • address/netmask/gateway:IP、子網路遮罩、預設閘道

情境二:使用 DHCP 自動取得 IP

auto eth0
iface eth0 inet dhcp

DNS 解析設定:/etc/resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4
# 或使用內部 DNS
nameserver 192.168.1.1

注意:若使用 NetworkManager 或 systemd-resolved,此檔案可能被自動覆寫,請改用對應工具設定 (如 nmcli、resolvectl)。

驗證網路連通性

ping 8.8.8.8        # 測試外網連通
ping google.com     # 測試 DNS 解析
ip addr show eth0   # 確認 IP 設定生效

常見問題排除

  • 修改後不生效:確認執行 systemctl restart networking 或 ifdown eth0 && ifup eth0
  • IP 衝突:檢查網段內其他裝置是否使用相同 IP
  • DNS 不生效:檢查 /etc/resolv.conf 權限與內容,或檢查 /etc/nsswitch.conf hosts 項目
Copyright © Windows教程網 All Rights Reserved