配置服务器固定ip

原有server在搬家后,给分配了新的ip地址。

通过当前ip登陆

现在开始修改

当前为ubuntu18.04系统

1、修改配置文件/etc/network/interfaces

root@ubuntu:~#sudo vi /etc/network/interfaces

添加以下内容:

auto eth0#设置自动启动eth0接口

iface eth0 inet static#配置静态IP

2、修改DNS

sudo gedit /etc/resolve.conf

nameserver 127.0.0.1 #记得加上

nameserver 8.8.8.8#当地dns服务器(用ipconfig /all 查看本地dns,第一个dns是默认的,共有2个dns)

注:#后面的注释信息不要加进去。

3、重启网络,使配置生效

sudo /etc/init.d/networking restart

4、查看ip是否配置成功root@ubuntu:~# ifconfig

第一次查看发现ip没有变化,可以直接重启机器试试,

我在做这个时候,发现没有生效后,重新执行sudo /etc/init.d/networking restart 然后失败

于是试了各种办法,其实只需要重启就可以

当然ubuntu18.04对于ip设置有新的方法,你也可以通过netplan来设置

你可能感兴趣的:(配置服务器固定ip)