1.編輯/etc/network/interfaces文件:ubuntu
# This file describes the network interfaces available on your systemc#
# and how to activate them. For more information, see interfaces(5).segmentfault
source /etc/network/interfaces.d/*網絡
# The loopback network interfaceoop
auto lopost
iface lo inet loopbackspa
# The primary network interfacerest
auto eth0#etho爲一般的Ubuntu的網關名稱,有時也會改變,可經過ifconfig命令查看,有時會出現如ens160,ens33等名稱code
iface eth0 inet static#設置IP爲靜止IP,orm
address 192.168.1.103#你想設置的靜態IP地址
netmask 255.255.255.0#子網掩碼,一般爲255.255.255.0
#network 192.168.1.0
broadcast 192.168.1.255 #廣播地址,能夠經過ifconfig查看現有的。,
gateway 192.168.1.8#網關, #netstat -r 命令或者 nm-tool 查看現有的
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 61.139.2.69#國內常見的dns解析,
#dns-search localhost
dns-nameservers 8.8.8.8#谷歌dns解析,可是速度較慢
配置好後就重啓網卡:sudo /etc/init.d/networking restart
便可查看修改後的系統IP信息。若是無networking文件,則本身建立。
執行該命令時,可能出現的錯誤:
[....] Restarting networking (via systemctl): networking.serviceJob for networking.service failed because the control process exited with error code. See "systemctl status networking.service" and "journalctl -xe" for details.
failed!
後來發現出現這個錯誤的緣由,是由於Ubuntu16.04中的網卡名稱不是eth0。
具體是網卡名稱能夠經過ifocnfig命令查看,個人機子的網卡名稱爲enp0s25,有些機子的網卡名稱多是ens33,將eth0改爲本身的機子的網卡名稱,而後保存推出,重啓網絡,發現成功了!大功告成。