1
0
mirror of https://github.com/containers/podman.git synced 2026-02-05 06:45:31 +01:00

Merge pull request #27927 from kairosci/fix/27823-host-gateway-localhost

fix: use localhost for host.containers.internal in host network mode
This commit is contained in:
Paul Holzinger
2026-02-03 20:08:43 +01:00
committed by GitHub
3 changed files with 31 additions and 1 deletions

View File

@@ -1301,7 +1301,16 @@ func (c *Container) NetworkDisabled() (bool, error) {
} }
func (c *Container) HostNetwork() bool { func (c *Container) HostNetwork() bool {
if c.config.CreateNetNS || c.config.NetNsCtr != "" { // If container shares network namespace with another container, check that container
if c.config.NetNsCtr != "" {
netNsCtr, err := c.runtime.state.Container(c.config.NetNsCtr)
if err != nil {
return false
}
return netNsCtr.HostNetwork()
}
if c.config.CreateNetNS {
return false return false
} }
if c.config.Spec.Linux != nil { if c.config.Spec.Linux != nil {

View File

@@ -2427,6 +2427,7 @@ func (c *Container) addHosts() error {
NetworkInterface: c.runtime.network, NetworkInterface: c.runtime.network,
Exclude: exclude, Exclude: exclude,
PreferIP: preferIP, PreferIP: preferIP,
HostNetwork: c.HostNetwork(),
}) })
return etchosts.New(&etchosts.Params{ return etchosts.New(&etchosts.Params{

View File

@@ -773,6 +773,26 @@ nameserver 8.8.8.8" "nameserver order is correct"
run_podman network rm -f $netname run_podman network rm -f $netname
} }
# https://github.com/containers/podman/issues/27823
# bats test_tags=ci:parallel
@test "podman run --network=host uses localhost for host.containers.internal" {
run_podman run --rm --network=host $IMAGE cat /etc/hosts
assert "$output" =~ "127\.0\.0\.1[[:blank:]].*host\.containers\.internal" \
"host.containers.internal should resolve to 127.0.0.1 with --network=host"
}
# https://github.com/containers/podman/pull/27927
# bats test_tags=ci:parallel
@test "podman run in pod with host network uses localhost for host.containers.internal" {
local podname="test-pod-hostnet-$(random_string 10)"
run_podman pod create --name $podname --network host
run_podman run --rm --pod $podname $IMAGE cat /etc/hosts
assert "$output" =~ "127\.0\.0\.1[[:blank:]].*host\.containers\.internal" \
"host.containers.internal should resolve to 127.0.0.1 in pod with host network"
run_podman pod rm $podname
}
# bats test_tags=ci:parallel # bats test_tags=ci:parallel
@test "podman run port forward range" { @test "podman run port forward range" {
# we run a long loop of tests lets run all combinations before bailing out # we run a long loop of tests lets run all combinations before bailing out