echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
但如果在bash command line上运行该命令,必须为root ;
若通过bash script 运行,必须
chown root:root script;
chmod 777 script;
之后才 echo XXX | sudo /P/A/T/H/script
扩展思考:
[jim@jim shell]$ ll /proc/sys/net/ipv4/icmp_echo_ignore_all
-rw-r--r-- 1 root root 0 Apr 17 14:01 /proc/sys/net/ipv4/icmp_echo_ignore_all
[jim@jim shell]$ stat /proc/
File: `/proc/'
Size: 0 Blocks: 0 IO Block: 1024 directory
Device: 3h/3d Inode: 1 Links: 201
Access: (0555/dr-xr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2011-04-17 11:14:54.001999760 +0800
Modify: 2011-04-17 11:14:54.001999760 +0800
Change: 2011-04-17 11:14:54.001999760 +0800
以非root id 运行 (fail):
[jim@jim shell]$ echo '1' > /proc/sys/net/ipv4/icmp_echo_ignore_all
bash: /proc/sys/net/ipv4/icmp_echo_ignore_all: Permission denied
以root id 运行 (success):
[root@jim sudo-1.8.1p1]# echo '1' > /proc/sys/net/ipv4/icmp_echo_ignore_all
[root@jim sudo-1.8.1p1]#
以非root id sudo 运行 (fail)
[jim@jim shell]$ sudo echo '1' > /proc/sys/net/ipv4/icmp_echo_ignore_all
bash: /proc/sys/net/ipv4/icmp_echo_ignore_all: Permission denied
以非root 运行root的script ,success:
[jim@jim shell]$ cat ignore_ping.bash
#!/bin/bash
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
[jim@jim shell]$ stat ignore_ping.bash
File: `ignore_ping.bash'
Size: 61 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 280314 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2011-04-17 13:26:09.446376003 +0800
Modify: 2011-04-17 13:22:02.187376003 +0800
Change: 2011-04-17 13:25:54.945376002 +0800
[jim@jim shell]$ sudo ./ignore_ping.bash
[sudo] password for jim:
[jim@jim shell]$
阅读(1491) | 评论(0) | 转发(0) |