File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -1005,6 +1005,8 @@ func (c *Container) completeNetworkSetup() error {
1005
1005
nameservers = append (nameservers , server .String ())
1006
1006
}
1007
1007
}
1008
+ nameservers = c .addSlirp4netnsDNS (nameservers )
1009
+
1008
1010
// check if we have a bindmount for /etc/hosts
1009
1011
if hostsBindMount , ok := state .BindMounts [config .DefaultHostsFile ]; ok {
1010
1012
entries , err := c .getHostsEntries ()
Original file line number Diff line number Diff line change @@ -2015,8 +2015,13 @@ func (c *Container) generateResolvConf() error {
2015
2015
keepHostServers = true
2016
2016
// first add the nameservers from the networks status
2017
2017
nameservers = networkNameServers
2018
+
2018
2019
// slirp4netns has a built in DNS forwarder.
2019
- nameservers = c .addSlirp4netnsDNS (nameservers )
2020
+ // If in userns the network is not setup here, instead we need to do that in
2021
+ // c.completeNetworkSetup() which knows the actual slirp dns ip only at that point
2022
+ if ! c .config .PostConfigureNetNS {
2023
+ nameservers = c .addSlirp4netnsDNS (nameservers )
2024
+ }
2020
2025
}
2021
2026
2022
2027
// Set DNS search domains
Original file line number Diff line number Diff line change @@ -196,8 +196,18 @@ load helpers.network
196
196
@test " podman run with slirp4ns adds correct dns address to resolv.conf" {
197
197
CIDR=" $( random_rfc1918_subnet) "
198
198
run_podman run --rm --network slirp4netns:cidr=" ${CIDR} .0/24" \
199
- $IMAGE grep " ${CIDR} " /etc/resolv.conf
200
- is " $output " " nameserver ${CIDR} .3" " resolv.conf should have slirp4netns cidr+3 as a nameserver"
199
+ $IMAGE cat /etc/resolv.conf
200
+ assert " $output " =~ " nameserver ${CIDR} .3" " resolv.conf should have slirp4netns cidr+3 as first nameserver"
201
+ no_userns_out=" $output "
202
+
203
+ if is_rootless; then
204
+ # check the slirp ip also works correct with userns
205
+ run_podman run --rm --userns keep-id --network slirp4netns:cidr=" ${CIDR} .0/24" \
206
+ $IMAGE cat /etc/resolv.conf
207
+ assert " $output " =~ " nameserver ${CIDR} .3" " resolv.conf should have slirp4netns cidr+3 as first nameserver with userns"
208
+ assert " $output " == " $no_userns_out " " resolv.conf should look the same for userns"
209
+ fi
210
+
201
211
}
202
212
203
213
@test " podman run with slirp4ns assigns correct ip address container" {
You can’t perform that action at this time.
0 commit comments