Hi, apology if my question sound like story telling.
i have public ip alias on my eth0, and i wish to use it for a container without ding nat or whatever. and i figured ipvlan is the way to go.
i followed this page: https://www.gitmemory.com/issue/lxc/lxd/5830/500324610
but unfortunately the container dose not get an ip. so i have to modify netplan as follow:
then the container gets the ip alias wanted for it to have.
using HOST_IP as gate is because my ISP provider suggested i do so.
i have internet connectivity. doing curl ifconfig.me result on HOST_IP rathre than PUBLIC_IP / or alias.
i could be doing it wrong. thus. i do appreciate a functional example so i can follow.
Thanks in advance.
So the ipvlan NIC type will set the IP and gateway settings before the container starts (like routed NIC type too).
Unfortunately the netplan system inside Ubuntu containers (at least) will wipe the configuration and then try to use DHCP, which won’t work.
I’ve also not been able to figure out how to get netplan to create a default “device” route, as it insists that a “via” setting is specified.
Anyway, I’ve managed to coax it into working by adding a fake route to 169.254.0.1 which is how we do it with the routed NIC type.
If you replace your netplan config with something like this then it works.
Also, please note the subnet size specified on the IP address is /32 as it is only a single IP and is not bridged to the wider LAN. Using anything other than /32 (or /128 or IPv6 addresses) is likely to have unwanted results.
yup. i just did that. 1 thing tho, the ip alias is assigned to the container. but traffic in and out seems to be through host ip.
quick curl ifconfig.me shows host ip.
Please can you show me the iptables (or nftables) NAT rules, also please can you show a tcpdump running on the host’s external interface showing the packets leaving with the incorrect source IP.
sudo iptables -L -v -n -t nat
Chain PREROUTING (policy ACCEPT 967 packets, 104K bytes)
pkts bytes target prot opt in out source destination
985 104K PREROUTING_direct all -- * * 0.0.0.0/0 0.0.0.0/0
985 104K PREROUTING_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0
985 104K PREROUTING_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 1996 packets, 443K bytes)
pkts bytes target prot opt in out source destination
2034 450K OUTPUT_direct all -- * * 0.0.0.0/0 0.0.0.0/0
Chain POSTROUTING (policy ACCEPT 1996 packets, 443K bytes)
pkts bytes target prot opt in out source destination
2034 450K POSTROUTING_direct all -- * * 0.0.0.0/0 0.0.0.0/0
2034 450K POSTROUTING_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0
2034 450K POSTROUTING_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0
Chain OUTPUT_direct (1 references)
pkts bytes target prot opt in out source destination
Chain POSTROUTING_ZONES (1 references)
pkts bytes target prot opt in out source destination
0 0 POST_public all -- * vlan0 0.0.0.0/0 0.0.0.0/0 [goto]
1937 433K POST_public all -- * br0 0.0.0.0/0 0.0.0.0/0 [goto]
1 40 POST_public all -- * eth0 0.0.0.0/0 0.0.0.0/0 [goto]
93 16374 POST_public all -- * + 0.0.0.0/0 0.0.0.0/0 [goto]
Chain POSTROUTING_ZONES_SOURCE (1 references)
pkts bytes target prot opt in out source destination
Chain POSTROUTING_direct (1 references)
pkts bytes target prot opt in out source destination
Chain POST_external (0 references)
pkts bytes target prot opt in out source destination
1 108 POST_external_log all -- * * 0.0.0.0/0 0.0.0.0/0
1 108 POST_external_deny all -- * * 0.0.0.0/0 0.0.0.0/0
1 108 POST_external_allow all -- * * 0.0.0.0/0 0.0.0.0/0
Chain POST_external_allow (1 references)
pkts bytes target prot opt in out source destination
1 108 MASQUERADE all -- * !lo 0.0.0.0/0 0.0.0.0/0
Chain POST_external_deny (1 references)
pkts bytes target prot opt in out source destination
Chain POST_external_log (1 references)
pkts bytes target prot opt in out source destination
Chain POST_public (4 references)
pkts bytes target prot opt in out source destination
2033 449K POST_public_log all -- * * 0.0.0.0/0 0.0.0.0/0
2033 449K POST_public_deny all -- * * 0.0.0.0/0 0.0.0.0/0
2033 449K POST_public_allow all -- * * 0.0.0.0/0 0.0.0.0/0
Chain POST_public_allow (1 references)
pkts bytes target prot opt in out source destination
Chain POST_public_deny (1 references)
pkts bytes target prot opt in out source destination
Chain POST_public_log (1 references)
pkts bytes target prot opt in out source destination
Chain PREROUTING_ZONES (1 references)
pkts bytes target prot opt in out source destination
0 0 PRE_public all -- vlan0 * 0.0.0.0/0 0.0.0.0/0 [goto]
967 104K PRE_public all -- br0 * 0.0.0.0/0 0.0.0.0/0 [goto]
18 576 PRE_public all -- eth0 * 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 PRE_public all -- + * 0.0.0.0/0 0.0.0.0/0 [goto]
Chain PREROUTING_ZONES_SOURCE (1 references)
pkts bytes target prot opt in out source destination
Chain PREROUTING_direct (1 references)
pkts bytes target prot opt in out source destination
Chain PRE_external (0 references)
pkts bytes target prot opt in out source destination
0 0 PRE_external_log all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 PRE_external_deny all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 PRE_external_allow all -- * * 0.0.0.0/0 0.0.0.0/0
Chain PRE_external_allow (1 references)
pkts bytes target prot opt in out source destination
Chain PRE_external_deny (1 references)
pkts bytes target prot opt in out source destination
Chain PRE_external_log (1 references)
pkts bytes target prot opt in out source destination
Chain PRE_public (4 references)
pkts bytes target prot opt in out source destination
985 104K PRE_public_log all -- * * 0.0.0.0/0 0.0.0.0/0
985 104K PRE_public_deny all -- * * 0.0.0.0/0 0.0.0.0/0
985 104K PRE_public_allow all -- * * 0.0.0.0/0 0.0.0.0/0
Chain PRE_public_allow (1 references)
pkts bytes target prot opt in out source destination
Chain PRE_public_deny (1 references)
pkts bytes target prot opt in out source destination
Chain PRE_public_log (1 references)
pkts bytes target prot opt in out source destination
am not using nftables. just firewalld, and iptables.
about: please can you show a tcpdump running on the host’s external interface showing the packets leaving with the incorrect source IP.
apology, have no idea how to do that.
No you shouldn’t need a proxy device as the container should have a public IP. If ping is working to/from the public IP to/from external destinations then you have connectivity, and its likely a firewall rule blocking inbound traffic somewhere.
It should go to the container, i imagined i needed to add it on the host at first then make it available on the container. am going to remove it from host and try.
please check this edit:
That is normal, it is a static route of the public IP alias to the local loopback interface, it is added by LXD when using ipvlan, its only purpose is to activate the proxy ARP on the host so that your host responds to ARP requests for your public IP alias that you’re passing through into the container.
However it is important that the IP itself is not bound (setup) on the host.