sudo gedit /etc/network/interfaces
修改如下部分:
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.255
2. 修改dns解析
因为以前是dhcp解析,所以会自动分配dns服务器地址
而一旦设置为静态ip后就没有自动获取到的dns服务器了
要自己设置一个
sudo gedit /etc/resolv.conf
写上一个公网的DNS
nameserver XXX.XXX.XXX.XXX
重启网卡
/etc/init.d/networking stop
/etc/init.d/networking start
或者重启网卡(ifdown/ifup eth0)
在 Ubuntu 里面可以使用
sudo ifconfig eth0 down
sudo ifconfig eth0 up
使用ifconfig 可以看到新设置的ip地址已经生效
我的是重启客户机后静态ip才生效