zoukankan      html  css  js  c++  java
  • Ubuntu 16.04 配置单网卡绑定多IP

    Ubuntu 16.04 配置单网卡绑定多IP

    操作系统

    Ubuntu 16.04 LTS
    

    一、单个网卡配置多个IP

      //在 /etc/network/ 目录下编辑 interfaces 文件
    root@ubuntu:~# vim /etc/network/interfaces
    # 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 eth0                          //这台主机只有 eth0 这张网卡
    iface eth0 inet static
            address 192.168.121.24
            netmask 255.255.255.0
            gateway 192.168.121.2
            dns-nameserver 192.168.121.2
    
    auto eth0:0                      //配置子ip eth0:0
    iface eth0:0 inet static
            address 192.168.121.25
            netmask 255.255.255.0
    
    auto eth0:1                      //配置子ip eth0:1
    iface eth0:1 inet static
            address 192.168.121.26
            netmask 255.255.255.0
     
    auto eth0:2                      //配置子ip eth0:2   ;接着可以依次类推
    iface eth0:2 inet static
            address 192.168.121.27
            netmask 255.255.255.0
    

    二、添加 DNS 配置

    1. 直接在配置文件中添加
    auto eth0
    iface eth0 inet static
            address 192.168.121.24
            netmask 255.255.255.0
            gateway 192.168.121.2
            dns-nameserver 192.168.121.2      # 添加这行即可
    
    
    • 保存退出后,执行: systemctl restart networking
    1. /etc/resolvconf/resolv.conf.d/ 下的 head 或者 base 文件中添加 dns
    • 注意:在这连个文件中添加好后,立即执行: resolvconf -u
    root@ubuntu:~# vim /etc/resolvconf/resolv.conf.d/head
    # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
    #     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
    nameserver 192.168.121.2            # 添加这一行
    
    root@ubuntu:~# resolvconf -u        # 保存退出后,一定要执行这条命令,否则无效
    
    
    
    或者:
    root@ubuntu:~# echo "nameserver x.x.x.x" >> /etc/resolvconf/resolv.conf.d/base
    root@ubuntu:~# echo "nameserver x.x.x.x" >> /etc/resolvconf/resolv.conf.d/head     //任选其一;将 x.x.x.x 换成 DNS 地址
    root@ubuntu:~# resolvconf -u
    
    

    三、重启网络服务

      //重启网络服务
    root@ubuntu:~# systemctl restart networking.service
    
      //查看IP信息
    root@ubuntu:~# ip add
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:16:c5:69 brd ff:ff:ff:ff:ff:ff
        inet 192.168.121.24/24 brd 192.168.121.255 scope global eth0
           valid_lft forever preferred_lft forever
        inet 192.168.121.25/24 brd 192.168.121.255 scope global secondary eth0:0
           valid_lft forever preferred_lft forever
        inet 192.168.121.26/24 brd 192.168.121.255 scope global secondary eth0:1
           valid_lft forever preferred_lft forever
        inet 192.168.121.27/24 brd 192.168.121.255 scope global secondary eth0:2
           valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:fe16:c569/64 scope link 
           valid_lft forever preferred_lft forever
    
  • 相关阅读:
    JID 2.0 RC4 发布,高性能的 Java 序列化库
    FBReaderJ 1.6.3 发布,Android 电子书阅读器
    Arquillian 1.0.3.Final 发布,单元测试框架
    JavaScript 的宏扩展 Sweet.js
    Hypertable 0.9.6.5 发布,分布式数据库
    JRuby 1.7.0 发布,默认使用 Ruby 1.9 模式
    httppp 1.4.0 发布,HTTP响应时间监控
    Redis 2.6.0 正式版发布,高性能K/V服务器
    OfficeFloor 2.5.0 发布,IoC 框架
    XWiki 4.3 首个里程碑发布
  • 原文地址:https://www.cnblogs.com/itwangqiang/p/14572379.html
Copyright © 2011-2022 走看看