1. 进入网卡配置目录

    cd /etc/sysconfig/network-scripts
    
    [root@www network-scripts]# ls
    ifcfg-em1  ifcfg-lo ..
  2. 运行ifconfig查看当前使用的网卡配置

    [root@www network-scripts]# ifconfig 
    em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet 192.187.112.90  netmask 255.255.255.248  broadcast 192.187.112.95
         inet6 fe80::226:6cff:fef0:1158  prefixlen 64  scopeid 0x20<link>
         ether 00:26:6c:f0:11:58  txqueuelen 1000  (Ethernet)
         RX packets 541372  bytes 746304201 (711.7 MiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 99758  bytes 28932462 (27.5 MiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
         device memory 0xfbde0000-fbdfffff  
    
    em2: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
         ether 00:26:6c:f0:11:59  txqueuelen 1000  (Ethernet)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 0  bytes 0 (0.0 B)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
         device memory 0xfbd20000-fbd3ffff  
    
    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 1000  (Local Loopback)
         RX packets 128  bytes 11776 (11.5 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 128  bytes 11776 (11.5 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

    如上, 根据IP可以确认外网配置是em1

  3. 复制一个配置文件

    cp ifcfg-em1 ifcfg-em1:1
  4. 修改几项配置

    # Generated by dracut initrd
    NAME="em1"
    DEVICE="em1:1"   # 后面加:1
    ONBOOT="yes"
    NETBOOT="yes"
    UUID="75e73492-9586-45fc-951f-3d99ab134668"
    IPV6INIT="yes"
    BOOTPROTO="none"
    TYPE="Ethernet"
    PROXY_METHOD="none"
    BROWSER_ONLY="no"
    IPADDR="192.187.112.91"  # 改成其他IP
    PREFIX="29"
    GATEWAY="192.187.112.89"
    DNS1="127.0.0.1"
    DEFROUTE="yes"
    IPV4_FAILURE_FATAL="no"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_FAILURE_FATAL="no"

    如果需要配置更多IP, 可以继续复制ifcfg-em1文件为ifcfg-em1:2, 相应的修改复制后的文件, 示例:

    DEVICE="em1:2"   # 后面加:2
    IPADDR="192.187.112.92"  # 改成其他IP
  5. 重启网卡使配置生效

    systemctl restart network
    
    ### CentOS8使用如下命令:
    nmcli c reload  # 重新加载配置文件
    nmcli c up em1  # 重新激活网卡em1
  6. 查看是否生效

    [root@www network-scripts]# ifconfig 
    em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet 192.187.112.90  netmask 255.255.255.248  broadcast 192.187.112.95
         inet6 fe80::226:6cff:fef0:1158  prefixlen 64  scopeid 0x20<link>
         ether 00:26:6c:f0:11:58  txqueuelen 1000  (Ethernet)
         RX packets 542683  bytes 746406082 (711.8 MiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 100544  bytes 29029241 (27.6 MiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
         device memory 0xfbde0000-fbdfffff  
    
    em1:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet 192.187.112.91  netmask 255.255.255.248  broadcast 192.187.112.95
         ether 00:26:6c:f0:11:58  txqueuelen 1000  (Ethernet)
         device memory 0xfbde0000-fbdfffff  
    
    em2: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
         ether 00:26:6c:f0:11:59  txqueuelen 1000  (Ethernet)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 0  bytes 0 (0.0 B)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
         device memory 0xfbd20000-fbd3ffff  
    
    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 1000  (Local Loopback)
         RX packets 128  bytes 11776 (11.5 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 128  bytes 11776 (11.5 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    em1:1就是新增的虚拟网卡

加5个IP的最终效果:

[root@www network-scripts]# ifconfig 
em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.187.112.90  netmask 255.255.255.248  broadcast 192.187.112.95
        inet6 fe80::226:6cff:fef0:1158  prefixlen 64  scopeid 0x20<link>
        ether 00:26:6c:f0:11:58  txqueuelen 1000  (Ethernet)
        RX packets 543663  bytes 746488748 (711.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 101167  bytes 29138923 (27.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xfbde0000-fbdfffff  

em1:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.187.112.91  netmask 255.255.255.248  broadcast 192.187.112.95
        ether 00:26:6c:f0:11:58  txqueuelen 1000  (Ethernet)
        device memory 0xfbde0000-fbdfffff  

em1:2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.187.112.92  netmask 255.255.255.248  broadcast 192.187.112.95
        ether 00:26:6c:f0:11:58  txqueuelen 1000  (Ethernet)
        device memory 0xfbde0000-fbdfffff  

em1:3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.187.112.93  netmask 255.255.255.248  broadcast 192.187.112.95
        ether 00:26:6c:f0:11:58  txqueuelen 1000  (Ethernet)
        device memory 0xfbde0000-fbdfffff  

em1:4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.187.112.94  netmask 255.255.255.248  broadcast 192.187.112.95
        ether 00:26:6c:f0:11:58  txqueuelen 1000  (Ethernet)
        device memory 0xfbde0000-fbdfffff  

em1:5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.187.112.95  netmask 255.255.255.248  broadcast 192.187.112.95
        ether 00:26:6c:f0:11:58  txqueuelen 1000  (Ethernet)
        device memory 0xfbde0000-fbdfffff  

em2: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:26:6c:f0:11:59  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xfbd20000-fbd3ffff  

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 1000  (Local Loopback)
        RX packets 136  bytes 12464 (12.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 136  bytes 12464 (12.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

YYGP
25 声望11 粉丝

写BUG


引用和评论

0 条评论