Skip to content

Commit fb6ef35

Browse files
slpalyssarosenzweig
authored andcommitted
guest: allow unprivileged users to use ping
By default, the kernel doesn't allow unprivileged users to create ICMP Echo sockets, which can lead to confusing messages like this one: $ ping 1.1.1.1 ping: socktype: SOCK_DGRAM ping: socket: Address family not supported by protocol Most distros adjust "ipv4/ping_group_range" to allow unprivileged users to use "ping" without relying on setuid, so do the same for krun guests. Signed-off-by: Sergio Lopez <[email protected]>
1 parent 60f4e5f commit fb6ef35

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

crates/krun/src/guest/net.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fs;
2+
use std::io::Write;
23
use std::os::unix::process::ExitStatusExt as _;
34
use std::process::Command;
45

@@ -10,6 +11,17 @@ use crate::utils::env::find_in_path;
1011
use crate::utils::fs::find_executable;
1112

1213
pub fn configure_network() -> Result<()> {
14+
// Allow unprivileged users to use ping, as most distros do by default.
15+
{
16+
let mut file = fs::File::options()
17+
.write(true)
18+
.open("/proc/sys/net/ipv4/ping_group_range")
19+
.context("Failed to open ipv4/ping_group_range for writing")?;
20+
21+
file.write_all(format!("{} {}", 0, 2147483647).as_bytes())
22+
.context("Failed to extend ping group range")?;
23+
}
24+
1325
{
1426
let hostname =
1527
fs::read_to_string("/etc/hostname").context("Failed to read `/etc/hostname`")?;

0 commit comments

Comments
 (0)