linux刪除主ip,從ip自動被刪除

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 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

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章