Eu tenho um host (ubuntu xenial) rodando um container via systemd-nspawn
(também xenial):
systemd-nspawn --directory=gogs --network-macvlan=ens192 --boot
ens192
é a interface do host que obtém seu endereço IP via DHCP.
De dentro do contêiner, eu gostaria de obter um endereço IP que seria fornecido pelo DHCP da rede, aquele que anteriormente o fornecia ao host (primeiro preciso usar um endereço MAC registrado no servidor DHCP) ):
root@git:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: mv-ens192: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1
link/ether d2:b9:c3:77:25:83 brd ff:ff:ff:ff:ff:ff link-netnsid 0
root@git:~# ifconfig mv-ens192 hw ether aa:a0:a0:a0:a0:01
root@git:~# ifconfig mv-ens192 up
root@git:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: mv-ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1
link/ether 00:50:56:bb:60:3f brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::250:56ff:febb:603f/64 scope link
valid_lft forever preferred_lft forever
root@git:~# dhclient -v
Internet Systems Consortium DHCP Client 4.3.3
Copyright 2004-2015 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/mv-ens192/aa:a0:a0:a0:a0:01
Sending on LPF/mv-ens192/aa:a0:a0:a0:a0:01
Sending on Socket/fallback
DHCPDISCOVER on mv-ens192 to 255.255.255.255 port 67 interval 3 (xid=0xd36b8c1e)
DHCPDISCOVER on mv-ens192 to 255.255.255.255 port 67 interval 7 (xid=0xd36b8c1e)
A descoberta não vai embora.
Por que isso falha?
O pacote de descoberta DHCP vai para a NIC do host, que deve então despachá-lo (não deve ser diferente da chamada que o host está fazendo ao solicitar seu próprio IP).
Observação: ao executar um tshark
no host , vejo a solicitação do contêiner:
634 8.404019212 0.0.0.0 -> 255.255.255.255 DHCP 342 DHCP Discover - Transaction ID 0xd36b8c1e