首页 > Linux运维 > CentOS > centos7/rhel7一个网卡添加多个ip地址
2019
07-15

centos7/rhel7一个网卡添加多个ip地址

临时生效方式

[root@bogon network-scripts]# ifconfig ens192:0 192.168.21.130 netmask 255.255.255.0 up
[root@bogon network-scripts]# ifconfig ens192:1 192.168.21.131 netmask 255.255.255.0 up
[root@bogon network-scripts]# ifconfig ens192:2 192.168.21.132 netmask 255.255.255.0 up

[root@bogon network-scripts]# ifconfig 
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.21.52  netmask 255.255.255.0  broadcast 192.168.21.255
        inet6 fe80::2725:4338:4578:954c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:2a:91:5e  txqueuelen 1000  (Ethernet)
        RX packets 7772  bytes 748880 (731.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2136  bytes 959641 (937.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens192:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.21.130  netmask 255.255.255.0  broadcast 192.168.21.255
        ether 00:0c:29:2a:91:5e  txqueuelen 1000  (Ethernet)

ens192:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.21.131  netmask 255.255.255.0  broadcast 192.168.21.255
        ether 00:0c:29:2a:91:5e  txqueuelen 1000  (Ethernet)

ens192:2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.21.132  netmask 255.255.255.0  broadcast 192.168.21.255
        ether 00:0c:29:2a:91:5e  txqueuelen 1000  (Ethernet)

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 16  bytes 1376 (1.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1376 (1.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

重启网络,临时添加的ip就会失效。

[root@bogon network-scripts]# systemctl restart network.service

[root@bogon network-scripts]# ifconfig 
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.21.52  netmask 255.255.255.0  broadcast 192.168.21.255
        inet6 fe80::2725:4338:4578:954c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:2a:91:5e  txqueuelen 1000  (Ethernet)
        RX packets 7772  bytes 748880 (731.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2136  bytes 959641 (937.1 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 1000  (Local Loopback)
        RX packets 16  bytes 1376 (1.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1376 (1.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

配置文件方式

[root@bogon network-scripts]# cat ifcfg-ens192:0
TYPE=Ethernet
BOOTPROTO=static
NAME=ens192:0
DEVICE=ens192:0
ONBOOT=yes
IPADDR=192.168.21.130
NETMASK=255.255.255.0


[root@bogon network-scripts]# cat ifcfg-ens192:1
TYPE=Ethernet
BOOTPROTO=static
NAME=ens192:1
DEVICE=ens192:1
ONBOOT=yes
IPADDR=192.168.21.131
NETMASK=255.255.255.0


[root@bogon network-scripts]# cat ifcfg-ens192:2
TYPE=Ethernet
BOOTPROTO=static
NAME=ens192:2
DEVICE=ens192:2
ONBOOT=yes
IPADDR=192.168.21.132
NETMASK=255.255.255.0

重启网络生效

[root@bogon network-scripts]# systemctl restart network.service

[root@bogon network-scripts]# ifconfig 
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.21.52  netmask 255.255.255.0  broadcast 192.168.21.255
        inet6 fe80::2725:4338:4578:954c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:2a:91:5e  txqueuelen 1000  (Ethernet)
        RX packets 7772  bytes 748880 (731.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2136  bytes 959641 (937.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens192:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.21.130  netmask 255.255.255.0  broadcast 192.168.21.255
        ether 00:0c:29:2a:91:5e  txqueuelen 1000  (Ethernet)

ens192:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.21.131  netmask 255.255.255.0  broadcast 192.168.21.255
        ether 00:0c:29:2a:91:5e  txqueuelen 1000  (Ethernet)

ens192:2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.21.132  netmask 255.255.255.0  broadcast 192.168.21.255
        ether 00:0c:29:2a:91:5e  txqueuelen 1000  (Ethernet)

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 16  bytes 1376 (1.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1376 (1.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

最后编辑:
作者:劳福喜博客
这个作者貌似有点懒,什么都没有留下。

留下一个回复

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据