原文地址:http://www.cnblogs.com/vincedotnet/p/4013099.html html
. 找到文件並做以下修改:vim
sudo vim /etc/network/interfaces服務器
修改以下部分:dom
auto eth0
iface eth0 inet static
address 192.168.0.117
gateway 192.168.0.1 #這個地址你要確認下 網關是否是這個地址
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255oop
表示本身這樣設置下就能夠了 # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.168.3.22 netmask 255.255.255.0 gateway 192.168.3.255
2. 修改dns解析spa
由於之前是dhcp解析,因此會自動分配dns服務器地址rest
而一旦設置爲靜態ip後就沒有自動獲取到的dns服務器了code
要本身設置一個server
sudo vim /etc/resolv.confhtm
寫上一個公網的DNS
nameserver 202.96.128.86
(注意:8.8.8.8是谷歌的DNS服務器,可是解析速度慢,仍是找到一個國內的dns來用)
3. 重啓網卡:
sudo /etc/init.d/networking restart
默認配置以下
/etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 127.0.1.1 search localdomain