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
    
  • 相关阅读:
    WCF Server Console
    Restart IIS With Powershell
    RestartService (recursively)
    Copy Files
    Stopping and Starting Dependent Services
    多线程同步控制 ManualResetEvent AutoResetEvent MSDN
    DTD 简介
    Using Powershell to Copy Files to Remote Computers
    Starting and Stopping Services (IIS 6.0)
    java中的NAN和INFINITY
  • 原文地址:https://www.cnblogs.com/itwangqiang/p/14572379.html
Copyright © 2011-2022 走看看