Ubuntu16 配置静态IP

安装虚拟机时,为了不每次重启虚拟机IP发生变化,因此进行静态IP的配置
步骤:vim

  1. 配置静态IP,除了IP外,网关和DNS也须要进行配置
  2. 查看网关IP  Gateway
    $ route -n

  3. 查看DNS IP, nameserver
    $ cat /etc/resolv.conf

  4. 查看当前网络配置(注意要记住网卡名字ens33)bash

    $ ifconfig

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

    旧配置以下(动态IP)网络

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    source /etc/network/interfaces.d/*
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    auto ens33
    iface ens33 inet dhcp

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

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    source /etc/network/interfaces.d/*
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    auto ens33
    iface ens33 inet static
    address 192.168.14.139
    gateway 192.168.14.2
    netmask 255.255.255.0
    broadcast 192.168.14.255

     

  6. 配置DNSrest

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

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

    nameserver 192.168.14.2

     

  7.  刷新DNS配置
    $ sudo resolvconf -u

     

  8. 重启网卡
    $ sudo /etc/init.d/networking restart
     
  9. 检查:重复2.3.4三步骤,查看如今的配置,重启虚拟机网络,查看IP是否会发生变化 
相关文章
相关标签/搜索