1. 程式人生 > >Ubuntu 16.04 設定固定IP地址

Ubuntu 16.04 設定固定IP地址

查詢網路介面名

輸入命令:

ifconfig
或者
ip address

記錄下返回結果的網路介面名, 一般以 enp開頭

修改檔案

修改/etc/network/interfaces檔案 將原有的

auto lo
iface lo inet loopback

修改為

auto enp3s0
iface enp3s0 inet static
address 192.168.1.102
netmask 255.255.255.0
gateway 192.168.1.1

dns-nameservers 192.168.1.1
# 如果多個dns:
# dns-nameservers X.X.X.X Y.Y.Y.Y Z.Z.Z.Z

重新整理介面 重啟服務

sudo /etc/init.d/networking restart

如果上面命令無法令ubuntu重啟網路,則使用下面命令:

sudo ifdown eth0 && sudo ifup eth0