V
V
Vi2015-12-06 03:48:08
linux
Vi, 2015-12-06 03:48:08

Two addresses per interface or two sub-interfaces on Linux?

In general, in the config file, for example, debian, you can set sub-interface br0:1 br0:2 etc
and using the ip addr add xxxx / xx dev interface command, you can set an additional address for the interface,
but in the first case (with the config file) we will display record that this is a sub interface
and in the second case the address and additional info will be simply written.
Maybe there is a guru who can unwind and explain such nuances?
Well, maybe you can throw an article or something about sub interfaces, and how it is implemented programmatically

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg Tsilyurik, 2015-12-06
@Olej

In general, in the config file for example debian, you can set sub-interface br0:1 br0:2 etc

I don't know who the "common config file" is and what do you mean by sub-interface...
But:
1. Actually, Subinterface is understood in the most general form as any logical network interfaces attached to a real-life physical interface:
2. What you show with the ip command is an alias (synonym) IP address for the interface, which can be arbitrarily for one interface, like this:
bash-4.2$ sudo ifconfig eth0:0 192.168.2.5/24
bash-4.2$ sudo ifconfig eth0:1 192.168.3.5/24

See alias IPs
In this case, packets from the interface will leave with the same MAC address, but with a different IP address (according to the routing table).
3. On the other hand, subinterfaces (they are also called virtual interfaces) can be created by additional drivers:
Virtual network interface
Another virtual interface
4. All this (about alias IP, etc.) is quite well explained in the standards and literature on TCP / IP ... take Stevens' book.
5. Any further clarification on your question depends on what you want to achieve from such an interface.

A
Andrey San, 2015-12-07
@admusers

if you need 2 ip, then it’s better to make 2 network interfaces, since both ip will be used on the network, and in which case you can fix the problem with the network interface and that part of the packets will go without problems from the working interface.

V
Vladimir, 2015-12-07
@rostel

instead of creating br0:1 br0:2
, you can add a couple of lines to br0 for each secondary address

up ip addr add  x.x.x.x/xx dev br0
down ip addr del x.x.x.x/xx dev br0

br0:1 etc. only for ancient ifconfig

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question