1.eth0的30.1.1.0/24網段存在兩個ip
一個主ip:30.1.1.1/24 從ip:30.1.1.2/24
[root@sangfor ~]# ip addr show eth0
371: eth0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500link/ether 28:51:32:03:4a:ce brd ff:ff:ff:ff:ff:ff
inet 20.1.1.1/24 brd 20.1.1.255 scope global eth0
inet 30.1.1.1/24 brd 30.1.1.255 scope global eth0
inet 30.1.1.2/24 brd 30.1.1.255 scope global secondary eth0
inet6 fe80::2a51:32ff:fe03:4ace/64 scope link
valid_lft forever preferred_lft forever
2.刪除主ip 30.1.1.1/24 後接口配置如下
[root@sangfor ~]# ip addr show eth0
379: eth0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 500
link/ether 28:51:32:03:4a:ce brd ff:ff:ff:ff:ff:ff
inet 20.1.1.1/24 brd 20.1.1.255 scope global eth0
inet6 fe80::2a51:32ff:fe03:4ace/64 scope link
valid_lft forever preferred_lft forever
好神奇,從ip怎麼也沒了呢??
原來是因爲有一個內核參數控制這個:
down掉所屬某個子網的primary ip的時候, 所有相關的secondary ip也會down掉。
設置一個內核參數, 當primary ip宕掉時可以將secondary ip提升爲primary ip。
echo "1" > /proc/sys/net/ipv4/conf/all/promote_secondaries
接下來重複操作1、2兩步,從ip就不會被刪掉了:
[root@sangfor ~]# ip addr show eth0
371: eth0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500
link/ether 28:51:32:03:4a:ce brd ff:ff:ff:ff:ff:ff
inet 20.1.1.1/24 brd 20.1.1.255 scope global eth0
inet 30.1.1.1/24 brd 30.1.1.255 scope global eth0
inet 30.1.1.2/24 brd 30.1.1.255 scope global secondary eth0
inet6 fe80::2a51:32ff:fe03:4ace/64 scope link
valid_lft forever preferred_lft forever
[root@sangfor ~]# ip addr show eth0
371: eth0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500
link/ether 28:51:32:03:4a:ce brd ff:ff:ff:ff:ff:ff
inet 20.1.1.1/24 brd 20.1.1.255 scope global eth0
inet 30.1.1.2/24 brd 30.1.1.255 scope global eth0
inet6 fe80::2a51:32ff:fe03:4ace/64 scope link
valid_lft forever preferred_lft forever