Если я запускаю следующее, тогда IP-адрес фактически не добавляется:
ip link add veth0 type veth peer name veth1; ip address add 10.0.1.2/24 dev veth1
Однако, если я сплю между командами, то это добавляется:
ip link add veth0 type veth peer name veth1; sleep 0.1; ip address add 10.0.1.2/24 dev veth1
Я повторил несколько раз, и результаты соответствуют.
Есть ли лучший способ сделать это, чем просто спать между ними?
ОБНОВИТЬ:
Используя ip montitor, создается впечатление, что при создании пары veth выполняется множество вещей (не знаю, что), и что, когда обе команды выполняются в одной строке (без спящего режима), создание IP-адреса останавливает много это делается, и IP-адреса автоматически удаляются.
Кто-нибудь понимает, что все это происходит, когда создается ветеринарная пара?
вывод ip-монитора для создания вета:
ipv4 dev veth1 forwarding on rp_filter strict mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
ipv6 dev veth1 forwarding off mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
372: veth1@NONE: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default
link/ether da:a6:13:1a:29:31 brd ff:ff:ff:ff:ff:ff
ipv4 dev veth0 forwarding on rp_filter strict mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
ipv6 dev veth0 forwarding off mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
373: veth0@veth1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default
link/ether 4a:9e:6c:13:13:34 brd ff:ff:ff:ff:ff:ff
372: veth1@veth0: <NO-CARRIER,BROADCAST,MULTICAST,UP,M-DOWN> mtu 1500 qdisc noqueue state LOWERLAYERDOWN group default
link/ether da:a6:13:1a:29:31 brd ff:ff:ff:ff:ff:ff
373: veth0@veth1: <NO-CARRIER,BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN group default
link/ether 4a:9e:6c:13:13:34 brd ff:ff:ff:ff:ff:ff
ff00::/8 dev veth0 table local metric 256 pref medium
373: veth0@veth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 4a:9e:6c:13:13:34 brd ff:ff:ff:ff:ff:ff
ff00::/8 dev veth1 table local metric 256 pref medium
372: veth1@veth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether da:a6:13:1a:29:31 brd ff:ff:ff:ff:ff:ff
Deleted ff00::/8 dev veth0 table local metric 256 pref medium
372: veth1@veth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether da:a6:13:1a:29:31 brd ff:ff:ff:ff:ff:ff
Deleted ff00::/8 dev veth1 table local metric 256 pref medium
ff00::/8 dev veth1 table local metric 256 pref medium
373: veth0@veth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 4a:9e:6c:13:13:34 brd ff:ff:ff:ff:ff:ff
ff00::/8 dev veth0 table local metric 256 pref medium
372: veth1@veth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether da:a6:13:1a:29:31 brd ff:ff:ff:ff:ff:ff
Deleted ff00::/8 dev veth1 table local metric 256 pref medium
ff00::/8 dev veth1 table local metric 256 pref medium
fe80::/64 dev veth1 proto kernel metric 256 pref medium
373: veth0@veth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 4a:9e:6c:13:13:34 brd ff:ff:ff:ff:ff:ff
Deleted ff00::/8 dev veth0 table local metric 256 pref medium
ff00::/8 dev veth0 table local metric 256 pref medium
fe80::/64 dev veth0 proto kernel metric 256 pref medium
вывод IP-монитора для добавления IP-адреса:
372: veth1 inet 10.0.1.2/24 scope global veth1
valid_lft forever preferred_lft forever
local 10.0.1.2 dev veth1 table local proto kernel scope host src 10.0.1.2
10.0.1.0/24 dev veth1 proto kernel scope link src 10.0.1.2
broadcast 10.0.1.0 dev veth1 table local proto kernel scope link src 10.0.1.2
broadcast 10.0.1.255 dev veth1 table local proto kernel scope link src 10.0.1.2
выход ip-монитора при работе как на одной линии (без сна). Символ * обозначает строку, которая является началом создания IP-адреса:
ipv4 dev veth1 forwarding on rp_filter strict mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
ipv6 dev veth1 forwarding off mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
374: veth1@NONE: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default
link/ether 72:94:ec:5a:d7:76 brd ff:ff:ff:ff:ff:ff
ipv4 dev veth0 forwarding on rp_filter strict mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
ipv6 dev veth0 forwarding off mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
375: veth0@veth1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default
link/ether b6:7f:f2:e5:69:e6 brd ff:ff:ff:ff:ff:ff
****************************************************************
374: veth1 inet 10.0.1.2/24 scope global veth1
valid_lft forever preferred_lft forever
****************************************************************
local 10.0.1.2 dev veth1 table local proto kernel scope host src 10.0.1.2
375: veth0@veth1: <NO-CARRIER,BROADCAST,MULTICAST,UP,M-DOWN> mtu 1500 qdisc noqueue state LOWERLAYERDOWN group default
link/ether b6:7f:f2:e5:69:e6 brd ff:ff:ff:ff:ff:ff
374: veth1@veth0: <NO-CARRIER,BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN group default
link/ether 72:94:ec:5a:d7:76 brd ff:ff:ff:ff:ff:ff
10.0.1.0/24 dev veth1 proto kernel scope link src 10.0.1.2
broadcast 10.0.1.0 dev veth1 table local proto kernel scope link src 10.0.1.2
broadcast 10.0.1.255 dev veth1 table local proto kernel scope link src 10.0.1.2
ff00::/8 dev veth1 table local metric 256 pref medium
374: veth1@veth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 72:94:ec:5a:d7:76 brd ff:ff:ff:ff:ff:ff
ff00::/8 dev veth0 table local metric 256 pref medium
375: veth0@veth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether b6:7f:f2:e5:69:e6 brd ff:ff:ff:ff:ff:ff
Deleted 10.0.1.0/24 dev veth1 proto kernel scope link src 10.0.1.2
Deleted ff00::/8 dev veth1 table local metric 256 pref medium
Deleted 374: veth1 inet 10.0.1.2/24 scope global veth1
valid_lft forever preferred_lft forever
Deleted broadcast 10.0.1.255 dev veth1 table local proto kernel scope link src 10.0.1.2
Deleted broadcast 10.0.1.0 dev veth1 table local proto kernel scope link src 10.0.1.2
Deleted local 10.0.1.2 dev veth1 table local proto kernel scope host src 10.0.1.2
375: veth0@veth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether b6:7f:f2:e5:69:e6 brd ff:ff:ff:ff:ff:ff
Deleted ff00::/8 dev veth0 table local metric 256 pref medium
ff00::/8 dev veth0 table local metric 256 pref medium
374: veth1@veth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 72:94:ec:5a:d7:76 brd ff:ff:ff:ff:ff:ff
ff00::/8 dev veth1 table local metric 256 pref medium
375: veth0@veth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether b6:7f:f2:e5:69:e6 brd ff:ff:ff:ff:ff:ff
Deleted ff00::/8 dev veth0 table local metric 256 pref medium
ff00::/8 dev veth0 table local metric 256 pref medium
fe80::/64 dev veth0 proto kernel metric 256 pref medium
374: veth1@veth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 72:94:ec:5a:d7:76 brd ff:ff:ff:ff:ff:ff
Deleted ff00::/8 dev veth1 table local metric 256 pref medium
ff00::/8 dev veth1 table local metric 256 pref medium
fe80::/64 dev veth1 proto kernel metric 256 pref medium
374: veth1 inet6 fe80::1ab9:60e6:dfe2:5904/64 scope link
valid_lft forever preferred_lft forever
local fe80::1ab9:60e6:dfe2:5904 dev veth1 table local proto kernel metric 0 pref medium
374: veth1 inet6 fe80::1ab9:60e6:dfe2:5904/64 scope link noprefixroute
valid_lft forever preferred_lft forever
Deleted fe80::/64 dev veth1 proto kernel metric 256 pref medium
fe80::/64 dev veth1 proto kernel metric 256 pref medium
fe80::/64 dev veth1 proto kernel metric 102 pref medium
375: veth0 inet6 fe80::aa07:cb3f:757e:f3f4/64 scope link
valid_lft forever preferred_lft forever
local fe80::aa07:cb3f:757e:f3f4 dev veth0 table local proto kernel metric 0 pref medium
375: veth0 inet6 fe80::aa07:cb3f:757e:f3f4/64 scope link noprefixroute
valid_lft forever preferred_lft forever
Deleted fe80::/64 dev veth0 proto kernel metric 256 pref medium
fe80::/64 dev veth0 proto kernel metric 256 pref medium
fe80::/64 dev veth0 proto kernel metric 101 pref medium