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是否會發生變化 
相關文章
相關標籤/搜索