zoukankan      html  css  js  c++  java
  • Linux同一机器设置多个IP2019-7-6

    1.临时增加

    1)先查看目前的网卡信息

    [root@study ~]# ifconfig
    eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 192.168.218.138 netmask 255.255.255.0 broadcast 192.168.218.255
    inet6 fe80::20c:29ff:feda:49b1 prefixlen 64 scopeid 0x20<link>
    ether 00:0c:29:da:49:b1 txqueuelen 1000 (Ethernet)
    RX packets 8990 bytes 823774 (804.4 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 3603 bytes 808211 (789.2 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
    inet 127.0.0.1 netmask 255.0.0.0
    inet6 ::1 prefixlen 128 scopeid 0x10<host>
    loop txqueuelen 0 (Local Loopback)
    RX packets 192 bytes 18960 (18.5 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 192 bytes 18960 (18.5 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    2)新增一个虚拟端口,并配置IP地址
    [root@study ~]# ifconfig eno16777736:1 192.168.217.140 netmask 255.255.255.0 up
    #up表示当即生效,另外,如果想关闭某个端口,可以ifconfig eno16777736:1down

    [root@study ~]# ping 192.168.217.140
    PING 192.168.217.140 (192.168.217.140) 56(84) bytes of data.
    64 bytes from 192.168.217.140: icmp_seq=1 ttl=64 time=0.010 ms
    64 bytes from 192.168.217.140: icmp_seq=2 ttl=64 time=0.021 ms

    查看当前路由

    [root@study ~]# netstat -rn
    Kernel IP routing table
    Destination Gateway Genmask Flags MSS Window irtt Iface
    0.0.0.0 192.168.218.2 0.0.0.0 UG 0 0 0 eno16777736
    192.168.217.0 0.0.0.0 255.255.255.0 U 0 0 0 eno16777736
    192.168.217.0 0.0.0.0 255.255.255.0 U 0 0 0 eno16777736
    192.168.218.0 0.0.0.0 255.255.255.0 U 0 0 0 eno16777736

    3)设置路由

    对应新IP,新增一个网段,使这个网段能够访问

    [root@study ~]# route add -net 192.168.217.0 netmask 255.255.255.0 gw 192.168.217.1 eno16777736:1

    2.永久性新增一个IP

    1)在/etc/sysconfig/network-scripts/下,新增ifcfg-eno16777736:1文件

    修改成

    DEVICE=eno16777736:1
    #BOOTPROTO=dhcp
    BOOTPROTO=static
    HWADDR=00:0c:29:da:49:b1
    ONBOOT=yes
    IPADDR=192.168.217.140
    NETMASK=255.255.255.0
    TYPE=Ethernet
    GATEWAY=192.168.217.1

    2)重启网络服务

    [root@study ~]# /etc/init.d/network restart

  • 相关阅读:
    Object.prototype.toString.call()进行类型判断
    JavaScript中的typeof操作符用法实例
    js ==与===区别(两个等号与三个等号)
    js nextSibling属性和previousSibling属性概述及使用注意
    Java 缓存技术之 ehcache
    不可不知 DDoS的攻击原理与防御方法
    jQuery的选择器中的通配符[id^='code']
    jquery $("[id$='d']").val();这句话什么意思?
    js 数组的操作
    【转】理解js中的原型链,prototype与__proto__的关系
  • 原文地址:https://www.cnblogs.com/DevonL/p/11143573.html
Copyright © 2011-2022 走看看