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改为本身的机子的网卡名称,而后保存推出,重启网络,发现成功了!大功告成。