Sudo Hangs

Problem description.

one day during work, I encountered this problem, every time I sudo a command, it took awhile to prompt from password.

how to fix it

I recalled that one of my colleague share how he use strace to debug a application. I decided to give it a shot.

1
$ strace -Tvxfo trace.log sudo ls

the log file is very large, these lines tells what cause the problem

1
2
3
4
5
6
0.000093 socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 6 <0.000014>
0.000042 connect(6, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0 <0.000
0.000051 poll([{fd=6, events=POLLOUT}], 1, 0) = 1 ([{fd=6, revents=POLLOUT}]) <0.000009>
0.000043 sendto(6, "\x02\xd8\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x08\x4a\x43\x75\x62\x75\x6e\x74\x75\x00
0.000066 poll([{fd=6, events=POLLIN}], 1, 5000) = 0 (Timeout) <5.005021>
5.005098 poll([{fd=6, events=POLLOUT}], 1, 0) = 1 ([{fd=6, revents=POLLOUT}]) <0.000008>

I changed the hostname in /etc/hostname day before. Line 4 say that it want to send somthing to JCubuntu (which is my new hostname), but it couldn’t, so time out occurred.

the solution is adding a new line to the /etc/hosts

1
127.0.0.1  newhostname

the problem will disappear

Comments