> ## Content Index
> Fetch the complete content index at: https://www.albert-yu.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# ubuntu 16.04 設定固定IP
- URL: https://www.albert-yu.com/blog/ubuntu-16-04-static-ip/
- Published: 2018-01-09T08:04:09.000Z
- Updated: 2026-10-30T03:43:33.000Z
- Author: Albert Yu
- Tags: Linux/Unix, OS, IP, Ubuntu, 固定IP

Ubuntu 在安裝完成時會設DHCP 並自動取得 IP，但伺服器的IP位置不可能承受連不到的風險。

這時候可以透過文字介面來手動設定。

1.修改 Ethernet 網路設定

```
root@management:~# vim /etc/network/interfaces
 # This file describes the network interfaces available on your system
 # and how to activate them. For more information, see interfaces(5).source /etc/network/interfaces.d/*# The loopback network interface
 auto lo
 iface lo inet loopback# The primary network interface
 auto ens160
 iface ens160 inet static # 固定 (靜態) IP
 address 10.159.xx.xx # IP 位址
 netmask 255.255.255.0 # 網路遮罩
 gateway 10.159.xx.xx # 預設閘道
 dns-nameservers 168.95.1.1 #DNS第一組
 dns-nameservers 8.8.8.8 #DNS第二組
```

2\. 修改完可使用以下指令重新啟動網路讀取網路設定 root@management:\~# /etc/init.d/networking restart  
\[ ok \] Restarting networking (via systemctl): networking.service. 重點提示： 有些錯誤的網站會寫說DNS設定是在/etc/resolv.conf 但這在ubuntu 12之後已經棄用 如果重開機會直接失效 如果需要DNS設定請直接寫在/etc/network/interfaces