Ubuntu16 配置静态IP

前端之家收集整理的这篇文章主要介绍了Ubuntu16 配置静态IP前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

安装虚拟机时,为了避免每次重启虚拟机IP发生变化,所以进行静态IP的配置
步骤:

  1. 配置静态IP,除了IP外,网关和DNS也需要进行配置
  2. 查看网关IP Gateway
    1. $ route -n
  3. 查看DNS IP,nameserver
    1. $ cat /etc/resolv.conf
  4. 查看当前网络配置(注意要记住网卡名字ens33)

    1. $ ifconfig
  5. 修改静态IP
    1. $ sudo vim /etc/network/interfaces

    旧配置如下(动态IP)

    1. # This file describes the network interfaces available on your system
    2. # and how to activate them. For more information,see interfaces(5).
    3.  
    4. source /etc/network/interfaces.d/*
    5.  
    6. # The loopback network interface
    7. auto lo
    8. iface lo inet loopback
    9.  
    10. # The primary network interface
    11. auto ens33
    12. iface ens33 inet dhcp

    修改为新配置(静态IP),注意Ubuntu 16 使用的网卡命名不是eth + 数字,而是 ens + 数字,所以配置静态IP前请记住ifconfig输出的网卡名称(上面第4步)

    1. # This file describes the network interfaces available on your system
    2. # and how to activate them. For more information,see interfaces(5).
    3.  
    4. source /etc/network/interfaces.d/*
    5.  
    6. # The loopback network interface
    7. auto lo
    8. iface lo inet loopback
    9.  
    10. # The primary network interface
    11. auto ens33
    12. iface ens33 inet static
    13. address 192.168.14.139
    14. gateway 192.168.14.2
    15. netmask 255.255.255.0
    16. broadcast 192.168.14.255
  6. 配置DNS

    1. $ sudo vim /etc/resolvconf/resolv.conf.d/base

    首次配置,该文件为空,输入如下内容

    1. nameserver 192.168.14.2
  7. 刷新DNS配置
    1. $ sudo resolvconf -u
  8. 重启网卡
    1. $ sudo /etc/init.d/networking restart
  9. 检查:重复2.3.4三步骤,查看现在的配置,重启虚拟机网络,查看IP是否会发生变化

猜你在找的Ubuntu相关文章