Ubuntu16 配置静态IP

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

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

    151250_TrgS_2264300.png

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

    151404_T8V5_2264300.png

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

    $ ifconfig

    151928_XxHj_2264300.png

  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步)

    # 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. 配置DNS

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

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

    nameserver 192.168.14.2

     

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

     

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

转载于:https://my.oschina.net/u/2264300/blog/836783

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值