On the eth0 interface, the ip row is raised. Suppose the file / etc / network / interfaces:

auto eth0 iface eth0 inet static address 100.100.100.100 netmask 255.255.255.0 auto eth0:1 iface eth0:1 inet static address 100.100.100.101 netmask 255.255.255.0 auto eth0:2 iface eth0:2 inet static address 100.100.100.102 netmask 255.255.255.0 

If you look at the routing table, we see the following entries.

 $ ip route show default via 100.100.100.1 dev eth0 100.100.100.0/24 dev eth0 proto kernel scope link src 100.100.100.102 

The task is always to ensure that the src 100.100.100.102 value is the ip that I specify (and was constant). I can do this manually, via the ip command, but this will only be until the first reboot of the server or the service networking reload command

How to do it correctly, given that the number of ip can be more than 100 on one interface?

And if you create a routing table, again through the ip command, then it also exists only until the first reboot.

    1 answer 1

    eth0: 1 eth0: 2

    so-called network interface aliases in the network subsystem of the linux program are irrelevant for 15-16 years already. below I give the normal configuration without this “heavy legacy”. but if you want, just add configuration alias .

    The task is that I want that always the value of src 100.100.100.102 was the ip that I specify (and was constant).

    and indicate this explicitly (last line):

     auto eth0 iface eth0 inet static address 100.100.100.100 netmask 255.255.255.0 up ip aa 100.100.100.101/24 dev $IFACE up ip aa 100.100.100.102/24 dev $IFACE up ip rc 100.100.100.0/24 dev $IFACE src 100.100.100.102 

    used abbreviations (you can write and completely, just so shorter):

    • ip aa = ip address add
    • ip rc = ip route change

    about the "add configuration alias-s ".

    if they are so necessary, then the easiest way is to specify these alias (in the terminology of the ip program - labels, labels ) directly with the arguments of the ip program:

     ip aa ... label $IFACE:0 
    • It is worth deciphering aa and r ch for posterity. And to search. - Alexey Ten
    • @AlexeyTen, decrypted. - aleksandr barakin
    • In my opinion, abbreviations are good when you manually type commands. And in the config file (and in the response) it is better that everything would be clear - Alexey Ten
    • @AlexeyTen, in general, I agree with your opinion, and often I myself cite the brief and long form of the option / parameter. for example: -u and --unified . - aleksandr barakin pm
    • Thanks @alexanderbarakin! Your option is really good! And where can I read in more detail about variables used like $ IFACE - Kislik