1 개요[ | ]
- ping --count option doesn't work.
- ping -c 옵션 안되는 현상
- -c 옵션을 준 목적은 ping을 1회 시도해보고 되든 안되든 그 결과를 알아내고자 한 것이다.
- 그런데 무한히 재시도하는 경우도 발생할 수 있다.
Console
Copy
root@ubuntu1:~# ping 8.8.8.8 -c1
PING 8.8.8.8 (8.8.8.8): 56 data bytes
ping: sendto: Network is unreachable
ping: sendto: Network is unreachable
ping: sendto: Network is unreachable
... (생략)
ping: sendto: Network is unreachable
^C--- 8.8.8.8 ping statistics ---
0 packets transmitted, 0 packets received,
- → -c1 옵션을 주었지만 무한정 계속 시도하여 끝나지 않음
2 (비교) 일반적인 경우[ | ]
- 성공
Console
Copy
root@zetawiki:~# ping 8.8.8.8 -c1
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=52 time=35.8 ms
--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
- → 응답 패킷을 받고 끝남
- 실패
Console
Copy
root@zetawiki:~# ping 123.123.123.123 -c1
PING 123.123.123.123 (123.123.123.123) 56(84) bytes of data.
--- 123.123.123.123 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
- → 패킷 유실로 처리됨
3 원인[ | ]
Console
Copy
root@ubuntu1:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.255.0 U 0 0 0 eth1
- → 기본 게이트웨이가 없음
- 기본 게이트웨이가 없으니 ping 패킷을 보내는 것조차 하지 못해 횟수가 count 되지 않는 것
4 대체 방안[ | ]
- workaround로 timeout 을 붙여 수행
Console
Copy
root@ubuntu1:~# timeout 1 ping 8.8.8.8 -c1
PING 8.8.8.8 (8.8.8.8): 56 data bytes
ping: sendto: Network is unreachable
- → ping을 보내지 못하더라도 1초 후 중단됨
- 만약 게이트웨이가 추가되어 성공하는 경우라면...
Console
Copy
root@ubuntu2:~# timeout 1 ping 8.8.8.8 -c1
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=43 time=37.960 ms
--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 37.960/37.960/37.960/0.000 ms
5 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.
- 분류 댓글:
- 리눅스 네트워크 (5)
리눅스 hosts 파일 ― 올해대박리눅스 hosts 파일 ― Jmnote리눅스 nc 포트 열기 ― …우분투 절전모드 해제시 와이파이 안되는 문제 ― D4RT우분투 절전모드 해제시 와이파이 안되는 문제 ― Beyondthelimit