CentOS配置虚拟IP(VIP)

Linux笔记 2020年05月25日

本篇笔记记录了在CentOS7环境下配置,查看,删除虚拟IP(VIP)的方法

当前IP信息

[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:49:4e:64 brd ff:ff:ff:ff:ff:ff
    inet 192.168.75.240/24 brd 192.168.75.255 scope global noprefixroute dynamic ens33
       valid_lft 970sec preferred_lft 970sec
[root@localhost ~]# 

配置VIP

ip addr add 192.168.75.100/24 dev ens33

查看IP信息

ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:49:4e:64 brd ff:ff:ff:ff:ff:ff
    inet 192.168.75.240/24 brd 192.168.75.255 scope global noprefixroute dynamic ens33
       valid_lft 1097sec preferred_lft 1097sec
    inet 192.168.75.100/24 scope global secondary ens33
       valid_lft forever preferred_lft forever

VIP192.168.75.100已经设置成功

ping

本机ping虚拟IP

ping 192.168.75.100
PING 192.168.75.100 (192.168.75.100) 56(84) bytes of data.
64 bytes from 192.168.75.100: icmp_seq=1 ttl=64 time=0.058 ms
64 bytes from 192.168.75.100: icmp_seq=2 ttl=64 time=0.051 ms
64 bytes from 192.168.75.100: icmp_seq=3 ttl=64 time=0.026 ms

同网段其他机器ping虚拟IP

[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:99:34:af brd ff:ff:ff:ff:ff:ff
    inet 192.168.75.241/24 brd 192.168.75.255 scope global noprefixroute dynamic ens33
       valid_lft 1099sec preferred_lft 1099sec
[root@localhost ~]# ping 192.168.75.100
PING 192.168.75.100 (192.168.75.100) 56(84) bytes of data.
64 bytes from 192.168.75.100: icmp_seq=1 ttl=64 time=0.325 ms
64 bytes from 192.168.75.100: icmp_seq=2 ttl=64 time=0.270 ms
64 bytes from 192.168.75.100: icmp_seq=3 ttl=64 time=0.188 ms

删除VIP

ip addr del 192.168.75.100/24 dev ens33